From 235d86ab8c8e99f08ec38483ae086d8f452a3a91 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 25 Jan 2016 13:34:55 +0100 Subject: [PATCH] Semi-implemented new item system I guess? --- build.gradle | 2 +- .../mod/tile/TileEntityInventoryBase.java | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index e69289c47..0d0ec81ee 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ group = "de.ellpeck.actuallyadditions" archivesBaseName = "ActuallyAdditions" minecraft { - version = "1.8.9-11.15.0.1715" + version = "1.8.9-11.15.0.1718" runDir = "idea" mappings = "stable_20" 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 17b84f55c..b71af5608 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java @@ -11,22 +11,37 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumFacing; import net.minecraft.util.IChatComponent; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.SidedInvWrapper; + +import java.util.HashMap; +import java.util.Map; public abstract class TileEntityInventoryBase extends TileEntityBase implements ISidedInventory{ public ItemStack slots[]; public String name; + private Map itemHandlers = new HashMap(); + public TileEntityInventoryBase(int slots, String name){ this.initializeSlots(slots); this.name = "container."+ModUtil.MOD_ID_LOWER+"."+name; + + for(EnumFacing facing : EnumFacing.values()){ + this.itemHandlers.put(facing, new SidedInvWrapper(this, facing)); + } } public void initializeSlots(int itemAmount){ @@ -198,6 +213,17 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements @Override public IChatComponent getDisplayName(){ - return null; + return new ChatComponentText(StringUtil.localize(this.getName())); } + + @Override + public T getCapability(Capability capability, EnumFacing facing){ + if(facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){ + return (T)this.itemHandlers.get(facing); + } + else{ + return super.getCapability(capability, facing); + } + } + }