Guest User

TileEntityForge

a guest
Mar 10th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.15 KB | None | 0 0
  1. public class TileEntityForge extends TileEntity implements ISidedInventory
  2. {
  3. private String localizedName;
  4.  
  5. private static final int[] slots_top = new int[] {0, 1, 2, 3};
  6. private static final int[] slots_bottom = new int[] {4, 5};
  7. private static final int[] slots_sides = new int[] {4};
  8.  
  9.  
  10. private ItemStack[] slots = new ItemStack[6];
  11.  
  12. public int furnaceSpeed = 500;
  13.  
  14.  
  15.  
  16. public int burnTime;
  17.  
  18. public int currentItemBurnTime;
  19.  
  20. public int cookTime;
  21.  
  22. public int getSizeInventory()
  23. {
  24. return this.slots.length;
  25. }
  26.  
  27. public boolean isInvNameLocalized()
  28. {
  29. return this.localizedName != null && this.localizedName.length() > 0;
  30.  
  31. }
  32.  
  33. public String getInvName()
  34. {
  35. return this.isInvNameLocalized() ? this.localizedName : "container.Forge";
  36. }
  37.  
  38. public void setGuiDisplayName(String displayName)
  39. {
  40. this.localizedName = displayName;
  41. }
  42.  
  43.  
  44. public ItemStack getStackInSlot(int i)
  45. {
  46. return this.slots[i];
  47. }
  48.  
  49.  
  50. public ItemStack decrStackSize(int i, int j)
  51. {
  52. if(this.slots[i] != null)
  53. {
  54. ItemStack itemstack;
  55.  
  56. if(this.slots[i].stackSize <= j)
  57. {
  58. itemstack = this.slots[i];
  59. this.slots[i] = null;
  60.  
  61. return itemstack;
  62. }
  63. else
  64. {
  65. itemstack = this.slots[i].splitStack(j);
  66.  
  67. if(this.slots[i].stackSize == 0)
  68. {
  69. this.slots[i] = null;
  70. }
  71.  
  72. return itemstack;
  73. }
  74. }
  75. return null;
  76. }
  77.  
  78.  
  79. public ItemStack getStackInSlotOnClosing(int i)
  80. {
  81. if(this.slots[i] != null)
  82. {
  83. ItemStack itemstack = this.slots[i];
  84.  
  85. this.slots[i] = null;
  86. return itemstack;
  87. }
  88.  
  89. return null;
  90. }
  91.  
  92.  
  93. public void setInventorySlotContents(int i, ItemStack itemstack)
  94. {
  95. this.slots[i] = itemstack;
  96.  
  97. if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
  98. {
  99. itemstack.stackSize = this.getInventoryStackLimit();
  100. }
  101. }
  102.  
  103.  
  104. public int getInventoryStackLimit()
  105. {
  106. return 64;
  107. }
  108.  
  109.  
  110. public boolean isUseableByPlayer(EntityPlayer entityplayer)
  111. {
  112. return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.getDistanceSq((double)this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
  113. }
  114.  
  115.  
  116. public void openChest()
  117. {
  118.  
  119. }
  120.  
  121.  
  122. public void closeChest()
  123. {
  124.  
  125. }
  126.  
  127. public boolean isBurning()
  128. {
  129. return this.burnTime > 0;
  130. }
  131.  
  132. public void updateEntity()
  133. {
  134. boolean flag = this.burnTime > 0;
  135. boolean flag1 = false;
  136.  
  137. if(this.burnTime > 0)
  138. {
  139. this.burnTime--;
  140. }
  141.  
  142. if(!this.worldObj.isRemote)
  143. {
  144. if(this.burnTime == 0 && this.canSmelt() && this.doStuff() && this.doStuff2() && this.doStuff3())
  145. {
  146. this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[4]);
  147.  
  148. if(this.burnTime > 0)
  149. {
  150. flag1 = true;
  151.  
  152. if(this.slots[4] != null)
  153. {
  154. this.slots[4].stackSize--;
  155.  
  156. if(this.slots[4].stackSize == 0)
  157. {
  158. this.slots[4] = this.slots[4].getItem().getContainerItemStack(this.slots[4]);
  159. }
  160. }
  161. }
  162. }
  163.  
  164. if(this.isBurning() && this.canSmelt() && this.doStuff() && this.doStuff2() && this.doStuff3())
  165. {
  166. this.cookTime++;
  167.  
  168. if(this.cookTime == this.furnaceSpeed)
  169. {
  170. this.cookTime = 0;
  171. this.smeltItem();
  172. flag1 = true;
  173. }
  174. }
  175.  
  176. else
  177. {
  178. this.cookTime = 0;
  179. }
  180.  
  181. if(flag != this.burnTime > 0)
  182. {
  183. flag1 = true;
  184. BlockForge.updateForgeBlockState(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
  185. }
  186. }
  187.  
  188. if(flag1)
  189. {
  190. this.onInventoryChanged();
  191. }
  192. }
  193.  
  194. private boolean canSmelt()
  195. {
  196. if(this.slots[0] == null)
  197. {
  198. return false;
  199. }
  200. else
  201. {
  202. ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);
  203.  
  204. if(itemstack == null) return false;
  205. if(this.slots[5] == null) return true;
  206. if(!this.slots[5].isItemEqual(itemstack)) return false;
  207.  
  208. return (this.slots[5].stackSize + itemstack.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack.stackSize <= itemstack.getMaxStackSize());
  209. }
  210.  
  211. }
  212.  
  213. public boolean doStuff()
  214. {
  215. if(this.slots[1] == null)
  216. {
  217. return false;
  218. }
  219. else
  220. {
  221. ItemStack itemstack1 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[1]);
  222.  
  223. if(itemstack1 == null) return false;
  224. if(this.slots[5] == null) return true;
  225. if(!this.slots[5].isItemEqual(itemstack1)) return false;
  226.  
  227. return (this.slots[5].stackSize + itemstack1.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack1.stackSize <= itemstack1.getMaxStackSize());
  228. }
  229.  
  230. }
  231.  
  232. public boolean doStuff2()
  233. {
  234.  
  235. if(this.slots[2] == null)
  236. {
  237. return false;
  238. }
  239. else
  240. {
  241. ItemStack itemstack2 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[2]);
  242.  
  243. if(itemstack2 == null) return false;
  244. if(this.slots[5] == null) return true;
  245. if(!this.slots[5].isItemEqual(itemstack2)) return false;
  246.  
  247. return (this.slots[5].stackSize + itemstack2.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack2.stackSize <= itemstack2.getMaxStackSize());
  248. }
  249. }
  250.  
  251. public boolean doStuff3()
  252. {
  253.  
  254. if(this.slots[3] == null)
  255. {
  256. return false;
  257. }
  258. else
  259. {
  260. ItemStack itemstack3 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[3]);
  261.  
  262. if(itemstack3 == null) return false;
  263. if(this.slots[5] == null) return true;
  264. if(!this.slots[5].isItemEqual(itemstack3)) return false;
  265.  
  266. return (this.slots[5].stackSize + itemstack3.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack3.stackSize <= itemstack3.getMaxStackSize());
  267. }
  268. }
  269.  
  270. public void smeltItem()
  271. {
  272. if(this.canSmelt() && this.doStuff() && this.doStuff2() && this.doStuff3())
  273. {
  274. ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);
  275. ItemStack itemstack1 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[1]);
  276. ItemStack itemstack2 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[2]);
  277. ItemStack itemstack3 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[3]);
  278.  
  279. if(this.slots[5] == null)
  280. {
  281. this.slots[5] = itemstack.copy();
  282. this.slots[5] = itemstack1.copy();
  283. this.slots[5] = itemstack2.copy();
  284. this.slots[5] = itemstack3.copy();
  285. }
  286. else if(this.slots[5].isItemEqual(itemstack))
  287. {
  288. this.slots[5].stackSize += itemstack.stackSize;
  289. }
  290. else if(this.slots[5].isItemEqual(itemstack1))
  291. {
  292. this.slots[5].stackSize += itemstack1.stackSize;
  293. }
  294. else if(this.slots[5].isItemEqual(itemstack2))
  295. {
  296. this.slots[5].stackSize += itemstack2.stackSize;
  297. }
  298. else if(this.slots[5].isItemEqual(itemstack3))
  299. {
  300. this.slots[5].stackSize += itemstack3.stackSize;
  301. }
  302.  
  303. this.slots[0].stackSize--;
  304. this.slots[1].stackSize--;
  305. this.slots[2].stackSize--;
  306. this.slots[3].stackSize--;
  307.  
  308. if(this.slots[0].stackSize <= 0 && this.slots[1].stackSize <= 0 && this.slots[2].stackSize <= 0 && this.slots[3].stackSize <= 0)
  309. {
  310. this.slots[0] = null;
  311. this.slots[1] = null;
  312. this.slots[2] = null;
  313. this.slots[3] = null;
  314. }
  315. }
  316. }
  317.  
  318. public static int getItemBurnTime(ItemStack itemstack)
  319. {
  320. if(itemstack == null)
  321. {
  322. return 0;
  323. }
  324. else
  325. {
  326. int i = itemstack.getItem().itemID;
  327.  
  328. if(i == Item.bucketLava.itemID) return 20000;
  329.  
  330. return GameRegistry.getFuelValue(itemstack);
  331. }
  332. }
  333.  
  334. public static boolean isItemFuel(ItemStack itemstack)
  335. {
  336. return getItemBurnTime(itemstack) == 20000;
  337. }
  338.  
  339. public boolean isItemValidForSlot(int i, ItemStack itemstack)
  340. {
  341. return i == 5 ? false : (i == 4 ? isItemFuel(itemstack) : true);
  342. }
  343.  
  344.  
  345. public int[] getAccessibleSlotsFromSide(int var1)
  346. {
  347. return var1 == 0 ? slots_bottom : (var1 == 4 ? slots_top : slots_sides);
  348. }
  349.  
  350.  
  351. public boolean canInsertItem(int i, ItemStack itemstack, int j)
  352. {
  353. return this.isItemValidForSlot(i, itemstack);
  354. }
  355.  
  356.  
  357. public boolean canExtractItem(int i, ItemStack itemstack, int j)
  358. {
  359. return j != 0 || i != 1 || itemstack.itemID == Item.bucketEmpty.itemID;
  360. }
  361.  
  362. }
Advertisement
Add Comment
Please, Sign In to add comment