Search in sources :

Example 1 with SidedInvWrapper

use of net.minecraftforge.items.wrapper.SidedInvWrapper in project BloodMagic by WayofTime.

the class TileInventory method initializeItemHandlers.

protected void initializeItemHandlers() {
    if (this instanceof ISidedInventory) {
        handlerDown = new SidedInvWrapper((ISidedInventory) this, EnumFacing.DOWN);
        handlerUp = new SidedInvWrapper((ISidedInventory) this, EnumFacing.UP);
        handlerNorth = new SidedInvWrapper((ISidedInventory) this, EnumFacing.NORTH);
        handlerSouth = new SidedInvWrapper((ISidedInventory) this, EnumFacing.SOUTH);
        handlerWest = new SidedInvWrapper((ISidedInventory) this, EnumFacing.WEST);
        handlerEast = new SidedInvWrapper((ISidedInventory) this, EnumFacing.EAST);
    } else {
        handlerDown = new InvWrapper(this);
        handlerUp = handlerDown;
        handlerNorth = handlerDown;
        handlerSouth = handlerDown;
        handlerWest = handlerDown;
        handlerEast = handlerDown;
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) SidedInvWrapper(net.minecraftforge.items.wrapper.SidedInvWrapper) SidedInvWrapper(net.minecraftforge.items.wrapper.SidedInvWrapper) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper)

Example 2 with SidedInvWrapper

use of net.minecraftforge.items.wrapper.SidedInvWrapper in project BuildCraft by BuildCraft.

the class TileBuildCraft method getCapability.

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
    if (capability == CapUtil.CAP_ITEMS) {
        if (this instanceof IInventory) {
            if (invWrapper == null) {
                if (this instanceof ISidedInventory) {
                    invWrapper = new IItemHandler[7];
                    for (EnumFacing facing1 : EnumFacing.VALUES) {
                        invWrapper[facing1.ordinal()] = new SidedInvWrapper((ISidedInventory) this, facing);
                    }
                    invWrapper[6] = new SidedInvWrapper((ISidedInventory) this, null);
                } else {
                    invWrapper = new IItemHandler[1];
                    invWrapper[0] = new InvWrapper((IInventory) this);
                }
            }
            if (invWrapper.length == 7) {
                return (T) invWrapper[facing == null ? 6 : facing.ordinal()];
            } else {
                return (T) invWrapper[0];
            }
        }
        return null;
    } else {
        return super.getCapability(capability, facing);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) SidedInvWrapper(net.minecraftforge.items.wrapper.SidedInvWrapper) EnumFacing(net.minecraft.util.EnumFacing) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) SidedInvWrapper(net.minecraftforge.items.wrapper.SidedInvWrapper)

Example 3 with SidedInvWrapper

use of net.minecraftforge.items.wrapper.SidedInvWrapper in project Bookshelf by Darkhax-Minecraft.

the class InventoryUtils method getInventory.

/**
 * Gets an inventory from a position within the world. If no tile exists or the tile does
 * not have the inventory capability the empty inventory handler will be returned.
 *
 * @param world The world instance.
 * @param pos The position of the expected tile entity.
 * @param side The side to access the inventory from.
 * @return The inventory handler. Will be empty if none was found.
 */
public static IItemHandler getInventory(World world, BlockPos pos, Direction side) {
    final TileEntity tileEntity = world.getBlockEntity(pos);
    if (tileEntity != null) {
        final LazyOptional<IItemHandler> inventoryCap = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
        return inventoryCap.orElse(EmptyHandler.INSTANCE);
    } else {
        // Some blocks like composters are not tile entities so their inv can not be
        // accessed through the normal capability system.
        final BlockState state = world.getBlockState(pos);
        if (state.getBlock() instanceof ISidedInventoryProvider) {
            final ISidedInventoryProvider inventoryProvider = (ISidedInventoryProvider) state.getBlock();
            final ISidedInventory inventory = inventoryProvider.getContainer(state, world, pos);
            if (inventory != null) {
                return new SidedInvWrapper(inventory, side);
            }
        }
    }
    return EmptyHandler.INSTANCE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISidedInventory(net.minecraft.inventory.ISidedInventory) ISidedInventoryProvider(net.minecraft.inventory.ISidedInventoryProvider) BlockState(net.minecraft.block.BlockState) IItemHandler(net.minecraftforge.items.IItemHandler) SidedInvWrapper(net.minecraftforge.items.wrapper.SidedInvWrapper)

Aggregations

ISidedInventory (net.minecraft.inventory.ISidedInventory)3 SidedInvWrapper (net.minecraftforge.items.wrapper.SidedInvWrapper)3 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 BlockState (net.minecraft.block.BlockState)1 IInventory (net.minecraft.inventory.IInventory)1 ISidedInventoryProvider (net.minecraft.inventory.ISidedInventoryProvider)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 IItemHandler (net.minecraftforge.items.IItemHandler)1