diff options
Diffstat (limited to 'src')
2 files changed, 22 insertions, 19 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java index 6f00be31..0e71c7a9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GenericBlockHighlighter.java @@ -21,7 +21,10 @@ package io.github.moulberry.notenoughupdates.miscfeatures.world; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.util.BlockPos; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.event.world.WorldEvent; @@ -53,7 +56,24 @@ public abstract class GenericBlockHighlighter { @SubscribeEvent public void onTick(TickEvent.ClientTickEvent ev) { if (ev.phase != TickEvent.Phase.END) return; - highlightedBlocks.removeIf(it -> !isValidHighlightSpot(it)); + highlightedBlocks.removeIf(it -> !isValidHighlightSpot(it) || !canPlayerSeeBlock(it.getX(), it.getY(), it.getZ())); + } + + protected boolean canPlayerSeeBlock(double xCoord, double yCoord, double zCoord) { + EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; + if (p == null) return false; + World w = p.worldObj; + MovingObjectPosition hitResult = w.rayTraceBlocks( + new Vec3(p.posX, p.posY + p.eyeHeight, p.posZ), + new Vec3(xCoord, yCoord, zCoord), + false, + true, + true + ); + BlockPos bp = new BlockPos(xCoord, yCoord, zCoord); + return hitResult == null + || hitResult.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK + || bp.equals(hitResult.getBlockPos()); } @SubscribeEvent @@ -62,7 +82,7 @@ public abstract class GenericBlockHighlighter { } public void registerInterest(BlockPos pos) { - if (isValidHighlightSpot(pos)) { + if (isValidHighlightSpot(pos) && canPlayerSeeBlock(pos.getX(), pos.getY(), pos.getZ())) { highlightedBlocks.add(pos); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java index 74df8bd0..9857f84b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/world/GlowingMushroomHighlighter.java @@ -25,12 +25,9 @@ import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumParticleTypes; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -48,26 +45,12 @@ public class GlowingMushroomHighlighter extends GenericBlockHighlighter { isDecimalPartApproximately(event.getXCoord(), 0.5) && isDecimalPartApproximately(event.getYCoord(), 0.1) && isDecimalPartApproximately(event.getZCoord(), 0.5) - && canPlayerSee(event.getXCoord(), event.getYCoord(), event.getZCoord()) ) { registerInterest(blockPos); } } } - private boolean canPlayerSee(double xCoord, double yCoord, double zCoord) { - EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; - if (p == null) return false; - World w = p.worldObj; - MovingObjectPosition hitResult = w.rayTraceBlocks( - new Vec3(p.posX, p.posY + p.eyeHeight, p.posZ), - new Vec3(xCoord, yCoord, zCoord), - false, - true, - true - ); - return hitResult == null || hitResult.typeOfHit == null; - } @Override protected boolean isEnabled() { |