Skip to content

Commit

Permalink
Fix #1146
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLane committed Nov 6, 2019
1 parent ed76b1f commit 2062051
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions src/main/java/com/flansmod/client/FlansModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
Expand All @@ -18,14 +19,13 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.flansmod.api.IControllable;
import com.flansmod.client.model.GunAnimations;
import com.flansmod.client.teams.ClientTeamsData;
import com.flansmod.client.util.WorldRenderer;
Expand All @@ -39,7 +39,6 @@
import com.flansmod.common.network.PacketTeamInfo;
import com.flansmod.common.teams.Team;
import com.flansmod.common.types.InfoType;
import com.flansmod.common.vector.Vector3i;

@SideOnly(Side.CLIENT)
public class FlansModClient extends FlansMod
Expand Down Expand Up @@ -73,7 +72,7 @@ public class FlansModClient extends FlansMod
* Gun animation variables for each entity holding a gun. Currently only applicable to the player
*/
public static HashMap<EntityLivingBase, GunAnimations> gunAnimationsRight = new HashMap<>(),
gunAnimationsLeft = new HashMap<>();
gunAnimationsLeft = new HashMap<>();

// Scope variables
/**
Expand Down Expand Up @@ -120,7 +119,7 @@ public class FlansModClient extends FlansMod

public static int hitMarkerTime = 0;

public static ArrayList<Vector3i> blockLightOverrides = new ArrayList<>();
public static List<BlockPos> blockLightOverrides = new ArrayList<>();
public static int lightOverrideRefreshRate = 5;

private static WorldRenderer wr;
Expand Down Expand Up @@ -183,8 +182,8 @@ public static void tick()
{
// If we've opened a GUI page, or we switched weapons, close the current scope
if(FMLClientHandler.instance().getClient().currentScreen != null
|| !(itemInHand instanceof ItemGun)
|| ((ItemGun)itemInHand).GetType().getCurrentScope(itemstackInHand) != currentScope)
|| !(itemInHand instanceof ItemGun)
|| ((ItemGun)itemInHand).GetType().getCurrentScope(itemstackInHand) != currentScope)
{
currentScope = null;
minecraft.gameSettings.fovSetting = originalFOV;
Expand Down Expand Up @@ -347,7 +346,7 @@ else if(s.contains("_"))
else
{
data = new int[]{
Block.getIdFromBlock(Block.getBlockFromItem(InfoType.getRecipeElement(split[1], 0).getItem()))};
Block.getIdFromBlock(Block.getBlockFromItem(InfoType.getRecipeElement(split[1], 0).getItem()))};

if(split[0].equals("blockcrack"))
{
Expand Down Expand Up @@ -406,17 +405,13 @@ public static void updateFlashlights(Minecraft mc)
lightOverrideRefreshRate = mc.gameSettings.fancyGraphics ? 10 : 20;

// Reset old light values
for(Vector3i v : blockLightOverrides)
{
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(v.x, v.y, v.z));
}
blockLightOverrides.forEach(blockPos -> mc.world.checkLightFor(EnumSkyBlock.BLOCK, blockPos));
// Clear the list
blockLightOverrides.clear();

//Find all flashlights
for(Object obj : mc.world.playerEntities)
for(EntityPlayer player : mc.world.playerEntities)
{
EntityPlayer player = (EntityPlayer)obj;
ItemStack currentHeldItem = player.getHeldItemMainhand();
if(currentHeldItem.getItem() instanceof ItemGun)
{
Expand Down Expand Up @@ -454,58 +449,43 @@ public static void updateFlashlights(Minecraft mc)
x++;
break;
}
blockLightOverrides.add(new Vector3i(x, y, z));
mc.world.setLightFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z), 12);
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y + 1, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y - 1, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x + 1, y, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x - 1, y, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z + 1));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z - 1));
BlockPos blockPos = new BlockPos(x, y, z);
blockLightOverrides.add(blockPos);
lightBlock(mc, blockPos, 12);
}
}
}
}
}

for(Object obj : mc.world.loadedEntityList)
for(Entity entity : mc.world.loadedEntityList)
{
if(obj instanceof EntityBullet)
if(entity instanceof EntityBullet)
{
EntityBullet bullet = (EntityBullet)obj;
EntityBullet bullet = (EntityBullet)entity;
if(!bullet.isDead && bullet.getFiredShot().getBulletType().hasLight)
{
int x = MathHelper.floor(bullet.posX);
int y = MathHelper.floor(bullet.posY);
int z = MathHelper.floor(bullet.posZ);
blockLightOverrides.add(new Vector3i(x, y, z));
mc.world.setLightFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z), 15);
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y + 1, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y - 1, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x + 1, y, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x - 1, y, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z + 1));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z - 1));
BlockPos blockPos = new BlockPos(x, y, z);
blockLightOverrides.add(blockPos);
lightBlock(mc, blockPos, 15);
}
}
else if(obj instanceof EntityMecha)
else if(entity instanceof EntityMecha)
{
EntityMecha mecha = (EntityMecha)obj;
EntityMecha mecha = (EntityMecha)entity;
int x = MathHelper.floor(mecha.posX);
int y = MathHelper.floor(mecha.posY);
int z = MathHelper.floor(mecha.posZ);
if(mecha.lightLevel() > 0)
{
blockLightOverrides.add(new Vector3i(x, y, z));
mc.world.setLightFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z),
Math.max(mc.world.getLightFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z)),
mecha.lightLevel()));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y + 1, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y - 1, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x + 1, y, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x - 1, y, z));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z + 1));
mc.world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, new BlockPos(x, y, z - 1));
BlockPos blockPos = new BlockPos(x, y, z);
int lightLevel = Math
.max(mc.world.getLightFor(EnumSkyBlock.BLOCK, blockPos), mecha.lightLevel());
blockLightOverrides.add(blockPos);
lightBlock(mc, blockPos, lightLevel);
}
if(mecha.forceDark())
{
Expand All @@ -518,9 +498,10 @@ else if(obj instanceof EntityMecha)
int xd = i + x;
int yd = j + y;
int zd = k + z;
blockLightOverrides.add(new Vector3i(xd, yd, zd));
mc.world.setLightFor(EnumSkyBlock.SKY, new BlockPos(xd, yd, zd),
Math.abs(i) + Math.abs(j) + Math.abs(k));
BlockPos blockPos = new BlockPos(xd, yd, zd);
blockLightOverrides.add(blockPos);
mc.world.setLightFor(EnumSkyBlock.SKY, blockPos,
Math.abs(i) + Math.abs(j) + Math.abs(k));
}
}
}
Expand All @@ -529,4 +510,19 @@ else if(obj instanceof EntityMecha)
}
}
}

private static void lightBlock(Minecraft mc, BlockPos blockPos, int lightValue)
{
mc.world.setLightFor(EnumSkyBlock.BLOCK, blockPos, lightValue);
Vec3i diffVec = new Vec3i(1, 1, 1);
BlockPos
.getAllInBox(blockPos.subtract(diffVec), blockPos.add(diffVec))
.forEach(posToUpdate ->
{
if(!posToUpdate.equals(blockPos))
{
mc.world.checkLightFor(EnumSkyBlock.BLOCK, posToUpdate);
}
});
}
}

0 comments on commit 2062051

Please sign in to comment.