aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/Ic2ExpReactorPlanner/components/Exchanger.java
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2022-01-29 19:15:48 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2022-01-29 19:15:48 +0000
commitc0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1 (patch)
tree2b549b5dfe3f80421ae2d45e041f929ea46d59aa /src/main/java/Ic2ExpReactorPlanner/components/Exchanger.java
parentb926dfb3bc67b74b53749a3e420a8a6ce0fba6a7 (diff)
parent0de849179b344dfddc68393aaa23b3b75b307670 (diff)
downloadGT5-Unofficial-c0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1.tar.gz
GT5-Unofficial-c0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1.tar.bz2
GT5-Unofficial-c0da5cc4ea19dfb2a05e64ce09d808b4efdc95b1.zip
Merge branch 'master' of https://github.com/GTNewHorizons/GTplusplus into St00f
# Conflicts: # .gitignore # dependencies.gradle # src/main/java/gtPlusPlus/core/config/ConfigHandler.java # src/main/java/gtPlusPlus/core/item/base/BaseItemComponent.java # src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java # src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java # src/main/resources/assets/miscutils/lang/en_US.lang
Diffstat (limited to 'src/main/java/Ic2ExpReactorPlanner/components/Exchanger.java')
-rw-r--r--src/main/java/Ic2ExpReactorPlanner/components/Exchanger.java130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/main/java/Ic2ExpReactorPlanner/components/Exchanger.java b/src/main/java/Ic2ExpReactorPlanner/components/Exchanger.java
new file mode 100644
index 0000000000..efb9a826e2
--- /dev/null
+++ b/src/main/java/Ic2ExpReactorPlanner/components/Exchanger.java
@@ -0,0 +1,130 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package Ic2ExpReactorPlanner.components;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import gregtech.api.objects.GT_ItemStack;
+
+/**
+ * Represents a heat exchanger of some sort in a reactor.
+ * @author Brian McCloud
+ */
+public class Exchanger extends ReactorItem {
+
+ private final int switchSide;
+ private final int switchReactor;
+
+ public Exchanger(final int id, final String baseName, GT_ItemStack aItem, final double maxDamage, final double maxHeat, final String sourceMod, final int switchSide, final int switchReactor) {
+ super(id, baseName, aItem, maxDamage, maxHeat, sourceMod);
+ this.switchSide = switchSide;
+ this.switchReactor = switchReactor;
+ }
+
+ public Exchanger(final Exchanger other) {
+ super(other);
+ this.switchSide = other.switchSide;
+ this.switchReactor = other.switchReactor;
+ }
+
+ @Override
+ public void transfer() {
+ List<ReactorItem> heatableNeighbors = new ArrayList<>(4);
+ ReactorItem component = parent.getComponentAt(row, col - 1);
+ if (component != null && component.isHeatAcceptor()) {
+ heatableNeighbors.add(component);
+ }
+ component = parent.getComponentAt(row, col + 1);
+ if (component != null && component.isHeatAcceptor()) {
+ heatableNeighbors.add(component);
+ }
+ component = parent.getComponentAt(row - 1, col);
+ if (component != null && component.isHeatAcceptor()) {
+ heatableNeighbors.add(component);
+ }
+ component = parent.getComponentAt(row + 1, col);
+ if (component != null && component.isHeatAcceptor()) {
+ heatableNeighbors.add(component);
+ }
+ // Code adapted from decompiled IC2 code, class ItemReactorHeatSwitch, with permission from Thunderdark.
+ double myHeat = 0;
+ if (switchSide > 0) {
+ for (ReactorItem heatableNeighbor : heatableNeighbors) {
+ double mymed = getCurrentHeat() * 100.0 / getMaxHeat();
+ double heatablemed = heatableNeighbor.getCurrentHeat() * 100.0 / heatableNeighbor.getMaxHeat();
+
+ double add = (int) (heatableNeighbor.getMaxHeat() / 100.0 * (heatablemed + mymed / 2.0));
+ if (add > switchSide) {
+ add = switchSide;
+ }
+ if (heatablemed + mymed / 2.0 < 1.0) {
+ add = switchSide / 2;
+ }
+ if (heatablemed + mymed / 2.0 < 0.75) {
+ add = switchSide / 4;
+ }
+ if (heatablemed + mymed / 2.0 < 0.5) {
+ add = switchSide / 8;
+ }
+ if (heatablemed + mymed / 2.0 < 0.25) {
+ add = 1;
+ }
+ if (Math.round(heatablemed * 10.0) / 10.0 > Math.round(mymed * 10.0) / 10.0) {
+ add -= 2 * add;
+ } else if (Math.round(heatablemed * 10.0) / 10.0 == Math.round(mymed * 10.0) / 10.0) {
+ add = 0;
+ }
+ myHeat -= add;
+ if (add > 0) {
+ currentComponentHeating += add;
+ }
+ add = heatableNeighbor.adjustCurrentHeat(add);
+ myHeat += add;
+ }
+ }
+ if (switchReactor > 0) {
+ double mymed = getCurrentHeat() * 100.0 / getMaxHeat();
+ double Reactormed = parent.getCurrentHeat() * 100.0 / parent.getMaxHeat();
+
+ int add = (int) Math.round(parent.getMaxHeat() / 100.0 * (Reactormed + mymed / 2.0));
+ if (add > switchReactor) {
+ add = switchReactor;
+ }
+ if (Reactormed + mymed / 2.0 < 1.0) {
+ add = switchSide / 2;
+ }
+ if (Reactormed + mymed / 2.0 < 0.75) {
+ add = switchSide / 4;
+ }
+ if (Reactormed + mymed / 2.0 < 0.5) {
+ add = switchSide / 8;
+ }
+ if (Reactormed + mymed / 2.0 < 0.25) {
+ add = 1;
+ }
+ if (Math.round(Reactormed * 10.0) / 10.0 > Math.round(mymed * 10.0) / 10.0) {
+ add -= 2 * add;
+ } else if (Math.round(Reactormed * 10.0) / 10.0 == Math.round(mymed * 10.0) / 10.0) {
+ add = 0;
+ }
+ myHeat -= add;
+ parent.adjustCurrentHeat(add);
+ if (add > 0) {
+ currentHullHeating = add;
+ } else {
+ currentHullCooling = -add;
+ }
+ }
+ adjustCurrentHeat(myHeat);
+ }
+
+ @Override
+ public double getHullCoolingCapacity() {
+ return switchReactor;
+ }
+
+}