Guest User

Untitled

a guest
Feb 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. import forge.ISidedInventory;
  2. import ic2.common.IHasGuiContainer;
  3. import ic2.platform.Platform;
  4. import java.util.HashMap;
  5. import java.util.Random;
  6.  
  7. public class TileEntityRotary extends TileEntityAdvBlock3
  8. implements IHasGuiContainer, ISidedInventory
  9. {
  10. public int soundTicker;
  11. public static short maxSpeed = 10000;
  12. public short speed;
  13. public short progress;
  14. public static HashMap maceration;
  15. private static final int inputSlot = 0;
  16. private static final int fuelSlot = 1;
  17. private static final int outputSlot = 2;
  18.  
  19. public TileEntityRotary()
  20. {
  21. super(4, 2, maxSpeed, 128);
  22. this.speed = 0;
  23. this.progress = 0;
  24. this.wrenchRate = 0.8F;
  25. this.soundTicker = mod_IC2.random.nextInt(64);
  26. }
  27.  
  28. public String c()
  29. {
  30. if (Platform.isRendering())
  31. {
  32. return "Rotary Macerator";
  33. }
  34.  
  35. return "RotaryMacerator";
  36. }
  37.  
  38. public void a(xb nbttagcompound)
  39. {
  40. super.a(nbttagcompound);
  41. this.speed = nbttagcompound.d("speed");
  42. this.progress = nbttagcompound.d("progress");
  43. }
  44.  
  45. public void b(xb nbttagcompound)
  46. {
  47. super.b(nbttagcompound);
  48. nbttagcompound.a("speed", this.speed);
  49. nbttagcompound.a("progress", this.progress);
  50. }
  51.  
  52. public String getSpeed()
  53. {
  54. return "" + this.speed + " RPM";
  55. }
  56.  
  57. public int gaugeProgressScaled(int i)
  58. {
  59. return i * this.progress / 4000;
  60. }
  61.  
  62. public int gaugeFuelScaled(int i)
  63. {
  64. return i * this.energy / this.maxEnergy;
  65. }
  66.  
  67. public void b_()
  68. {
  69. super.b_();
  70. if (Platform.isSimulating())
  71. {
  72. boolean flag = false;
  73. if (this.energy <= this.maxEnergy)
  74. {
  75. flag = provideEnergy();
  76. }
  77. boolean flag1 = getActive();
  78. if (this.progress >= 4000)
  79. {
  80. operate();
  81. flag = true;
  82. this.progress = 0;
  83. flag1 = false;
  84. }
  85. boolean flag2 = canOperate();
  86. if ((this.energy > 0) && ((flag2) || (isRedstonePowered())))
  87. {
  88. this.energy -= 1;
  89. if (this.speed < maxSpeed)
  90. {
  91. this.speed = (short)(this.speed + 1);
  92. }
  93. flag1 = true;
  94. }
  95. else {
  96. this.speed = (short)(this.speed - Math.min(this.speed, 4));
  97. }
  98. if ((!flag1) || (this.progress == 0))
  99. {
  100. if (flag2)
  101. {
  102. if (this.energy >= 15)
  103. {
  104. flag1 = true;
  105. }
  106. }
  107. else {
  108. this.progress = 0;
  109. }
  110. }
  111. else if ((!flag2) || (this.energy < 15))
  112. {
  113. if (!flag2)
  114. {
  115. this.progress = 0;
  116. }
  117. flag1 = false;
  118. }
  119. if ((flag1) && (flag2))
  120. {
  121. this.progress = (short)(this.progress + this.speed / 30);
  122. this.energy -= 15;
  123. }
  124. if (flag)
  125. {
  126. l();
  127. }
  128. if (flag1 != getActive())
  129. {
  130. setActive(flag1);
  131. }
  132. }
  133. }
  134.  
  135. public void operate()
  136. {
  137. if (!canOperate())
  138. {
  139. return;
  140. }
  141. ul itemstack = getResultFor(this.inventory[0]);
  142. if (this.inventory[2] == null)
  143. {
  144. this.inventory[2] = itemstack.k();
  145. }
  146. else if (this.inventory[2].a + itemstack.a >= this.inventory[2].c() + 1)
  147. {
  148. if (this.inventory[3] == null)
  149. {
  150. this.inventory[3] = itemstack.k();
  151. }
  152. else
  153. {
  154. this.inventory[3].a += itemstack.a;
  155. }
  156. }
  157. else if (!this.inventory[2].a(itemstack))
  158. {
  159. if (this.inventory[3] == null)
  160. {
  161. this.inventory[3] = itemstack.k();
  162. }
  163. else
  164. {
  165. this.inventory[3].a += itemstack.a;
  166. }
  167. }
  168. else
  169. {
  170. this.inventory[2].a += itemstack.a;
  171. }
  172. if (this.inventory[0].a().j())
  173. {
  174. this.inventory[0] = new ul(this.inventory[0].a().i());
  175. }
  176. else {
  177. this.inventory[0].a -= 1;
  178. }
  179. if (this.inventory[0].a <= 0)
  180. {
  181. this.inventory[0] = null;
  182. }
  183. }
  184.  
  185. public boolean canOperate()
  186. {
  187. if (this.inventory[0] == null)
  188. {
  189. return false;
  190. }
  191. ul itemstack = getResultFor(this.inventory[0]);
  192. if (itemstack == null)
  193. {
  194. return false;
  195. }
  196. if ((this.inventory[2] == null) || (this.inventory[3] == null))
  197. {
  198. return true;
  199. }
  200. if ((!this.inventory[3].a(itemstack)) && (!this.inventory[2].a(itemstack)))
  201. {
  202. return false;
  203. }
  204.  
  205. return (this.inventory[2].a < this.inventory[2].c() - 1) || (this.inventory[3].a < this.inventory[3].c() - 1);
  206. }
  207.  
  208. public boolean isRedstonePowered()
  209. {
  210. return this.i.r(this.j, this.k, this.l);
  211. }
  212.  
  213. public static void initmaceration()
  214. {
  215. maceration = new HashMap();
  216. addRecipe(lr.I.bA, new ul(mod_IC2.itemDustIron, 2));
  217. addRecipe(lr.H.bA, new ul(mod_IC2.itemDustGold, 2));
  218. addRecipe(mod_IC2.blockOreTin.bA, new ul(mod_IC2.itemDustTin, 2));
  219. addRecipe(mod_IC2.blockOreCopper.bA, new ul(mod_IC2.itemDustCopper, 2));
  220. addRecipe(sv.n.br, new ul(mod_IC2.itemDustCoal));
  221. addRecipe(mod_IC2.itemIngotAdvIron.br, new ul(mod_IC2.itemDustIron));
  222. addRecipe(mod_IC2.itemIngotTin.br, new ul(mod_IC2.itemDustTin));
  223. addRecipe(mod_IC2.itemIngotCopper.br, new ul(mod_IC2.itemDustCopper));
  224. addRecipe(sv.p.br, new ul(mod_IC2.itemDustIron));
  225. addRecipe(mod_IC2.itemIngotAdvIron.br, new ul(mod_IC2.itemDustIron));
  226. addRecipe(sv.q.br, new ul(mod_IC2.itemDustGold));
  227. addRecipe(lr.ac.bA, new ul(sv.L));
  228. addRecipe(lr.G.bA, new ul(sv.aq));
  229. addRecipe(lr.u.bA, new ul(lr.x));
  230. addRecipe(lr.x.bA, new ul(lr.F));
  231. addRecipe(lr.R.bA, new ul(lr.F));
  232. addRecipe(lr.aU.bA, new ul(sv.aE));
  233. }
  234.  
  235. public static void addRecipe(int i, ul itemstack)
  236. {
  237. maceration.put(Integer.valueOf(i), itemstack);
  238. }
  239.  
  240. public ul getResultFor(ul itemstack)
  241. {
  242. if ((itemstack.c == sv.n.br) && (itemstack.i() != 0))
  243. {
  244. return null;
  245. }
  246.  
  247. return (ul)maceration.get(Integer.valueOf(itemstack.c));
  248. }
  249.  
  250. public cf getGuiContainer(ui inventoryplayer)
  251. {
  252. return new ContainerRotary(inventoryplayer, this);
  253. }
  254.  
  255. public int getStartInventorySide(int i)
  256. {
  257. switch (i)
  258. {
  259. case 0:
  260. return 1;
  261. case 1:
  262. return 0;
  263. }
  264. return 2;
  265. }
  266.  
  267. public int getSizeInventorySide(int i)
  268. {
  269. switch (i)
  270. {
  271. case 0:
  272. return 1;
  273. }
  274. return 2;
  275. }
  276. }
Add Comment
Please, Sign In to add comment