From ecc02fec7171c7a15125240a49ab4e052e5d75b8 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Tue, 24 Mar 2020 15:11:43 +0100 Subject: [PATCH] BeltTileEntity safety checks --- .../contraptions/relays/belt/BeltBlock.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 619706039..5ce182f03 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -78,7 +78,10 @@ public class BeltBlock extends HorizontalKineticBlock public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) { if (face.getAxis() != getRotationAxis(state)) return false; - BeltTileEntity beltEntity = (BeltTileEntity) world.getTileEntity(pos); + TileEntity tileEntity = world.getTileEntity(pos); + if (!(tileEntity instanceof BeltTileEntity)) + return false; + BeltTileEntity beltEntity = (BeltTileEntity) tileEntity; return beltEntity != null && beltEntity.hasPulley(); } @@ -149,8 +152,12 @@ public class BeltBlock extends HorizontalKineticBlock @Override public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) { + TileEntity tileEntity = worldIn.getTileEntity(pos); + if (!(tileEntity instanceof BeltTileEntity)) + return; + BeltTileEntity belt = null; - belt = (BeltTileEntity) worldIn.getTileEntity(pos); + belt = (BeltTileEntity) tileEntity; if (state.get(SLOPE) == Slope.VERTICAL) return; @@ -180,7 +187,10 @@ public class BeltBlock extends HorizontalKineticBlock return; } - BeltTileEntity controller = (BeltTileEntity) worldIn.getTileEntity(belt.getController()); + TileEntity controllerTE = worldIn.getTileEntity(belt.getController()); + if (!(controllerTE instanceof BeltTileEntity)) + return; + BeltTileEntity controller = (BeltTileEntity) controllerTE; if (controller == null || controller.passengers == null) return; if (controller.passengers.containsKey(entityIn)) { @@ -367,8 +377,12 @@ public class BeltBlock extends HorizontalKineticBlock public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { VoxelShape shape = getShape(state, worldIn, pos, context); - BeltTileEntity belt = (BeltTileEntity) worldIn.getTileEntity(pos); - if (belt == null || context.getEntity() == null) + TileEntity tileEntity = worldIn.getTileEntity(pos); + if (!(tileEntity instanceof BeltTileEntity)) + return shape; + + BeltTileEntity belt = (BeltTileEntity) tileEntity; + if (context.getEntity() == null) return shape; BeltTileEntity controller = (BeltTileEntity) worldIn.getTileEntity(belt.getController()); if (controller == null)