diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-13 00:28:02 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-13 00:28:02 +0000 |
commit | 3e519e890249825dc8face0087cc631684d36e8c (patch) | |
tree | 33f667dc118da284af154ffbfe9f926ff55928a8 /src/main/java/gtPlusPlus/xmod/gregtech/common/computer | |
parent | b72a9b138fafceab899c1bd86fee64decb9fb98a (diff) | |
download | GT5-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/computer')
-rw-r--r-- | src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_ComputerCube_Setup.java | 74 | ||||
-rw-r--r-- | src/main/java/gtPlusPlus/xmod/gregtech/common/computer/GT_Computercube_Simulator.java | 149 |
2 files changed, 223 insertions, 0 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;*/ + } + + +} |