Search in sources :

Example 1 with BlockAccessDelegate

use of network.rs485.logisticspipes.proxy.mcmp.BlockAccessDelegate in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method dropBlockAsItemWithChance.

@Override
public void dropBlockAsItemWithChance(World world, @Nonnull final BlockPos pos, @Nonnull IBlockState state, float chance, int fortune) {
    if (world.isRemote) {
        return;
    }
    int i1 = quantityDropped(world.rand);
    for (int j1 = 0; j1 < i1; j1++) {
        if (world.rand.nextFloat() > chance) {
            continue;
        }
        CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.getPipe(world, pos);
        if (pipe == null) {
            pipe = LogisticsBlockGenericPipe.pipeRemoved.get(new DoubleCoordinates(pos));
        }
        if (pipe == null)
            return;
        if (pipe.item != null && (pipe.canBeDestroyed() || pipe.destroyByPlayer())) {
            for (ItemStack stack : pipe.dropContents()) {
                spawnAsEntity(world, pos, stack);
            }
            spawnAsEntity(world, pos, new ItemStack(pipe.item, 1, damageDropped(state)));
            final NonNullList<ItemStack> list = NonNullList.create();
            CoreUnroutedPipe finalPipe = pipe;
            BlockAccessDelegate worldDelegate = new BlockAccessDelegate(world) {

                @Override
                public TileEntity getTileEntity(BlockPos testPos) {
                    if (pos == testPos) {
                        return finalPipe.container;
                    }
                    return super.getTileEntity(pos);
                }
            };
            mcmpBlockAccess.addDrops(list, worldDelegate, pos, state, fortune);
            for (ItemStack stack : list) {
                spawnAsEntity(world, pos, stack);
            }
        } else if (pipe.item != null) {
            LogisticsBlockGenericPipe.cacheTileToPreventRemoval(pipe);
        }
    }
}
Also used : BlockAccessDelegate(network.rs485.logisticspipes.proxy.mcmp.BlockAccessDelegate) BlockPos(net.minecraft.util.math.BlockPos) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockAccessDelegate (network.rs485.logisticspipes.proxy.mcmp.BlockAccessDelegate)1 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)1