Make TETeleposer extend TEInventory
This commit is contained in:
parent
3bb437d751
commit
252555cb3e
1 changed files with 5 additions and 120 deletions
|
@ -20,20 +20,19 @@ import net.minecraftforge.common.util.Constants;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TETeleposer extends TileEntity implements IInventory
|
public class TETeleposer extends TEInventory
|
||||||
{
|
{
|
||||||
private ItemStack[] inv;
|
public static final int sizeInv = 1;
|
||||||
|
|
||||||
private int resultID;
|
private int resultID;
|
||||||
private int resultDamage;
|
private int resultDamage;
|
||||||
private int previousInput;
|
private int previousInput;
|
||||||
|
|
||||||
public static final int sizeInv = 1;
|
|
||||||
|
|
||||||
private boolean isActive;
|
private boolean isActive;
|
||||||
|
|
||||||
public TETeleposer()
|
public TETeleposer()
|
||||||
{
|
{
|
||||||
this.inv = new ItemStack[1];
|
super(sizeInv);
|
||||||
resultID = 0;
|
resultID = 0;
|
||||||
resultDamage = 0;
|
resultDamage = 0;
|
||||||
isActive = false;
|
isActive = false;
|
||||||
|
@ -44,18 +43,6 @@ public class TETeleposer extends TileEntity implements IInventory
|
||||||
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
|
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
|
||||||
{
|
{
|
||||||
super.readFromNBT(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");
|
resultID = par1NBTTagCompound.getInteger("resultID");
|
||||||
resultDamage = par1NBTTagCompound.getInteger("resultDamage");
|
resultDamage = par1NBTTagCompound.getInteger("resultDamage");
|
||||||
|
@ -67,122 +54,25 @@ public class TETeleposer extends TileEntity implements IInventory
|
||||||
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
|
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
|
||||||
{
|
{
|
||||||
super.writeToNBT(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("resultID", resultID);
|
||||||
par1NBTTagCompound.setInteger("resultDamage", resultDamage);
|
par1NBTTagCompound.setInteger("resultDamage", resultDamage);
|
||||||
par1NBTTagCompound.setTag("Inventory", itemList);
|
|
||||||
par1NBTTagCompound.setBoolean("isActive", isActive);
|
par1NBTTagCompound.setBoolean("isActive", isActive);
|
||||||
par1NBTTagCompound.setInteger("previousInput", previousInput);
|
par1NBTTagCompound.setInteger("previousInput", previousInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public String getInventoryName()
|
public String getInventoryName()
|
||||||
{
|
{
|
||||||
return "TETeleposer";
|
return "TETeleposer";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCustomInventoryName()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit()
|
public int getInventoryStackLimit()
|
||||||
{
|
{
|
||||||
return 1;
|
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
|
//Logic for the actual block is under here
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
|
@ -356,12 +246,7 @@ public class TETeleposer extends TileEntity implements IInventory
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
|
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
|
||||||
{
|
{
|
||||||
if (slot == 0)
|
return slot == 0;
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue