CD4017BE / InductiveAutomation

Minecraft tech mod
MIT License
5 stars 2 forks source link

Support for item handler capability #7

Closed raoulvdberge closed 7 years ago

raoulvdberge commented 8 years ago

Currently pipes can't take items from a tile that uses Forge's capability system, it depends on IInventory.

Instead of checking for TileEntity you could check for IItemHandler (and still have compatibility with old IInventory) using this snippet:

    public static IItemHandler getItemHandler(TileEntity tile, EnumFacing side) {
        if (tile == null) {
            return null;
        }

        IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);

        if (handler == null) {
            if (side != null && tile instanceof ISidedInventory) {
                handler = new SidedInvWrapper((ISidedInventory) tile, side);
            } else if (tile instanceof IInventory) {
                handler = new InvWrapper((IInventory) tile);
            }
        }

        return handler;
    }

Of course the pipes would need to use the IItemHandler interface.

CD4017BE commented 8 years ago

I just started changing everything into Forge's capability system: Items, Fluids, Energy, Heat, Gas and maybe also some multiblock-machine related systems.

CD4017BE commented 7 years ago

CD4017BE_lib-4.3.0