Advertisement
Guest User

Tile entity

a guest
Nov 24th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. package com.Looke81.BioWarfare.tileentity;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.init.Blocks;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.nbt.NBTTagCompound;
  8. import net.minecraft.nbt.NBTTagList;
  9. import net.minecraft.network.NetworkManager;
  10. import net.minecraft.network.Packet;
  11. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  12. import net.minecraft.tileentity.TileEntity;
  13. import net.minecraftforge.common.util.Constants;
  14.  
  15. public class TileEntityAgarPlate extends TileEntity implements IInventory{
  16. public static final int sizeInv = 1;
  17. private ItemStack[] inv;
  18. private int resultID;
  19. private int resultDamage;
  20. private int upgradeLevel;
  21. public int capacity;
  22. private boolean isActive;
  23. private int liquidRequired; //mB
  24. private boolean canBeFilled;
  25. private int consumptionRate;
  26. private int drainRate;
  27. private float consumptionMultiplier;
  28. private float efficiencyMultiplier;
  29. private float sacrificeEfficiencyMultiplier;
  30. private float selfSacrificeEfficiencyMultiplier;
  31. private float capacityMultiplier;
  32. private float orbCapacityMultiplier;
  33. private float dislocationMultiplier;
  34. private int accelerationUpgrades;
  35. private boolean isUpgraded;
  36. private boolean isResultBlock;
  37. private int bufferCapacity;
  38. private int progress;
  39. private int hasChanged = 0;
  40. public TileEntityAgarPlate()
  41. {
  42. this.inv = new ItemStack[1];
  43. resultID = 0;
  44. resultDamage = 0;
  45. isActive = false;
  46. consumptionRate = 0;
  47. drainRate = 0;
  48. consumptionMultiplier = 0;
  49. efficiencyMultiplier = 0;
  50. capacityMultiplier = 1;
  51. isUpgraded = false;
  52. upgradeLevel = 0;
  53. isResultBlock = false;
  54. progress = 0;
  55.  
  56. }
  57. public ItemStack displayItem;
  58.  
  59. public void writeToNBT(NBTTagCompound tag)
  60. {
  61. super.writeToNBT(tag);
  62. NBTTagList nbttaglist = new NBTTagList();
  63.  
  64. for (int i = 0; i < this.inv.length; ++i)
  65. {
  66. if (this.inv[i] != null)
  67. {
  68. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  69. nbttagcompound1.setByte("slot", (byte)i);
  70. this.inv[i].writeToNBT(nbttagcompound1);
  71. nbttaglist.appendTag(nbttagcompound1);
  72. }
  73. }
  74. }
  75.  
  76. public void readFromNBT(NBTTagCompound p_145839_1_)
  77. {
  78. super.readFromNBT(p_145839_1_);
  79. NBTTagList nbttaglist = p_145839_1_.getTagList("Items", 10);
  80. this.inv = new ItemStack[this.getSizeInventory()];
  81.  
  82.  
  83. for (int i = 0; i < nbttaglist.tagCount(); ++i)
  84. {
  85. NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
  86. int j = nbttagcompound1.getByte("slot");
  87.  
  88. if (j >= 0 && j < this.inv.length)
  89. {
  90. this.inv[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
  91. }
  92. }
  93. }
  94. @Override
  95. public Packet getDescriptionPacket() {
  96. NBTTagCompound nbtTag = new NBTTagCompound();
  97. writeToNBT(nbtTag);
  98. return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbtTag);
  99. }
  100.  
  101. @Override
  102. public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
  103. readFromNBT(packet.func_148857_g());
  104. }
  105.  
  106.  
  107.  
  108. @Override
  109. public ItemStack getStackInSlot(int slot)
  110. {
  111. return inv[slot];
  112.  
  113. }
  114.  
  115. @Override
  116. public int getSizeInventory() {
  117. return 1;
  118. }
  119.  
  120. @Override
  121. public ItemStack decrStackSize(int slot, int amt) {
  122. ItemStack stack = getStackInSlot(slot);
  123.  
  124. if (stack != null)
  125. {
  126. if (stack.stackSize <= amt)
  127. {
  128. setInventorySlotContents(slot, null);
  129. } else
  130. {
  131. stack = stack.splitStack(amt);
  132.  
  133. if (stack.stackSize == 0)
  134. {
  135. setInventorySlotContents(slot, null);
  136. }
  137. }
  138. }
  139.  
  140. return stack;
  141. }
  142.  
  143. @Override
  144. public ItemStack getStackInSlotOnClosing(int slot)
  145. {
  146. ItemStack stack = getStackInSlot(slot);
  147.  
  148. if (stack != null)
  149. {
  150. setInventorySlotContents(slot, null);
  151. }
  152.  
  153. return stack;
  154. }
  155.  
  156. @Override
  157. public void setInventorySlotContents(int slot, ItemStack itemStack)
  158. {
  159. inv[slot] = itemStack;
  160. this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
  161.  
  162. if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
  163. {
  164. itemStack.stackSize = getInventoryStackLimit();
  165. }
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172. @Override
  173. public String getInventoryName() {
  174. return "TileEntityAgarPlate" ;
  175. }
  176.  
  177. @Override
  178. public boolean hasCustomInventoryName() {
  179. return false;
  180. }
  181.  
  182. @Override
  183. public int getInventoryStackLimit() {
  184. return 2;
  185. }
  186.  
  187. @Override
  188. public boolean isUseableByPlayer(EntityPlayer entityPlayer)
  189. {
  190. return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
  191. }
  192.  
  193. @Override
  194. public void openInventory() {
  195.  
  196. }
  197.  
  198. @Override
  199. public void closeInventory() {
  200.  
  201. }
  202.  
  203. @Override
  204. public boolean isItemValidForSlot(int slot, ItemStack itemstack)
  205. {
  206. return slot == 0;
  207. }
  208.  
  209.  
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement