Make TESocket extend TEInventory

This commit is contained in:
ljfa-ag 2015-03-04 14:10:02 +01:00
parent 106eabbf9b
commit 3bb437d751

View file

@ -11,19 +11,18 @@ import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
public class TESocket extends TileEntity implements IInventory
public class TESocket extends TEInventory
{
private ItemStack[] inv;
public static final int sizeInv = 1;
private int resultID;
private int resultDamage;
public static final int sizeInv = 1;
private boolean isActive;
public TESocket()
{
this.inv = new ItemStack[1];
super(sizeInv);
resultID = 0;
resultDamage = 0;
isActive = false;
@ -33,18 +32,6 @@ public class TESocket extends TileEntity implements IInventory
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
resultID = par1NBTTagCompound.getInteger("resultID");
resultDamage = par1NBTTagCompound.getInteger("resultDamage");
@ -55,121 +42,24 @@ public class TESocket extends TileEntity implements IInventory
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
if (inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
inv[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
par1NBTTagCompound.setInteger("resultID", resultID);
par1NBTTagCompound.setInteger("resultDamage", resultDamage);
par1NBTTagCompound.setTag("Inventory", itemList);
par1NBTTagCompound.setBoolean("isActive", isActive);
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inv[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amt)
{
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
if (stack.stackSize <= amt)
{
setInventorySlotContents(slot, null);
} else
{
stack = stack.splitStack(amt);
if (stack.stackSize == 0)
{
setInventorySlotContents(slot, null);
}
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
setInventorySlotContents(slot, null);
}
return stack;
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemStack)
{
inv[slot] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName()
{
return "TESocket";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer)
{
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
//Logic for the actual block is under here
@Override
public void updateEntity()
@ -242,11 +132,6 @@ public class TESocket extends TileEntity implements IInventory
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
if (slot == 0)
{
return true;
}
return false;
return slot == 0;
}
}