Search in sources :

Example 1 with BlockShulkerBox

use of net.minecraft.block.BlockShulkerBox in project RFTools by McJty.

the class BuilderTileEntity method commonQuarryBlock.

private boolean commonQuarryBlock(boolean silk, int rfNeeded, BlockPos srcPos, IBlockState srcState) {
    Block block = srcState.getBlock();
    int xCoord = getPos().getX();
    int yCoord = getPos().getY();
    int zCoord = getPos().getZ();
    int sx = srcPos.getX();
    int sy = srcPos.getY();
    int sz = srcPos.getZ();
    if (sx >= xCoord - 1 && sx <= xCoord + 1 && sy >= yCoord - 1 && sy <= yCoord + 1 && sz >= zCoord - 1 && sz <= zCoord + 1) {
        // Skip a 3x3x3 block around the builder.
        return skip();
    }
    if (isEmpty(srcState, block)) {
        return skip();
    }
    if (block.getBlockHardness(srcState, getWorld(), srcPos) >= 0) {
        boolean clear = getCardType().isClearing();
        if ((!clear) && srcState == getReplacementBlock()) {
            // We can skip dirt if we are not clearing.
            return skip();
        }
        if ((!BuilderConfiguration.quarryTileEntities) && getWorld().getTileEntity(srcPos) != null) {
            // Skip tile entities
            return skip();
        }
        FakePlayer fakePlayer = getHarvester();
        if (allowedToBreak(srcState, getWorld(), srcPos, fakePlayer)) {
            ItemStack filter = getStackInSlot(BuilderContainer.SLOT_FILTER);
            if (!filter.isEmpty()) {
                getFilterCache();
                if (filterCache != null) {
                    boolean match = filterCache.match(block.getItem(getWorld(), srcPos, srcState));
                    if (!match) {
                        consumeEnergy(Math.min(rfNeeded, BuilderConfiguration.builderRfPerSkipped));
                        // Skip this
                        return skip();
                    }
                }
            }
            if (!getCachedVoidableBlocks().contains(block)) {
                List<ItemStack> drops;
                if (silk && block.canSilkHarvest(getWorld(), srcPos, srcState, fakePlayer)) {
                    ItemStack drop;
                    try {
                        drop = (ItemStack) CommonProxy.Block_getSilkTouch.invoke(block, srcState);
                    } catch (IllegalAccessException | InvocationTargetException e) {
                        throw new RuntimeException(e);
                    }
                    drops = new ArrayList<>();
                    if (!drop.isEmpty()) {
                        drops.add(drop);
                    }
                    net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(drops, getWorld(), srcPos, srcState, 0, 1.0f, true, fakePlayer);
                } else {
                    int fortune = getCardType().isFortune() ? 3 : 0;
                    if (block instanceof BlockShulkerBox) {
                        // Shulker boxes drop in setBlockState, rather than anywhere sensible. Work around this.
                        drops = new ArrayList<>();
                        TileEntity te = getWorld().getTileEntity(srcPos);
                        if (te instanceof TileEntityShulkerBox) {
                            TileEntityShulkerBox teShulkerBox = (TileEntityShulkerBox) te;
                            ItemStack stack = new ItemStack(Item.getItemFromBlock(block));
                            teShulkerBox.saveToNbt(stack.getOrCreateSubCompound("BlockEntityTag"));
                            if (teShulkerBox.hasCustomName()) {
                                stack.setStackDisplayName(teShulkerBox.getName());
                            }
                            drops.add(stack);
                        }
                    } else {
                        drops = block.getDrops(getWorld(), srcPos, srcState, fortune);
                    }
                    net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(drops, getWorld(), srcPos, srcState, fortune, 1.0f, false, fakePlayer);
                }
                if (!checkAndInsertItems(block, drops)) {
                    // Not enough room. Wait
                    return waitOrSkip("Not enough room!\nor no usable storage\non top or below!");
                }
            }
            clearOrDirtBlock(rfNeeded, srcPos, srcState, clear);
        }
    }
    return silk ? skip() : false;
}
Also used : TileEntityShulkerBox(net.minecraft.tileentity.TileEntityShulkerBox) InvocationTargetException(java.lang.reflect.InvocationTargetException) FakePlayer(net.minecraftforge.common.util.FakePlayer) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockShulkerBox(net.minecraft.block.BlockShulkerBox) BaseBlock(mcjty.lib.container.BaseBlock) Block(net.minecraft.block.Block)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BaseBlock (mcjty.lib.container.BaseBlock)1 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)1 Block (net.minecraft.block.Block)1 BlockShulkerBox (net.minecraft.block.BlockShulkerBox)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityShulkerBox (net.minecraft.tileentity.TileEntityShulkerBox)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1