Gintarus

trigg

Sep 15th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.79 KB | None | 0 0
  1. package ic2.bcIntigration.core.triggers;
  2.  
  3. import buildcraft.api.statements.IStatement;
  4. import buildcraft.api.statements.IStatementContainer;
  5. import buildcraft.api.statements.IStatementParameter;
  6. import buildcraft.api.statements.ITriggerExternal;
  7. import cpw.mods.fml.relauncher.Side;
  8. import cpw.mods.fml.relauncher.SideOnly;
  9. import ic2.api.item.IElectricItem;
  10. import ic2.core.Ic2Icons;
  11. import ic2.core.block.generator.tileentity.TileEntityBaseGenerator;
  12. import ic2.core.block.machine.tileentity.TileEntityAdvancedMachine;
  13. import ic2.core.block.machine.tileentity.TileEntityElectricMachine;
  14. import ic2.core.block.wiring.TileEntityElectricBlock;
  15. import ic2.core.item.ItemBatteryDischarged;
  16. import ic2.core.util.StackUtil;
  17. import net.minecraft.client.renderer.texture.IIconRegister;
  18. import net.minecraft.nbt.NBTTagCompound;
  19. import net.minecraft.tileentity.TileEntity;
  20. import net.minecraft.util.IIcon;
  21. import net.minecraft.util.StatCollector;
  22. import net.minecraftforge.common.util.ForgeDirection;
  23.  
  24. public class TriggerCapacitor
  25. implements ITriggerExternal {
  26. int action;
  27.  
  28. public TriggerCapacitor(int action) {
  29. this.action = action;
  30. }
  31.  
  32. public IStatementParameter createParameter(int arg0) {
  33. return null;
  34. }
  35.  
  36. public String getDescription() {
  37. String un = this.getUnlocalizedDistrciption();
  38. if (un == null) {
  39. return "This shouldn't happen";
  40. }
  41. return StatCollector.func_74838_a((String)("gate." + un + ".name"));
  42. }
  43.  
  44. private String getUnlocalizedDistrciption() {
  45. switch (this.action) {
  46. case 0: {
  47. return "energyStorageEmpty";
  48. }
  49. case 1: {
  50. return "energyStorageHasEnergy";
  51. }
  52. case 2: {
  53. return "energyStorageSpace";
  54. }
  55. case 3: {
  56. return "energyStorageFull";
  57. }
  58. case 4: {
  59. return "energyStorageItemEmptyCharge";
  60. }
  61. case 5: {
  62. return "energyStorageItemPartlyCharge";
  63. }
  64. case 6: {
  65. return "energyStorageItemFullyCharged";
  66. }
  67. case 7: {
  68. return "energyStorageDrainingEmptyItem";
  69. }
  70. case 8: {
  71. return "energyStorageDrainingChargedItem";
  72. }
  73. case 9: {
  74. return "energyStorageDrainingFullyChargedItem";
  75. }
  76. }
  77. return null;
  78. }
  79.  
  80. @SideOnly(value=Side.CLIENT)
  81. public IIcon getIcon() {
  82. return Ic2Icons.getTexture("triggers")[this.getIconID()];
  83. }
  84.  
  85. private int getIconID() {
  86. switch (this.action) {
  87. case 0: {
  88. return 0;
  89. }
  90. case 1: {
  91. return 1;
  92. }
  93. case 2: {
  94. return 2;
  95. }
  96. case 3: {
  97. return 3;
  98. }
  99. case 4: {
  100. return 4;
  101. }
  102. case 5: {
  103. return 5;
  104. }
  105. case 6: {
  106. return 6;
  107. }
  108. case 7: {
  109. return 9;
  110. }
  111. case 8: {
  112. return 7;
  113. }
  114. case 9: {
  115. return 8;
  116. }
  117. }
  118. return 0;
  119. }
  120.  
  121. public String getUniqueTag() {
  122. return "trigger.EUCapacitor." + this.action;
  123. }
  124.  
  125. public int maxParameters() {
  126. return 0;
  127. }
  128.  
  129. public int minParameters() {
  130. return 0;
  131. }
  132.  
  133. @SideOnly(value=Side.CLIENT)
  134. public void registerIcons(IIconRegister arg0) {
  135. }
  136.  
  137. public IStatement rotateLeft() {
  138. return this;
  139. }
  140.  
  141. public boolean isTriggerActive(TileEntity tile, ForgeDirection dir, IStatementContainer arg2, IStatementParameter[] arg3) {
  142. if (tile == null) {
  143. return false;
  144. }
  145. if (tile instanceof TileEntityElectricMachine) {
  146. TileEntityElectricMachine machine = (TileEntityElectricMachine)tile;
  147. boolean hasEnergy = machine.energy > machine.maxInput;
  148. boolean hasRoom = machine.energy < machine.maxEnergy - machine.maxInput;
  149. boolean dischargeEnergy = false;
  150. boolean dischargeRoom = false;
  151. if (machine.inventory[1] != null && machine.inventory[1].func_77973_b() instanceof IElectricItem) {
  152. IElectricItem ei = (IElectricItem)machine.inventory[1].func_77973_b();
  153. NBTTagCompound nbt = StackUtil.getOrCreateNbtData(machine.inventory[1]);
  154. if (nbt.func_74762_e("charge") > 0) {
  155. dischargeEnergy = true;
  156. }
  157. if ((double)nbt.func_74762_e("charge") < ei.getMaxCharge(machine.inventory[1])) {
  158. dischargeRoom = true;
  159. }
  160. } else if (machine.inventory[1] != null && machine.inventory[1].func_77973_b() instanceof ItemBatteryDischarged) {
  161. dischargeEnergy = false;
  162. dischargeRoom = true;
  163. } else if (this.action == 7 || this.action == 8 || this.action == 9) {
  164. return false;
  165. }
  166. switch (this.action) {
  167. case 0: {
  168. return !hasEnergy;
  169. }
  170. case 1: {
  171. return hasEnergy;
  172. }
  173. case 2: {
  174. return hasRoom;
  175. }
  176. case 3: {
  177. return !hasRoom;
  178. }
  179. case 7: {
  180. return !dischargeEnergy;
  181. }
  182. case 8: {
  183. return dischargeEnergy && dischargeRoom;
  184. }
  185. case 9: {
  186. return !dischargeRoom;
  187. }
  188. }
  189. } else if (tile instanceof TileEntityAdvancedMachine) {
  190. TileEntityAdvancedMachine machine = (TileEntityAdvancedMachine)tile;
  191. boolean hasEnergy = machine.energy > machine.maxInput;
  192. boolean hasRoom = machine.energy < machine.maxEnergy - machine.maxInput;
  193. boolean dischargeEnergy = false;
  194. boolean dischargeRoom = false;
  195. if (machine.inventory[0] != null && machine.inventory[0].func_77973_b() instanceof IElectricItem) {
  196. IElectricItem ei = (IElectricItem)machine.inventory[0].func_77973_b();
  197. NBTTagCompound nbt = StackUtil.getOrCreateNbtData(machine.inventory[0]);
  198. if (nbt.func_74762_e("charge") > 0) {
  199. dischargeEnergy = true;
  200. }
  201. if ((double)nbt.func_74762_e("charge") < ei.getMaxCharge(machine.inventory[0])) {
  202. dischargeRoom = true;
  203. }
  204. } else if (machine.inventory[0] != null && machine.inventory[0].func_77973_b() instanceof ItemBatteryDischarged) {
  205. dischargeEnergy = false;
  206. dischargeRoom = true;
  207. } else if (this.action == 7 || this.action == 8 || this.action == 9) {
  208. return false;
  209. }
  210. switch (this.action) {
  211. case 0: {
  212. return !hasEnergy;
  213. }
  214. case 1: {
  215. return hasEnergy;
  216. }
  217. case 2: {
  218. return hasRoom;
  219. }
  220. case 3: {
  221. return !hasRoom;
  222. }
  223. case 7: {
  224. return !dischargeEnergy;
  225. }
  226. case 8: {
  227. return dischargeEnergy && dischargeRoom;
  228. }
  229. case 9: {
  230. return !dischargeRoom;
  231. }
  232. }
  233. } else if (tile instanceof TileEntityBaseGenerator) {
  234. TileEntityBaseGenerator gen = (TileEntityBaseGenerator)tile;
  235. boolean hasEnergy = gen.storage > 0;
  236. boolean hasRoom = gen.storage < gen.maxStorage;
  237. boolean chargeEnergy = false;
  238. boolean chargeRoom = false;
  239. if (gen.inventory[0] != null && gen.inventory[0].func_77973_b() instanceof IElectricItem) {
  240. IElectricItem ei = (IElectricItem)gen.inventory[0].func_77973_b();
  241. NBTTagCompound nbt = StackUtil.getOrCreateNbtData(gen.inventory[0]);
  242. if (nbt.func_74762_e("charge") > 0) {
  243. chargeEnergy = true;
  244. }
  245. if ((double)nbt.func_74762_e("charge") < ei.getMaxCharge(gen.inventory[0])) {
  246. chargeRoom = true;
  247. }
  248. } else if (gen.inventory[0] != null && gen.inventory[0].func_77973_b() instanceof ItemBatteryDischarged) {
  249. chargeEnergy = false;
  250. chargeRoom = true;
  251. } else if (this.action == 4 || this.action == 5 || this.action == 6) {
  252. return false;
  253. }
  254. switch (this.action) {
  255. case 0: {
  256. return !hasEnergy;
  257. }
  258. case 1: {
  259. return hasEnergy;
  260. }
  261. case 2: {
  262. return hasRoom;
  263. }
  264. case 3: {
  265. return !hasRoom;
  266. }
  267. case 4: {
  268. return !chargeEnergy;
  269. }
  270. case 5: {
  271. return chargeEnergy && chargeRoom;
  272. }
  273. case 6: {
  274. return !chargeRoom;
  275. }
  276. }
  277. } else if (tile instanceof TileEntityElectricBlock) {
  278. NBTTagCompound nbt;
  279. IElectricItem ei;
  280. TileEntityElectricBlock block = (TileEntityElectricBlock)tile;
  281. boolean hasEnergy = block.energy > block.output;
  282. boolean hasRoom = block.energy < block.maxStorage;
  283. boolean chargeEnergy = false;
  284. boolean chargeRoom = false;
  285. boolean dischargeEnergy = false;
  286. boolean dischargeRoom = false;
  287. if (block.inventory[0] != null && block.inventory[0].func_77973_b() instanceof IElectricItem) {
  288. ei = (IElectricItem)block.inventory[0].func_77973_b();
  289. nbt = StackUtil.getOrCreateNbtData(block.inventory[0]);
  290. if (nbt.func_74762_e("charge") > 0) {
  291. chargeEnergy = true;
  292. }
  293. if ((double)nbt.func_74762_e("charge") < ei.getMaxCharge(block.inventory[0])) {
  294. chargeRoom = true;
  295. }
  296. } else if (block.inventory[0] != null && block.inventory[0].func_77973_b() instanceof ItemBatteryDischarged) {
  297. chargeEnergy = false;
  298. chargeRoom = true;
  299. } else if (this.action == 4 || this.action == 5 || this.action == 6) {
  300. return false;
  301. }
  302. if (block.inventory[1] != null && block.inventory[1].func_77973_b() instanceof IElectricItem) {
  303. ei = (IElectricItem)block.inventory[1].func_77973_b();
  304. nbt = StackUtil.getOrCreateNbtData(block.inventory[1]);
  305. if (nbt.func_74762_e("charge") > 0) {
  306. dischargeEnergy = true;
  307. }
  308. if ((double)nbt.func_74762_e("charge") < ei.getMaxCharge(block.inventory[0])) {
  309. dischargeRoom = true;
  310. }
  311. } else if (block.inventory[1] != null && block.inventory[1].func_77973_b() instanceof ItemBatteryDischarged) {
  312. dischargeEnergy = false;
  313. dischargeRoom = true;
  314. } else if (this.action == 7 || this.action == 8 || this.action == 9) {
  315. return false;
  316. }
  317. switch (this.action) {
  318. case 0: {
  319. return !hasEnergy;
  320. }
  321. case 1: {
  322. return hasEnergy;
  323. }
  324. case 2: {
  325. return hasRoom;
  326. }
  327. case 3: {
  328. return !hasRoom;
  329. }
  330. case 4: {
  331. return !chargeEnergy;
  332. }
  333. case 5: {
  334. return chargeEnergy && chargeRoom;
  335. }
  336. case 6: {
  337. return !chargeRoom;
  338. }
  339. case 7: {
  340. return !dischargeEnergy;
  341. }
  342. case 8: {
  343. return dischargeEnergy && dischargeRoom;
  344. }
  345. case 9: {
  346. return !dischargeRoom;
  347. }
  348. }
  349. }
  350. return false;
  351. }
  352. }
Advertisement
Add Comment
Please, Sign In to add comment