From 2d94838a3ecda48b12e9cf086598e445b6d8e555 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Sat, 5 Sep 2020 12:33:16 +0200 Subject: [PATCH] Fix beacon reading --- .../curiosities/ChromaticCompoundItem.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java index ae5687f98..c9de59089 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/ChromaticCompoundItem.java @@ -21,13 +21,11 @@ import net.minecraft.particles.ParticleTypes; import net.minecraft.tileentity.BeaconTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceContext; +import net.minecraft.util.math.*; import net.minecraft.util.math.RayTraceContext.BlockMode; import net.minecraft.util.math.RayTraceContext.FluidMode; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraft.world.gen.Heightmap; public class ChromaticCompoundItem extends Item { @@ -117,20 +115,25 @@ public class ChromaticCompoundItem extends Item { // Is inside beacon beam? boolean isOverBeacon = false; - BlockPos.Mutable testPos = new BlockPos.Mutable(entity.getPosition()); - while (testPos.getY() > 0) { - testPos.move(Direction.DOWN); - BlockState state = world.getBlockState(testPos); - if (state.getOpacity(world, testPos) >= 15 && state.getBlock() != Blocks.BEDROCK) - break; - if (state.getBlock() == Blocks.BEACON) { - TileEntity te = world.getTileEntity(testPos); - if (!(te instanceof BeaconTileEntity)) + int entityX = MathHelper.floor(entity.getX()); + int entityZ = MathHelper.floor(entity.getZ()); + int localWorldHeight = world.getHeight(Heightmap.Type.WORLD_SURFACE, entityX, entityZ); + if (entity.getY() > localWorldHeight) { + BlockPos.Mutable testPos = new BlockPos.Mutable(entityX, localWorldHeight, entityZ); + while (testPos.getY() > 0) { + testPos.move(Direction.DOWN); + BlockState state = world.getBlockState(testPos); + if (state.getOpacity(world, testPos) >= 15 && state.getBlock() != Blocks.BEDROCK) break; - BeaconTileEntity bte = (BeaconTileEntity) te; - if (bte.getLevels() != 0) - isOverBeacon = true; - break; + if (state.getBlock() == Blocks.BEACON) { + TileEntity te = world.getTileEntity(testPos); + if (!(te instanceof BeaconTileEntity)) + break; + BeaconTileEntity bte = (BeaconTileEntity) te; + if (bte.getLevels() != 0) + isOverBeacon = true; + break; + } } }