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;
}
}
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);
}
}
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;
}
Aggregations