mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Added InvWrapper Capabilities to inventories
This commit is contained in:
parent
b3729703b7
commit
11bc13aefd
3 changed files with 38 additions and 1 deletions
|
@ -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> T getCapability(Capability<T> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> T getCapability(Capability<T> capability, EnumFacing facing){
|
||||
return this.isBoundThingInRange() ? this.worldObj.getTileEntity(this.boundPosition).getCapability(capability, facing) : super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue