diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java index 345b88464..b464c1f81 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java @@ -20,15 +20,23 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumFacing; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.wrapper.SidedInvWrapper; public abstract class TileEntityInventoryBase extends TileEntityBase implements ISidedInventory{ public ItemStack slots[]; public String name; + private SidedInvWrapper[] invWrappers = new SidedInvWrapper[6]; public TileEntityInventoryBase(int slots, String name){ this.initializeSlots(slots); this.name = "container."+ModUtil.MOD_ID+"."+name; + + for(int i = 0; i < this.invWrappers.length; i++){ + this.invWrappers[i] = new SidedInvWrapper(this, EnumFacing.values()[i]); + } } public void initializeSlots(int itemAmount){ @@ -203,4 +211,22 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements return new TextComponentString(StringUtil.localize(this.getName())); } + @Override + public boolean hasCapability(Capability capability, EnumFacing facing){ + return this.getCapability(capability, facing) != null; + } + + @Override + public T getCapability(Capability capability, EnumFacing facing){ + if(this.hasInvWrapperCapabilities() && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){ + return (T)this.invWrappers[facing.ordinal()]; + } + else{ + return super.getCapability(capability, facing); + } + } + + public boolean hasInvWrapperCapabilities(){ + return true; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java index e7e0dba00..44b407a54 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java @@ -16,6 +16,7 @@ import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.capabilities.Capability; public class TileEntityPhantomItemface extends TileEntityPhantomface{ @@ -110,7 +111,7 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{ @Override public boolean isBoundThingInRange(){ - return super.isBoundThingInRange() && this.worldObj.getTileEntity(this.boundPosition) instanceof IInventory; + return super.isBoundThingInRange() && this.getInventory() != null; } @Override @@ -122,4 +123,9 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{ public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canExtractItem(slot, stack, side)); } + + @Override + public T getCapability(Capability capability, EnumFacing facing){ + return this.isBoundThingInRange() ? this.worldObj.getTileEntity(this.boundPosition).getCapability(capability, facing) : super.getCapability(capability, facing); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java index 27ee9acea..1e45ae82a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java @@ -179,4 +179,9 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ return false; } + + @Override + public boolean hasInvWrapperCapabilities(){ + return false; + } }