Advertisement
Guest User

Wool Dyer Tile Entity

a guest
Nov 3rd, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. package phnxflms.unidye;
  2.  
  3. import ic2.api.energy.prefab.BasicSink;
  4. import ic2.api.tile.IWrenchable;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.inventory.IInventory;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.nbt.NBTTagCompound;
  9. import net.minecraft.nbt.NBTTagList;
  10. import net.minecraft.src.ModLoader;
  11. import net.minecraft.tileentity.TileEntity;
  12. import net.minecraft.world.Explosion;
  13.  
  14. public class TileEntityWoolDyer extends TileEntity implements IInventory, IWrenchable{
  15.  
  16. protected BasicSink ic2EnergySink = new BasicSink(this, 1000, 1);
  17.  
  18. private ItemStack[] inv;
  19. public int woolCount = 0;
  20.  
  21. public TileEntityWoolDyer() {
  22. inv = new ItemStack[3];
  23. }
  24.  
  25. @Override
  26. public void onChunkUnload(){
  27. ic2EnergySink.onChunkUnload();
  28. super.onChunkUnload();
  29. }
  30.  
  31. public void readFromNBT(NBTTagCompound nbttagcompound){
  32. super.readFromNBT(nbttagcompound);
  33. ic2EnergySink.readFromNBT(nbttagcompound);
  34.  
  35. this.woolCount = nbttagcompound.getInteger("woolCount");
  36.  
  37. NBTTagList tagList = nbttagcompound.getTagList("Inventory");
  38. for (int i = 0; i < tagList.tagCount(); i++) {
  39. NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
  40. byte slot = tag.getByte("Slot");
  41. if (slot >= 0 && slot < inv.length) {
  42. inv[slot] = ItemStack.loadItemStackFromNBT(tag);
  43. }
  44. }
  45. }
  46.  
  47. public void writeToNBT(NBTTagCompound nbttagcompound){
  48. super.writeToNBT(nbttagcompound);
  49. ic2EnergySink.writeToNBT(nbttagcompound);
  50.  
  51. nbttagcompound.setInteger("woolCount", woolCount);
  52.  
  53. NBTTagList itemList = new NBTTagList();
  54. for (int i = 0; i < inv.length; i++) {
  55. ItemStack stack = inv[i];
  56. if (stack != null) {
  57. NBTTagCompound tag = new NBTTagCompound();
  58. tag.setByte("Slot", (byte) i);
  59. stack.writeToNBT(tag);
  60. itemList.appendTag(tag);
  61. }
  62. }
  63. nbttagcompound.setTag("Inventory", itemList);
  64. }
  65.  
  66. public void updateEntity(){
  67. ic2EnergySink.updateEntity();
  68. }
  69.  
  70. @Override
  71. public void invalidate(){
  72. ic2EnergySink.invalidate();
  73. super.invalidate();
  74. onChunkUnload();
  75. }
  76.  
  77. @Override
  78. public int getSizeInventory() {
  79. return inv.length;
  80. }
  81.  
  82. @Override
  83. public ItemStack getStackInSlot(int i) {
  84. return inv[i];
  85. }
  86.  
  87. @Override
  88. public ItemStack decrStackSize(int slot, int amt) {
  89. ItemStack stack = getStackInSlot(slot);
  90. if (stack != null) {
  91. if (stack.stackSize <= amt) {
  92. setInventorySlotContents(slot, null);
  93. } else {
  94. stack = stack.splitStack(amt);
  95. if (stack.stackSize == 0) {
  96. setInventorySlotContents(slot, null);
  97. }
  98. }
  99. }
  100. return stack;
  101. }
  102.  
  103. @Override
  104. public ItemStack getStackInSlotOnClosing(int slot) {
  105. ItemStack stack = getStackInSlot(slot);
  106. if (stack != null) {
  107. setInventorySlotContents(slot, null);
  108. }
  109. return stack;
  110. }
  111.  
  112. @Override
  113. public void setInventorySlotContents(int slot, ItemStack stack) {
  114. inv[slot] = stack;
  115. if (stack != null && stack.stackSize > getInventoryStackLimit()) {
  116. stack.stackSize = getInventoryStackLimit();
  117. }
  118.  
  119. }
  120.  
  121. @Override
  122. public String getInvName() {
  123. return "unidye.tileentitywooldyer";
  124. }
  125.  
  126. @Override
  127. public boolean isInvNameLocalized() {
  128. return false;
  129. }
  130.  
  131. @Override
  132. public int getInventoryStackLimit() {
  133. return 64;
  134. }
  135.  
  136. @Override
  137. public boolean isUseableByPlayer(EntityPlayer entityplayer) {
  138. return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&
  139. entityplayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
  140. }
  141.  
  142. @Override
  143. public void openChest() {
  144.  
  145. }
  146.  
  147. @Override
  148. public void closeChest() {
  149.  
  150. }
  151.  
  152. @Override
  153. public boolean isItemValidForSlot(int i, ItemStack itemstack) {
  154. return false;
  155. }
  156.  
  157. @Override
  158. public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
  159. return false;
  160. }
  161.  
  162. @Override
  163. public short getFacing() {
  164. return 0;
  165. }
  166.  
  167. @Override
  168. public void setFacing(short facing) {
  169.  
  170. }
  171.  
  172. @Override
  173. public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
  174. return true;
  175. }
  176.  
  177. @Override
  178. public float getWrenchDropRate() {
  179. return 1F;
  180. }
  181.  
  182. @Override
  183. public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
  184. return new ItemStack(Unidye.woolDyer, 1);
  185. }
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement