aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/common
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2022-01-13 00:28:02 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2022-01-13 00:28:02 +0000
commit3e519e890249825dc8face0087cc631684d36e8c (patch)
tree33f667dc118da284af154ffbfe9f926ff55928a8 /src/main/java/gtPlusPlus/xmod/gregtech/common
parentb72a9b138fafceab899c1bd86fee64decb9fb98a (diff)
downloadGT5-Unofficial-3e519e890249825dc8face0087cc631684d36e8c.tar.gz
GT5-Unofficial-3e519e890249825dc8face0087cc631684d36e8c.tar.bz2
GT5-Unofficial-3e519e890249825dc8face0087cc631684d36e8c.zip
Basically finished work on Reactor Simulator.
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common')
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_ComputerCube_Setup.java74
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_Computercube_Simulator.java149
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java74
3 files changed, 261 insertions, 36 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_ComputerCube_Setup.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_ComputerCube_Setup.java
new file mode 100644
index 0000000000..bd2df1b8ff
--- /dev/null
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_ComputerCube_Setup.java
@@ -0,0 +1,74 @@
+package gtPlusPlus.xmod.gregtech.common.computer;
+
+import static gtPlusPlus.xmod.gregtech.common.tileentities.misc.GT_TileEntity_ComputerCube.sReactorList;
+
+import java.util.ArrayList;
+
+import Ic2ExpReactorPlanner.ComponentFactory;
+import gregtech.api.enums.ItemList;
+import gregtech.api.objects.GT_ItemStack;
+import gregtech.api.util.GT_ModHandler;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.lib.LoadedMods;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
+import gtPlusPlus.xmod.bartworks.BW_Utils;
+import gtPlusPlus.xmod.goodgenerator.GG_Utils;
+import net.minecraft.item.ItemStack;
+
+public class GT_ComputerCube_Setup {
+
+ public static void init() {
+ Logger.INFO("[Reactor Simulator] Added " + ComponentFactory.getComponentCount() + " components to ComponentFactory.");
+ if (sReactorList == null) {
+ sReactorList = new ArrayList<GT_ItemStack>();
+
+ String[] aIc2Items = new String[]{
+ "reactorUraniumSimple", "reactorUraniumDual", "reactorUraniumQuad", /*"reactorIsotopeCell",*/ "reactorReflector", "reactorReflectorThick", "reactorCoolantSimple",
+ "reactorCoolantTriple", "reactorCoolantSix", "reactorCondensator", "reactorCondensatorLap", "reactorPlating", "reactorPlatingHeat", "reactorPlatingExplosive", "reactorVent",
+ "reactorVentCore", "reactorVentGold", "reactorVentSpread", "reactorVentDiamond", "reactorHeatSwitch", "reactorHeatSwitchCore", "reactorHeatSwitchSpread",
+ "reactorHeatSwitchDiamond", /*"reactorHeatpack",*/
+ };
+
+ for (String aItem : aIc2Items) {
+ ItemStack aStack = GT_ModHandler.getIC2Item(aItem, 1);
+ if (!ItemUtils.checkForInvalidItems(aStack)) {
+ Logger.INFO("Unable to find IC2 Item: " + aItem);
+ CORE.crash("Unable to find IC2 Item: " + aItem);
+ }
+ else {
+ sReactorList.add(new GT_ItemStack(aStack.copy()));
+ }
+ }
+
+ ItemList[] aGtItems = new ItemList[]{
+ ItemList.Neutron_Reflector, ItemList.Moxcell_1, ItemList.Moxcell_2, ItemList.Moxcell_4, /*ItemList.Uraniumcell_1, ItemList.Uraniumcell_2, ItemList.Uraniumcell_4,*/
+ ItemList.NaquadahCell_1, ItemList.NaquadahCell_2, ItemList.NaquadahCell_4, ItemList.ThoriumCell_1, ItemList.ThoriumCell_2, ItemList.ThoriumCell_4, ItemList.MNqCell_1,
+ ItemList.MNqCell_2, ItemList.MNqCell_4, ItemList.Reactor_Coolant_He_1, ItemList.Reactor_Coolant_He_3, ItemList.Reactor_Coolant_He_6, ItemList.Reactor_Coolant_NaK_1,
+ ItemList.Reactor_Coolant_NaK_3, ItemList.Reactor_Coolant_NaK_6, ItemList.Reactor_Coolant_Sp_1, ItemList.Reactor_Coolant_Sp_2, ItemList.Reactor_Coolant_Sp_3,
+ ItemList.Reactor_Coolant_Sp_6
+ };
+
+ for (ItemList aItem : aGtItems) {
+ sReactorList.add(new GT_ItemStack(aItem.get(1)));
+ }
+
+ if (LoadedMods.BartWorks) {
+ ArrayList<ItemStack> aBartReactorItems = BW_Utils.getAll(1);
+ for (ItemStack aReactorItem : aBartReactorItems) {
+ sReactorList.add(new GT_ItemStack(aReactorItem));
+ }
+ }
+
+ if (LoadedMods.GoodGenerator) {
+ ArrayList<ItemStack> aGlodReactorItems = GG_Utils.getAll(1);
+ for (ItemStack aReactorItem : aGlodReactorItems) {
+ sReactorList.add(new GT_ItemStack(aReactorItem));
+ }
+ }
+ Logger.INFO("[Reactor Simulator] Added " + sReactorList.size() + " components to GT_TileEntity_ComputerCube.");
+
+ }
+ }
+
+}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_Computercube_Simulator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_Computercube_Simulator.java
new file mode 100644
index 0000000000..e0bedb5d18
--- /dev/null
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_Computercube_Simulator.java
@@ -0,0 +1,149 @@
+package gtPlusPlus.xmod.gregtech.common.computer;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import Ic2ExpReactorPlanner.AutomationSimulator;
+import Ic2ExpReactorPlanner.Reactor;
+import Ic2ExpReactorPlanner.SimulationData;
+import Ic2ExpReactorPlanner.components.ReactorItem;
+import gregtech.api.objects.GT_ItemStack;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.data.Pair;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
+import gtPlusPlus.xmod.gregtech.common.tileentities.misc.GT_TileEntity_ComputerCube;
+
+public class GT_Computercube_Simulator {
+
+ private static final HashMap<Integer, Pair<Integer, Integer>> sSlotPositions = new HashMap<Integer, Pair<Integer, Integer>>();
+
+ static {
+ int aSlot = 4;
+ for (int column = 0; column < 6; column++) {
+ for (int row = 0; row < 9; row++) {
+ sSlotPositions.put(aSlot++, new Pair<Integer, Integer>(row, column));
+ }
+ }
+ }
+
+ private final Reactor reactor = new Reactor();
+
+ public AutomationSimulator simulator = null;
+ /**
+ * The reactor that was last simulated.
+ */
+ public Reactor simulatedReactor = null;
+
+ private String currentReactorCode = null;
+
+ private String currentReactorOldCode = null;
+
+ private ArrayList<String> output = new ArrayList<String>();
+
+ private final GT_TileEntity_ComputerCube mTile;
+
+ public GT_Computercube_Simulator(GT_TileEntity_ComputerCube aTile) {
+ mTile = aTile;
+ }
+
+ public void slotClick(int aSlot, GT_ItemStack aStack) {
+
+ /*if (selection != null) {
+ componentToPlace = ComponentFactory.createComponent(selection.getActionCommand());
+ if (componentToPlace != null) {
+ componentToPlace.setInitialHeat(((Number)componentHeatSpinner.getValue()).intValue());
+ componentToPlace.setAutomationThreshold(((Number)placingThresholdSpinner.getValue()).intValue());
+ componentToPlace.setReactorPause(((Number)placingReactorPauseSpinner.getValue()).intValue());
+ }
+ }*/
+ if (aSlot >= 4 && aSlot < 58) {
+ Pair<Integer, Integer> aSpot = sSlotPositions.get(aSlot);
+ ReactorItem aItem;
+ if (aStack == null) {
+ aItem = null;
+ }
+ else {
+
+ Logger.INFO("Using lookup key: "+ItemUtils.getModId(aStack.toStack())+"."+aStack.mItem.getUnlocalizedName()+"."+aStack.mMetaData);
+ aItem = ReactorItem.sComponentMap.get(ItemUtils.getModId(aStack.toStack())+"."+aStack.mItem.getUnlocalizedName()+"."+aStack.mMetaData);
+
+ }
+ int aRow = aSpot.getKey();
+ int aColumn = aSpot.getValue();
+ Logger.INFO("Putting "+(aItem == null ? "null" : aItem.name)+" at x:"+aRow+", y:"+aColumn);
+ reactor.setComponentAt(aColumn, aRow, aItem);
+ currentReactorCode = reactor.getCode();
+ currentReactorOldCode = reactor.getOldCode();
+ Logger.INFO("Code: "+currentReactorCode);
+ }
+ //maxHeatLabel.setText(formatI18n("UI.MaxHeatSpecific", reactor.getMaxHeat()));
+ //heatSpinnerModel.setMaximum(reactor.getMaxHeat() - 1);
+ //heatSpinnerModel.setValue(Math.min(((Number)heatSpinnerModel.getValue()).intValue(), reactor.getMaxHeat() - 1));
+ //temperatureEffectsLabel.setText(formatI18n("UI.TemperatureEffectsSpecific", (int) (reactor.getMaxHeat() * 0.4), (int) (reactor.getMaxHeat() * 0.5), (int) (reactor.getMaxHeat() * 0.7), (int) (reactor.getMaxHeat() * 0.85), (int) (reactor.getMaxHeat() * 1.0)));
+ }
+
+ public void simulate() {
+ /*if (Utils.isClient()) {
+ return;
+ }*/
+ if (simulator != null && simulator.isRunning()) {
+ Logger.INFO("Simulator Running, Stopping.");
+ simulator.cancel();
+ }
+ Logger.INFO("Starting Simulator.");
+ mTile.mHeat = 0;
+ mTile.mEU = 0;
+ currentReactorCode = reactor.getCode();
+ currentReactorOldCode = reactor.getOldCode();
+ output.clear();
+ simulatedReactor = new Reactor();
+ simulatedReactor.setCode(reactor.getCode());
+ Logger.INFO("Making new AutomationSimulator.");
+ simulator = new AutomationSimulator(simulatedReactor, output, mTile);
+ Logger.INFO("Starting AutomationSimulator.process().");
+ simulator.process();
+ Logger.INFO("Done.");
+
+ SimulationData aData = simulator.getData();
+ if (aData != null && aData.totalReactorTicks > 0) {
+ mTile.mEU = aData.avgEUoutput * aData.totalReactorTicks;
+ mTile.mEUOut = aData.avgEUoutput;
+ mTile.mHeat = aData.avgHUoutput;
+ mTile.mMaxHeat = aData.maxHUoutput;
+ mTile.mExplosionStrength = aData.explosionPower;
+ mTile.mHEM = (float) aData.hullHeating;
+ mTile.mProgress = aData.totalReactorTicks;
+ }
+
+ for (String s : output) {
+ Logger.INFO(" "+s);
+ }
+ }
+
+ public ArrayList<String> getOutputData() {
+ return output;
+ }
+
+ private void clearGrid() {
+ reactor.clearGrid();
+ /*for (int i = 0; i < reactorButtons.length; i++) {
+ for (int j = 0; j < reactorButtons[i].length; j++) {
+ reactorButtons[i][j].setIcon(null);
+ reactorButtons[i][j].setToolTipText(null);
+ reactorButtonPanels[i][j].setBackground(Color.LIGHT_GRAY);
+ }
+ }*/
+ output.clear();
+ /*materialsArea.setText(reactor.getMaterials().toString());
+ componentListArea.setText(reactor.getComponentList().toString());
+ maxHeatLabel.setText(formatI18n("UI.MaxHeatSpecific", reactor.getMaxHeat()));
+ heatSpinnerModel.setMaximum(reactor.getMaxHeat() - 1);
+ heatSpinnerModel.setValue(Math.min(((Number) heatSpinnerModel.getValue()).intValue(), reactor.getMaxHeat() - 1));
+ temperatureEffectsLabel.setText(formatI18n("UI.TemperatureEffectsSpecific", (int)(reactor.getMaxHeat() * 0.4), (int)(reactor.getMaxHeat() * 0.5), (int)(reactor.getMaxHeat() * 0.7), (int)(reactor.getMaxHeat() * 0.85), (int)(reactor.getMaxHeat() * 1.0)));
+ lockCode = true;
+ codeField.setText(null);
+ lockCode = false;*/
+ }
+
+
+}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java
index dd8c79a855..11d5068374 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/GT_TileEntity_ComputerCube.java
@@ -3,6 +3,7 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.misc;
import java.util.ArrayList;
import java.util.Collections;
+import Ic2ExpReactorPlanner.SimulationData;
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.ItemList;
import gregtech.api.interfaces.ITexture;
@@ -17,12 +18,16 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.lib.LoadedMods;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
+import gtPlusPlus.xmod.bartworks.BW_Utils;
+import gtPlusPlus.xmod.goodgenerator.GG_Utils;
import gtPlusPlus.xmod.gregtech.api.gui.computer.GT_Container_ComputerCube;
import gtPlusPlus.xmod.gregtech.api.gui.computer.GT_GUIContainer_ComputerCube;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import gtPlusPlus.xmod.gregtech.common.computer.GT_ComputercubeDescription;
+import gtPlusPlus.xmod.gregtech.common.computer.GT_Computercube_Simulator;
import ic2.api.reactor.IReactor;
import ic2.api.reactor.IReactorComponent;
import ic2.core.Ic2Items;
@@ -72,6 +77,8 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank impl
public float mHEM = 1.0F, mExplosionStrength = 0.0F;
private boolean mNeedsUpdate;
+
+ private GT_Computercube_Simulator mSimulator;
public GT_TileEntity_ComputerCube(final int aID, final String aDescription) {
super(aID, "computer.cube", "Computer Cube", 5, 114, aDescription);
@@ -128,6 +135,14 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank impl
return true;
}
+ public final GT_Computercube_Simulator getSimulator() {
+ return this.mSimulator;
+ }
+
+ public final void setSimulator(GT_Computercube_Simulator mSimulator) {
+ this.mSimulator = mSimulator;
+ }
+
@Override
public boolean isSimpleMachine() {
return true;
@@ -160,7 +175,7 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank impl
@Override
public boolean ownerControl() {
- return true;
+ return false;
}
@Override
@@ -576,10 +591,12 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank impl
this.mStarted = true;
this.mHeat = 0;
this.mEU = 0;
+ mSimulator.simulate();
}
public void stopNuclearReactor() {
this.mStarted = false;
+ mSimulator.simulate();
}
public void storeAdditionalData(NBTTagCompound aNBT) {
@@ -612,44 +629,14 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank impl
@Override
public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
super.onFirstTick(aBaseMetaTileEntity);
- if (sReactorList == null) {
- sReactorList = new ArrayList<GT_ItemStack>();
-
- String[] aIc2Items = new String[]{
- "reactorUraniumSimple", "reactorUraniumDual", "reactorUraniumQuad", /*"reactorIsotopeCell",*/ "reactorReflector", "reactorReflectorThick", "reactorCoolantSimple",
- "reactorCoolantTriple", "reactorCoolantSix", "reactorCondensator", "reactorCondensatorLap", "reactorPlating", "reactorPlatingHeat", "reactorPlatingExplosive", "reactorVent",
- "reactorVentCore", "reactorVentGold", "reactorVentSpread", "reactorVentDiamond", "reactorHeatSwitch", "reactorHeatSwitchCore", "reactorHeatSwitchSpread",
- "reactorHeatSwitchDiamond", /*"reactorHeatpack",*/
- };
-
- for (String aItem : aIc2Items) {
- ItemStack aStack = GT_ModHandler.getIC2Item(aItem, 1);
- if (!ItemUtils.checkForInvalidItems(aStack)) {
- Logger.INFO("Unable to find IC2 Item: " + aItem);
- CORE.crash("Unable to find IC2 Item: " + aItem);
- }
- else {
- sReactorList.add(new GT_ItemStack(aStack.copy()));
- }
- }
-
- ItemList[] aGtItems = new ItemList[]{
- ItemList.Neutron_Reflector, ItemList.Moxcell_1, ItemList.Moxcell_2, ItemList.Moxcell_4, ItemList.Uraniumcell_1, ItemList.Uraniumcell_2, ItemList.Uraniumcell_4,
- ItemList.NaquadahCell_1, ItemList.NaquadahCell_2, ItemList.NaquadahCell_4, ItemList.ThoriumCell_1, ItemList.ThoriumCell_2, ItemList.ThoriumCell_4, ItemList.Reactor_Coolant_He_1,
- ItemList.Reactor_Coolant_He_3, ItemList.Reactor_Coolant_He_6, ItemList.Reactor_Coolant_NaK_1, ItemList.Reactor_Coolant_NaK_3, ItemList.Reactor_Coolant_NaK_6,
- };
-
- for (ItemList aItem : aGtItems) {
- sReactorList.add(new GT_ItemStack(aItem.get(1)));
- }
-
- }
-
}
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
+ if (mSimulator == null) {
+ mSimulator = new GT_Computercube_Simulator(this);
+ }
if(this.getBaseMetaTileEntity().isClientSide()) {
this.getWorld().markBlockForUpdate(this.getXCoord(), this.getYCoord(), this.getZCoord());
this.mNeedsUpdate = false;
@@ -694,7 +681,22 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank impl
}
}
}
- if (this.mMode == 1 && mReactorplanner && this.mStarted && this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(32, false))
+
+ if (this.mMode == 1 && mReactorplanner && this.mSimulator != null && this.mSimulator.simulator != null && this.mSimulator.simulatedReactor != null) {
+ SimulationData aData = this.mSimulator.simulator.getData();
+ if (aData != null && aData.totalReactorTicks > 0 && this.mProgress != aData.totalReactorTicks) {
+ Logger.INFO("Updating Variables");
+ this.mEU = aData.avgEUoutput;
+ this.mEUOut = (aData.totalEUoutput / aData.totalReactorTicks);
+ this.mHeat = aData.avgHUoutput;
+ this.mMaxHeat = aData.maxHUoutput;
+ this.mExplosionStrength = aData.explosionPower;
+ this.mHEM = (float) aData.hullHeating;
+ this.mProgress = aData.totalReactorTicks;
+ }
+ }
+
+ /*if (this.mMode == 1 && mReactorplanner && this.mStarted && this.getBaseMetaTileEntity().decreaseStoredEnergyUnits(32, false))
for (int i = 0; i < 25 && this.mStarted; i++) {
this.mEUOut = 0;
this.mMaxHeat = 10000;
@@ -737,7 +739,7 @@ public class GT_TileEntity_ComputerCube extends GT_MetaTileEntity_BasicTank impl
this.mEULast3 = this.mEULast4;
this.mEULast4 = this.mEUOut;
this.mEUOut = (this.mEUOut + this.mEULast1 + this.mEULast2 + this.mEULast3 + tEU) / 5;
- }
+ }*/
if (aTick % 20L == 0L) {
//this.getWorld().addBlockEvent(this.xCoord, this.yCoord, this.zCoord, (GregTech_API.sBlockList[1]).field_71990_ca, 10, this.mMode);
//this.getWorld().addBlockEvent(this.xCoord, this.yCoord, this.zCoord, (GregTech_API.sBlockList[1]).field_71990_ca, 11, this.mMaxHeat);