Make TESocket extend TEInventory
This commit is contained in:
parent
106eabbf9b
commit
3bb437d751
1 changed files with 5 additions and 120 deletions
|
@ -11,19 +11,18 @@ import net.minecraft.network.Packet;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.Constants;
|
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 resultID;
|
||||||
private int resultDamage;
|
private int resultDamage;
|
||||||
|
|
||||||
public static final int sizeInv = 1;
|
|
||||||
|
|
||||||
private boolean isActive;
|
private boolean isActive;
|
||||||
|
|
||||||
public TESocket()
|
public TESocket()
|
||||||
{
|
{
|
||||||
this.inv = new ItemStack[1];
|
super(sizeInv);
|
||||||
resultID = 0;
|
resultID = 0;
|
||||||
resultDamage = 0;
|
resultDamage = 0;
|
||||||
isActive = false;
|
isActive = false;
|
||||||
|
@ -33,18 +32,6 @@ public class TESocket 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");
|
||||||
|
@ -55,121 +42,24 @@ public class TESocket 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 "TESocket";
|
return "TESocket";
|
||||||
}
|
}
|
||||||
|
|
||||||
@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()
|
||||||
|
@ -242,11 +132,6 @@ public class TESocket 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