From 1da43f8ffc1ab8c1e53751ecbb20e1adcfadddfc Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 28 Mar 2020 19:03:18 +0100 Subject: [PATCH] More generic chest detection - Possibly enabled the use of modded chest blocks for portable inventories - More safety checks --- .../create/modules/contraptions/RotationPropagator.java | 7 +++++-- .../components/contraptions/MountedStorage.java | 6 ++++-- .../modules/contraptions/components/saw/SawBlock.java | 7 ++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java index 373c0493f..96955de75 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java @@ -298,8 +298,11 @@ public class RotationPropagator { BlockState neighbourState = worldIn.getBlockState(neighbourPos); if (!(neighbourState.getBlock() instanceof IRotate)) continue; - - final KineticTileEntity neighbourTE = (KineticTileEntity) worldIn.getTileEntity(neighbourPos); + TileEntity tileEntity = worldIn.getTileEntity(neighbourPos); + if (!(tileEntity instanceof KineticTileEntity)) + continue; + + final KineticTileEntity neighbourTE = (KineticTileEntity) tileEntity; if (!neighbourTE.hasSource() || !neighbourTE.source.equals(pos)) continue; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/MountedStorage.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/MountedStorage.java index e46eb52b2..e2056fba1 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/MountedStorage.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/MountedStorage.java @@ -7,6 +7,8 @@ import net.minecraft.block.ChestBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.properties.ChestType; +import net.minecraft.tileentity.BarrelTileEntity; +import net.minecraft.tileentity.ChestTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.items.CapabilityItemHandler; @@ -105,9 +107,9 @@ public class MountedStorage { TileEntityType type = te.getType(); if (type == AllTileEntities.FLEXCRATE.type) return true; - if (type == TileEntityType.BARREL) + if (te instanceof ChestTileEntity) return true; - if (type == TileEntityType.CHEST || type == TileEntityType.TRAPPED_CHEST) + if (te instanceof BarrelTileEntity) return true; return false; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/saw/SawBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/saw/SawBlock.java index e87f73bb0..562b65710 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/saw/SawBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/saw/SawBlock.java @@ -97,7 +97,12 @@ public class SawBlock extends DirectionalAxisKineticBlock implements IWithTileEn super.onLanded(worldIn, entityIn); if (!(entityIn instanceof ItemEntity)) return; - withTileEntityDo(entityIn.world, entityIn.getPosition(), te -> { + BlockPos pos = entityIn.getPosition(); + if (!(worldIn.getTileEntity(pos) instanceof SawTileEntity)) + return; + if (entityIn.world.isRemote) + return; + withTileEntityDo(entityIn.world, pos, te -> { te.insertItem((ItemEntity) entityIn); }); }