Advertisement
Guest User

Untitled

a guest
Jan 5th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. package RUMatter.tileEntities;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.inventory.IInventory;
  5. import net.minecraft.item.ItemStack;
  6. import net.minecraft.nbt.NBTTagCompound;
  7. import net.minecraft.nbt.NBTTagList;
  8. import net.minecraft.tileentity.TileEntity;
  9.  
  10. public class TileEntityRUChest extends TileEntity implements IInventory {
  11.  
  12. private ItemStack[] inv;
  13.  
  14. public TileEntityRUChest() {
  15. inv = new ItemStack[9];
  16. }
  17.  
  18. @Override
  19. public int getSizeInventory() {
  20. return inv.length;
  21. }
  22.  
  23. @Override
  24. public ItemStack getStackInSlot(int slot) {
  25. return inv[slot];
  26. }
  27.  
  28. @Override
  29. public void setInventorySlotContents(int slot, ItemStack stack) {
  30. inv[slot] = stack;
  31. if (stack != null && stack.stackSize > getInventoryStackLimit()) {
  32. stack.stackSize = getInventoryStackLimit();
  33. }
  34. }
  35.  
  36. @Override
  37. public ItemStack decrStackSize(int slot, int amt) {
  38. ItemStack stack = getStackInSlot(slot);
  39. if (stack != null) {
  40. if (stack.stackSize <= amt)
  41. setInventorySlotContents(slot, null);
  42. else {
  43. stack = stack.splitStack(amt);
  44. if (stack.stackSize == 0) setInventorySlotContents(slot, null);
  45. }
  46. }
  47. return stack;
  48. }
  49.  
  50. @Override
  51. public ItemStack getStackInSlotOnClosing(int slot) {
  52. ItemStack stack = getStackInSlot(slot);
  53. if (stack != null) setInventorySlotContents(slot, null);
  54. return stack;
  55. }
  56.  
  57. @Override
  58. public int getInventoryStackLimit() {
  59. return 64;
  60. }
  61.  
  62. @Override
  63. public boolean isUseableByPlayer(EntityPlayer player) {
  64. return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
  65. }
  66.  
  67. @Override
  68. public void openChest() {
  69. // TODO Auto-generated method stub
  70.  
  71. }
  72.  
  73. @Override
  74. public void closeChest() {
  75. // TODO Auto-generated method stub
  76.  
  77. }
  78.  
  79. @Override
  80. public void readFromNBT(NBTTagCompound tagCompound) {
  81. super.readFromNBT(tagCompound);
  82.  
  83. NBTTagList tagList = tagCompound.getTagList("Inventory");
  84. for (int i = 0; i < tagList.tagCount(); i++) {
  85. NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
  86. byte slot = tag.getByte("Slot");
  87. if (slot >= 0 && slot < inv.length) {
  88. inv[slot] = ItemStack.loadItemStackFromNBT(tag);
  89. }
  90. }
  91. }
  92.  
  93. @Override
  94. public void writeToNBT(NBTTagCompound tagCompound) {
  95. super.writeToNBT(tagCompound);
  96.  
  97. NBTTagList itemList = new NBTTagList();
  98. for (int i = 0; i < inv.length; i++) {
  99. ItemStack stack = inv[i];
  100. if (stack != null) {
  101. NBTTagCompound tag = new NBTTagCompound();
  102. tag.setByte("Slot", (byte) i);
  103. stack.writeToNBT(tag);
  104. itemList.appendTag(tag);
  105. }
  106. }
  107. tagCompound.setTag("Inventory", itemList);
  108. }
  109.  
  110. @Override
  111. public String getInvName() {
  112. return "RUChest";
  113. }
  114.  
  115. @Override
  116. public boolean isInvNameLocalized() {
  117. return this.getInvName().length() > 0;
  118. }
  119.  
  120. @Override
  121. public boolean isItemValidForSlot(int slot, ItemStack stack) {
  122. return true;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement