use of net.minecraft.tileentity.TileEntityPiston in project BetterWithAddons by DaedalusGame.
the class HardcorePackingHandler method hardcorePackingCompress.
@SubscribeEvent
public void hardcorePackingCompress(TickEvent.WorldTickEvent event) {
if (event.world == null || event.world.isRemote)
return;
HashSet<TileEntityPiston> toIterate = new HashSet<>(activePistons);
HashSet<TileEntityPiston> toRemove = new HashSet<>();
for (TileEntityPiston piston : toIterate) {
World world = piston.getWorld();
toRemove.add(piston);
if (world != null && !world.isRemote && piston != null && piston.isExtending()) {
BlockPos pos = piston.getPos();
EnumFacing facing = piston.getFacing();
BlockPos shovePos = piston.getPos();
IBlockState shoveState = piston.getPistonState();
BlockPos compressPos = shovePos.offset(facing);
IBlockState compressState = world.getBlockState(compressPos);
if (isEmpty(world, compressPos, compressState) && isSurrounded(world, compressPos, facing.getOpposite())) {
AxisAlignedBB blockMask = new AxisAlignedBB(shovePos).union(new AxisAlignedBB(compressPos));
List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, blockMask);
PackingRecipe recipe = CraftingManagerPacking.getInstance().getMostValidRecipe(compressState, items);
if (recipe != null && recipe.consumeIngredients(items)) {
world.setBlockState(compressPos, recipe.getOutput(compressState, items));
}
}
}
}
activePistons.removeAll(toRemove);
}
Aggregations