Guest User

Untitled

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