Search in sources :

Example 1 with TileEntityPiston

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);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TileEntityPiston(net.minecraft.tileentity.TileEntityPiston) PackingRecipe(betterwithaddons.crafting.recipes.PackingRecipe) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) EntityItem(net.minecraft.entity.item.EntityItem) HashSet(java.util.HashSet) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

PackingRecipe (betterwithaddons.crafting.recipes.PackingRecipe)1 HashSet (java.util.HashSet)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityItem (net.minecraft.entity.item.EntityItem)1 TileEntityPiston (net.minecraft.tileentity.TileEntityPiston)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1