Guest User

Untitled

a guest
Jan 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. public class TileEntityCocoaExtractor extends TileEntity
  4. implements IInventory
  5. {
  6.  
  7. public TileEntityCocoaExtractor()
  8. {
  9. cocoaExtractorItemStacks = new ItemStack[5];
  10. extractingTime = 0;
  11. currentItemBurnTime = 0;
  12. extractTime = 0;
  13. }
  14.  
  15. public int getSizeInventory()
  16. {
  17. return cocoaExtractorItemStacks.length;
  18. }
  19.  
  20. public ItemStack getStackInSlot(int i)
  21. {
  22. return cocoaExtractorItemStacks[i];
  23. }
  24.  
  25. public ItemStack decrStackSize(int i, int j)
  26. {
  27. if(cocoaExtractorItemStacks[i] != null)
  28. {
  29. if(cocoaExtractorItemStacks[i].stackSize <= j)
  30. {
  31. ItemStack itemstack = cocoaExtractorItemStacks[i];
  32. cocoaExtractorItemStacks[i] = null;
  33. return itemstack;
  34. }
  35. ItemStack itemstack1 = cocoaExtractorItemStacks[i].splitStack(j);
  36. if(cocoaExtractorItemStacks[i].stackSize == 0)
  37. {
  38. cocoaExtractorItemStacks[i] = null;
  39. }
  40. return itemstack1;
  41. } else
  42. {
  43. return null;
  44. }
  45. }
  46.  
  47. public void setInventorySlotContents(int i, ItemStack itemstack)
  48. {
  49. cocoaExtractorItemStacks[i] = itemstack;
  50. if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
  51. {
  52. itemstack.stackSize = getInventoryStackLimit();
  53. }
  54. }
  55.  
  56. public String getInvName()
  57. {
  58. return "CocoaExtractor";
  59. }
  60.  
  61. public void readFromNBT(NBTTagCompound nbttagcompound)
  62. {
  63. super.readFromNBT(nbttagcompound);
  64. NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
  65. cocoaExtractorItemStacks = new ItemStack[getSizeInventory()];
  66. for(int i = 0; i < nbttaglist.tagCount(); i++)
  67. {
  68. NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
  69. byte byte0 = nbttagcompound1.getByte("Slot");
  70. if(byte0 >= 0 && byte0 < cocoaExtractorItemStacks.length)
  71. {
  72. cocoaExtractorItemStacks[byte0] = new ItemStack(nbttagcompound1);
  73. }
  74. }
  75.  
  76. extractingTime = nbttagcompound.getShort("BurnTime");
  77. extractTime = nbttagcompound.getShort("CookTime");
  78. currentItemBurnTime = getItemBurnTime(cocoaExtractorItemStacks[1]);
  79. }
  80.  
  81. public void writeToNBT(NBTTagCompound nbttagcompound)
  82. {
  83. super.writeToNBT(nbttagcompound);
  84. nbttagcompound.setShort("BurnTime", (short)extractingTime);
  85. nbttagcompound.setShort("CookTime", (short)extractTime);
  86. NBTTagList nbttaglist = new NBTTagList();
  87. for(int i = 0; i < cocoaExtractorItemStacks.length; i++)
  88. {
  89. if(cocoaExtractorItemStacks[i] != null)
  90. {
  91. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  92. nbttagcompound1.setByte("Slot", (byte)i);
  93. cocoaExtractorItemStacks[i].writeToNBT(nbttagcompound1);
  94. nbttaglist.setTag(nbttagcompound1);
  95. }
  96. }
  97.  
  98. nbttagcompound.setTag("Items", nbttaglist);
  99. }
  100.  
  101. public int getInventoryStackLimit()
  102. {
  103. return 64;
  104. }
  105.  
  106. public int getCookProgressScaled(int i)
  107. {
  108. return (extractTime * i) / 200;
  109. }
  110.  
  111. public int getBurnTimeRemainingScaled(int i)
  112. {
  113. if(currentItemBurnTime == 0)
  114. {
  115. currentItemBurnTime = 200;
  116. }
  117. return (extractingTime * i) / currentItemBurnTime;
  118. }
  119.  
  120. public boolean isBurning()
  121. {
  122. return extractingTime > 0;
  123. }
  124.  
  125. public void updateEntity()
  126. {
  127. boolean flag = extractingTime > 0;
  128. boolean flag1 = false;
  129. if(extractingTime > 0)
  130. {
  131. extractingTime--;
  132. }
  133. if(!worldObj.multiplayerWorld)
  134. {
  135. if(extractingTime == 0 && canSmelt())
  136. {
  137. currentItemBurnTime = extractingTime = getItemBurnTime(cocoaExtractorItemStacks[1]);
  138. if(extractingTime > 0)
  139. {
  140. flag1 = true;
  141. if(cocoaExtractorItemStacks[1] != null)
  142. {
  143. if(cocoaExtractorItemStacks[1].getItem().hasContainerItem())
  144. {
  145. cocoaExtractorItemStacks[1] = new ItemStack(cocoaExtractorItemStacks[1].getItem().getContainerItem());
  146. } else
  147. {
  148. cocoaExtractorItemStacks[1].stackSize--;
  149. }
  150. if(cocoaExtractorItemStacks[1].stackSize == 0)
  151. {
  152. cocoaExtractorItemStacks[1] = null;
  153. }
  154. }
  155. }
  156. }
  157. if(isBurning() && canSmelt())
  158. {
  159. extractTime++;
  160. if(extractTime == 200)
  161. {
  162. extractTime = 0;
  163. smeltItem();
  164. flag1 = true;
  165. }
  166. } else
  167. {
  168. extractTime = 0;
  169. }
  170. if(flag != (extractingTime > 0))
  171. {
  172. flag1 = true;
  173. BlockCocoaExtractor.updateCocoaExtractorBlockState(extractingTime > 0, worldObj, xCoord, yCoord, zCoord);
  174. }
  175. }
  176. if(flag1)
  177. {
  178. onInventoryChanged();
  179. }
  180. }
  181.  
  182. private boolean canSmelt()
  183. {
  184. if(cocoaExtractorItemStacks[0] == null)
  185. {
  186. return false;
  187. }
  188. ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(cocoaExtractorItemStacks[0].getItem().shiftedIndex);
  189. if(itemstack == null)
  190. {
  191. return false;
  192. }
  193. if(cocoaExtractorItemStacks[2] == null)
  194. {
  195. if(cocoaExtractorItemStacks[3] == null)
  196. if(cocoaExtractorItemStacks[4] == null)
  197. {
  198. return true;
  199. } else
  200. if(!cocoaExtractorItemStacks[3].isItemEqual(itemstack))
  201. {
  202. return false;
  203. }else
  204. if(!cocoaExtractorItemStacks[4].isItemEqual(itemstack))
  205. {
  206. return false;
  207. }
  208. } else
  209. if(!cocoaExtractorItemStacks[2].isItemEqual(itemstack))
  210. {
  211. return false;
  212. }
  213. if(cocoaExtractorItemStacks[3] == null)
  214. {
  215. return true;
  216. }
  217. if(cocoaExtractorItemStacks[4] == null)
  218. {
  219. return true;
  220. }
  221. if(cocoaExtractorItemStacks[2].stackSize < getInventoryStackLimit() && cocoaExtractorItemStacks[2].stackSize < cocoaExtractorItemStacks[2].getMaxStackSize() && cocoaExtractorItemStacks[3].stackSize < getInventoryStackLimit() && cocoaExtractorItemStacks[3].stackSize < cocoaExtractorItemStacks[3].getMaxStackSize() && cocoaExtractorItemStacks[4].stackSize < getInventoryStackLimit() && cocoaExtractorItemStacks[4].stackSize < cocoaExtractorItemStacks[4].getMaxStackSize())
  222. {
  223. return true;
  224. }
  225. return cocoaExtractorItemStacks[2].stackSize < itemstack.getMaxStackSize() && cocoaExtractorItemStacks[3].stackSize < itemstack.getMaxStackSize() && cocoaExtractorItemStacks[4].stackSize < itemstack.getMaxStackSize();
  226.  
  227. }
  228.  
  229.  
  230. public void smeltItem()
  231. {
  232. if(!canSmelt())
  233. {
  234. return;
  235. }
  236. ItemStack itemstack2 = FurnaceRecipes.smelting().getSmeltingResult(cocoaExtractorItemStacks[0].getItem().shiftedIndex);
  237. if(cocoaExtractorItemStacks[4] == null)
  238. {
  239. cocoaExtractorItemStacks[4] = itemstack2.copy();
  240. } else
  241. if(cocoaExtractorItemStacks[4].itemID == itemstack2.itemID)
  242. {
  243. cocoaExtractorItemStacks[4].stackSize += itemstack2.stackSize;
  244. }
  245. if(cocoaExtractorItemStacks[0].getItem().hasContainerItem())
  246. {
  247. cocoaExtractorItemStacks[0] = new ItemStack(cocoaExtractorItemStacks[0].getItem().getContainerItem());
  248. } else
  249. {
  250. cocoaExtractorItemStacks[0].stackSize--;
  251. }
  252. if(cocoaExtractorItemStacks[0].stackSize <= 0)
  253. {
  254. cocoaExtractorItemStacks[0] = null;
  255. }
  256.  
  257. }
  258.  
  259. private int getItemBurnTime(ItemStack itemstack)
  260. {
  261. if(itemstack == null)
  262. {
  263. return 0;
  264. }
  265. int i = itemstack.getItem().shiftedIndex;
  266. if(i == Item.coal.shiftedIndex)
  267. {
  268. return 2400;
  269. }
  270.  
  271. else
  272. {
  273. return 0;
  274. }
  275. }
  276.  
  277. public boolean canInteractWith(EntityPlayer entityplayer)
  278. {
  279. if(worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
  280. {
  281. return false;
  282. }
  283. return entityplayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
  284. }
  285.  
  286. public void onInventoryChanged()
  287. {
  288. }
  289.  
  290. public void func_35142_x_()
  291. {
  292. }
  293.  
  294. public void func_35141_y_()
  295.  
  296. {
  297. }
  298.  
  299. private ItemStack cocoaExtractorItemStacks[];
  300. public int extractingTime;
  301. public int currentItemBurnTime;
  302. public int extractTime;
  303.  
  304. }
Add Comment
Please, Sign In to add comment