diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common')
2 files changed, 405 insertions, 277 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java index 57c5aab480..a75b148442 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java @@ -30,286 +30,414 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.api.util.GasSpargingRecipe; import gregtech.api.util.GasSpargingRecipeMap; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.minecraft.MaterialUtils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.RecipeUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -public class GregtechMetaTileEntity_SpargeTower extends GT_MetaTileEntity_EnhancedMultiBlockBase<GregtechMetaTileEntity_SpargeTower> { - - protected static final String STRUCTURE_PIECE_BASE = "base"; - protected static final String STRUCTURE_PIECE_LAYER = "layer"; - protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; - protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; - private static final IStructureDefinition<GregtechMetaTileEntity_SpargeTower> STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SpargeTower>builder() - .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ - {"b~b", "bbb", "bbb"}, - })) - .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][]{ - {"lll", "lcl", "lll"} - })) - .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][]{ - {"lll", "l-l", "lll"} - })) - .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][]{ - {"lll", "lll", "lll"} - })) - .addElement('b', ofChain( - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 1), - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, getCasingIndex(), 1), - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addInputToMachineList, getCasingIndex(), 1), - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 1), - onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4)) - )) - .addElement('l', ofChain( - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 2), - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addLayerOutputHatch, getCasingIndex(), 2), - ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 2), - onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4)) - )) - .addElement('c', ofChain( - onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, getCasingIndex(), 3)), - onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 3)), - onElementPass(t -> t.onTopLayerFound(true), ofBlock(ModBlocks.blockCasings5Misc, 4)), - isAir() - )) - .build(); - - protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); - protected int mHeight; - protected int mCasing; - protected boolean mTopLayerFound; - - public GregtechMetaTileEntity_SpargeTower(int aID, String aName, String aNameRegional) { - super(aID, aName, aNameRegional); - } - - public GregtechMetaTileEntity_SpargeTower(String aName) { - super(aName); - } - - public static int getCasingIndex() { - return 68; - } - - @Override - public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntity_SpargeTower(this.mName); - } - - @Override - protected GT_Multiblock_Tooltip_Builder createTooltip() { - final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType("Gas Sparge Tower") - .addInfo("Controller block for the Sparging Tower") - .addInfo("Fluids are only put out at the correct height") - .addInfo("The correct height equals the slot number in the NEI recipe") - .addSeparator() - .beginVariableStructureBlock(3, 3, 7, 7, 3, 3, true) - .addController("Front bottom") - .addOtherStructurePart("Sparge Tower Exterior Casing", "45 (minimum)") - .addEnergyHatch("Any casing", 1, 2) - .addMaintenanceHatch("Any casing", 1, 2, 3) - .addInputHatch("Any bottom layer casing", 1) - .addOutputHatch("6x Output Hatches (At least one per layer except bottom layer)", 2, 3) - .toolTipFinisher(CORE.GT_Tooltip_Builder); - return tt; - } - - @Override - public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - if (aSide == aFacing) { - if (aActive) - return new ITexture[]{ - BlockIcons.getCasingTextureForId(getCasingIndex()), - TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active).extFacing().build()}; - return new ITexture[]{ - BlockIcons.getCasingTextureForId(getCasingIndex()), - TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced).extFacing().build()}; - } - return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getCasingIndex())}; - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DistillationTower.png"); - } - - @Override - public GT_Recipe.GT_Recipe_Map getRecipeMap() { - if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { - generateRecipes(); - } +public class GregtechMetaTileEntity_SpargeTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SpargeTower> { + + protected static final String STRUCTURE_PIECE_BASE = "base"; + protected static final String STRUCTURE_PIECE_LAYER = "layer"; + protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; + protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; + private static final IStructureDefinition<GregtechMetaTileEntity_SpargeTower> STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SpargeTower>builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][]{ + {"b~b", "bbb", "bbb"}, + })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][]{ + {"lll", "lcl", "lll"} + })) + .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][]{ + {"lll", "l-l", "lll"} + })) + .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][]{ + {"lll", "lll", "lll"} + })) + .addElement('b', ofChain( + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 1), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, getCasingIndex(), 1), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addInputToMachineList, getCasingIndex(), 1), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 1), + onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4)) + )) + .addElement('l', ofChain( + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 2), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addLayerOutputHatch, getCasingIndex(), 2), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 2), + onElementPass(GregtechMetaTileEntity_SpargeTower::onCasingFound, ofBlock(ModBlocks.blockCasings5Misc, 4)) + )) + .addElement('c', ofChain( + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, getCasingIndex(), 3)), + onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 3)), + onElementPass(t -> t.onTopLayerFound(true), ofBlock(ModBlocks.blockCasings5Misc, 4)), + isAir() + )) + .build(); + + protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); + protected int mHeight; + protected int mCasing; + protected boolean mTopLayerFound; + + public GregtechMetaTileEntity_SpargeTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_SpargeTower(String aName) { + super(aName); + } + + public static int getCasingIndex() { + return 68; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_SpargeTower(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Gas Sparge Tower") + .addInfo("Controller block for the Sparging Tower") + .addInfo("Fluids are only put out at the correct height") + .addInfo("The correct height equals the slot number in the NEI recipe") + .addSeparator() + .beginStructureBlock(3, 8, 3, true) + .addController("Front bottom") + .addOtherStructurePart("Sparge Tower Exterior Casing", "45 (minimum)") + .addEnergyHatch("Any casing", 1, 2) + .addMaintenanceHatch("Any casing", 1, 2, 3) + .addInputHatch("2x Input Hatches (Any bottom layer casing)", 1) + .addOutputHatch("6x Output Hatches (At least one per layer except bottom layer)", 2, 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder); + return tt; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if (aSide == aFacing) { + if (aActive) + return new ITexture[]{ + BlockIcons.getCasingTextureForId(getCasingIndex()), + TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active).extFacing().build()}; + return new ITexture[]{ + BlockIcons.getCasingTextureForId(getCasingIndex()), + TextureFactory.builder().addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced).extFacing().build()}; + } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(getCasingIndex())}; + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DistillationTower.png"); + } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeMap() { + GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.clear(); + if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { + generateRecipes(); + } return GTPP_Recipe_Map.sSpargeTowerRecipes; - } - - private static boolean generateRecipes() { - for (GasSpargingRecipe aRecipe : GasSpargingRecipeMap.mRecipes) { - GTPP_Recipe newRecipe = new GTPP_Recipe( - false, - new ItemStack[] {}, - new ItemStack[] {}, - null, - aRecipe.mMaxOutputQuantity, - aRecipe.mFluidInputs, - aRecipe.mFluidOutputs, - aRecipe.mDuration, - aRecipe.mEUt, - 0); - GTPP_Recipe_Map.sSpargeTowerRecipes.add(newRecipe); - } - - - - return false; - } - - @Override - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - @Override - public boolean checkRecipe(ItemStack aStack) { - ArrayList<FluidStack> tFluidList = getStoredFluids(); - for (int i = 0; i < tFluidList.size() - 1; i++) { - for (int j = i + 1; j < tFluidList.size(); j++) { - if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { - if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { - tFluidList.remove(j--); - } else { - tFluidList.remove(i--); - break; - } - } - } - } - - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(0, GT_Utility.getTier(tVoltage)); - FluidStack[] tFluids = tFluidList.toArray(new FluidStack[0]); - if (tFluids.length > 0) { - for (FluidStack tFluid : tFluids) { - GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sDistillationRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], new FluidStack[]{tFluid}); - if (tRecipe != null) { - if (tRecipe.isRecipeInputEqual(true, tFluids)) { - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return false; - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; - this.mOutputFluids = tRecipe.mFluidOutputs.clone(); - updateSlots(); - return true; - } - } - } - } - - return false; - } - - protected void onCasingFound() { - mCasing++; - } - - protected void onTopLayerFound(boolean aIsCasing) { - mTopLayerFound = true; - if (aIsCasing) - onCasingFound(); - } - - protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { - if (aTileEntity == null || aTileEntity.isDead() || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) - return false; - while (mOutputHatchesByLayer.size() < mHeight) - mOutputHatchesByLayer.add(new ArrayList<>()); - GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); - tHatch.updateTexture(aBaseCasingIndex); - return mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); - } - - @Override - protected IAlignmentLimits getInitialAlignmentLimits() { - // don't rotate a freaking tower, it won't work - return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); - } - - @Override - public IStructureDefinition<GregtechMetaTileEntity_SpargeTower> getStructureDefinition() { - return STRUCTURE_DEFINITION; - } - - @Override - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - // reset - mOutputHatchesByLayer.forEach(List::clear); - mHeight = 1; - mTopLayerFound = false; - mCasing = 0; - - // check base - if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) - return false; - - // check each layer - while (mHeight < 7 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) { - if (mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) - // layer without output hatch - return false; - // not top - mHeight++; - } - - // validate final invariants... - return mCasing >= 7 * mHeight - 5 && mHeight >= 2 && mTopLayerFound && mMaintenanceHatches.size() == 1; - } - - @Override - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } - - @Override - public int getPollutionPerTick(ItemStack aStack) { - return 0; - } - - @Override - public int getDamageToComponent(ItemStack aStack) { - return 0; - } - - @Override - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; - } - - @Override - protected void addFluidOutputs(FluidStack[] mOutputFluids2) { - for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { - FluidStack tStack = mOutputFluids2[i].copy(); - if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) - dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); - } - } - - @Override - public void construct(ItemStack stackSize, boolean hintsOnly) { - buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); - int tTotalHeight = 7; // min 2 output layer, so at least 1 + 2 height - for (int i = 1; i < tTotalHeight - 1; i++) { - buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); - } - buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); - } + } + + private static boolean generateRecipes() { + for (GasSpargingRecipe aRecipe : GasSpargingRecipeMap.mRecipes) { + GTPP_Recipe newRecipe = new GTPP_Recipe( + false, + new ItemStack[] {}, + new ItemStack[] {}, + null, + null, + aRecipe.mFluidInputs.clone(), + new FluidStack[] {}, + aRecipe.mDuration, + aRecipe.mEUt, + 0); + GTPP_Recipe_Map.sSpargeTowerRecipes.add(newRecipe); + } + if (GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.isEmpty()) { + return false; + } + return true; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean checkRecipe(ItemStack aStack) { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(0, GT_Utility.getTier(tVoltage)); + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[0]); + if (tFluids.length > 0) { + Logger.INFO("Found "+tFluids.length+" input fluids. Searching "+GTPP_Recipe_Map.sSpargeTowerRecipes.mRecipeList.size()+" recipes."); + GT_Recipe tRecipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids); + if (tRecipe != null) { + Logger.INFO("Found recipe!"); + try { + String[] aRecipeInfo = RecipeUtils.getRecipeInfo(tRecipe); + for (String info : aRecipeInfo) { + Logger.INFO(" "+info); + } + } + catch (Throwable e) { + e.printStackTrace(); + } + if (tRecipe.isRecipeInputEqual(true, tFluids)) { + Logger.INFO("Found recipe that matches!"); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Reset outputs and progress stats + this.mEUt = 0; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; + this.mLastRecipe = tRecipe; + + // Deplete Inputs + if (tRecipe.mFluidInputs.length > 0) { + for (FluidStack aInputToConsume : tRecipe.mFluidInputs) { + Logger.INFO("Depleting "+aInputToConsume.getLocalizedName()+" - "+aInputToConsume.amount+"L"); + this.depleteInput(aInputToConsume); + } + } + else { + this.mEUt = 0; + this.mEfficiency = 0; + return false; + } + + calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + int aDevProgress = this.mMaxProgresstime / 10; + this.mMaxProgresstime = Math.max(1, aDevProgress); + this.mOutputItems = new ItemStack[]{}; + ArrayList<FluidStack> aFluidOutputs = getByproductsOfSparge(tRecipe.mFluidInputs[0], tRecipe.mFluidInputs[1]); + this.mOutputFluids = (FluidStack[]) aFluidOutputs.toArray(new FluidStack[0]).clone(); + updateSlots(); + Logger.INFO("Done!"); + return true; + } + } + else { + Logger.INFO("Did not find recipe!"); + } + } + this.mEUt = 0; + this.mEfficiency = 0; + Logger.INFO("Did not find recipe! (2)"); + return false; + } + + private static ArrayList<FluidStack> getByproductsOfSparge(final FluidStack aSpargeGas, final FluidStack aSpentFuel){ + GasSpargingRecipe aSpargeRecipe = GasSpargingRecipeMap.findRecipe(aSpargeGas, aSpentFuel); + ArrayList<FluidStack> aOutputGases = new ArrayList<FluidStack>(); + if (aSpargeRecipe == null) { + Logger.INFO("Did not find sparge recipe!"); + return aOutputGases; + } + else { + Logger.INFO("Found sparge recipe!"); + try { + String[] aRecipeInfo = aSpargeRecipe.getRecipeInfo(); + for (String info : aRecipeInfo) { + Logger.INFO(" "+info); + } + } + catch (Throwable e) { + e.printStackTrace(); + } + } + int aSpargeGasAmount = aSpargeRecipe.mInputGas.amount; + + aOutputGases.add(aSpargeRecipe.mOutputSpargedFuel.copy()); + ArrayList<FluidStack> aTempMap = new ArrayList<FluidStack>(); + for (int i=2;i<aSpargeRecipe.mFluidOutputs.length;i++) { + int aGasAmount = MathUtils.randInt(0, (aSpargeRecipe.mMaxOutputQuantity[i-2]/100)); + FluidStack aOutput = aSpargeRecipe.mFluidOutputs[i].copy(); + aSpargeGasAmount -= aGasAmount; + FluidStack aSpargeOutput = null; + if (aGasAmount > 0) { + aSpargeOutput = new FluidStack(aOutput.getFluid(), aGasAmount); + } + aTempMap.add(aSpargeOutput); + } + Logger.INFO("Sparge gas left: "+aSpargeGasAmount); + if (aSpargeGasAmount > 0) { + aOutputGases.add(new FluidStack(aSpargeRecipe.mInputGas.getFluid(), aSpargeGasAmount)); + } + Logger.INFO("Sparge Outputs: "+ItemUtils.getArrayStackNames(aTempMap)); + aOutputGases.addAll(aTempMap); + Logger.INFO("Sparge output size: "+aOutputGases.size()); + Logger.INFO("Output of sparging: "+ItemUtils.getArrayStackNames(aOutputGases)); + return aOutputGases; + } + + protected void onCasingFound() { + mCasing++; + } + + protected void onTopLayerFound(boolean aIsCasing) { + mTopLayerFound = true; + if (aIsCasing) { + onCasingFound(); + } + } + + protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null || aTileEntity.isDead() || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output)) + return false; + while (mOutputHatchesByLayer.size() < mHeight) { + mOutputHatchesByLayer.add(new ArrayList<>()); + } + GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) aTileEntity.getMetaTileEntity(); + tHatch.updateTexture(aBaseCasingIndex); + return mOutputHatchesByLayer.get(mHeight - 1).add(tHatch); + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a freaking tower, it won't work + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SpargeTower> getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // reset + mOutputHatchesByLayer.forEach(List::clear); + mHeight = 1; + mTopLayerFound = false; + mCasing = 0; + + // check base + if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) { + return false; + } + + // check each layer + while (mHeight < 8 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) { + if (mOutputHatchesByLayer.get(mHeight - 1).isEmpty()) { + // layer without output hatch + return false; + } + // not top + mHeight++; + } + + // validate final invariants... + Logger.INFO("Height: "+mHeight); + Logger.INFO("Casings: "+mCasing); + Logger.INFO("Required: "+(7 * mHeight - 5)); + Logger.INFO("Found Top: "+mTopLayerFound); + return mCasing >= 7 * mHeight - 5 && mTopLayerFound && mMaintenanceHatches.size() == 1; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + protected void addFluidOutputs(FluidStack[] mOutputFluids2) { + for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { + FluidStack tStack = mOutputFluids2[i] != null ? mOutputFluids2[i].copy() : null; + if (tStack == null) { + continue; + } + if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) { + dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); + } + } + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); + int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); + } + buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); + } + + @Override + public boolean hasSlotInGUI() { + return false; + } + + @Override + public String getCustomGUIResourceName() { + return null; + } + + @Override + public String getMachineType() { + return "Gas Sparger"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getEuDiscountForParallelism() { + return 0; + } + + @Override + public boolean onPlungerRightClick(EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + int aLayerIndex = 0; + PlayerUtils.messagePlayer(aPlayer, "Trying to clear "+mOutputHatchesByLayer.size()+" layers of output hatches."); + for (List<GT_MetaTileEntity_Hatch_Output> layer : this.mOutputHatchesByLayer) { + int aHatchIndex = 0; + for (GT_MetaTileEntity_Hatch_Output hatch : layer) { + if (hatch.mFluid != null) { + PlayerUtils.messagePlayer(aPlayer, "Clearing "+hatch.mFluid.amount+"L of "+hatch.mFluid.getLocalizedName()+" from hatch "+aHatchIndex+" on layer "+aLayerIndex+"."); + hatch.mFluid = null; + } + aHatchIndex++; + } + aLayerIndex++; + } + return aLayerIndex > 0; + } } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java index 7833129cf9..7d5c47e185 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java @@ -391,7 +391,7 @@ public class GregtechMTE_NuclearReactor extends GregtechMeta_MultiBlockBase { // Warm up for 4~ minutes Logger.WARNING("Checking LFTR recipes."); if (mEfficiency < this.getMaxEfficiency(null)) { - this.mProgresstime = 1; + this.mProgresstime = 0; this.mMaxProgresstime = 1; this.mEfficiencyIncrease = 2; Logger.WARNING("Warming Up! "+this.mEfficiency+"/"+this.getMaxEfficiency(null)); @@ -636,8 +636,8 @@ public class GregtechMTE_NuclearReactor extends GregtechMeta_MultiBlockBase { if (this.mSpargeTicks >= this.mSpargeTime) { this.mSpargeTime = 0; this.mSpargeTicks = 0; - Logger.WARNING("Sparging!"); - trySparge(); + //Logger.WARNING("Sparging!"); + //trySparge(); } } super.onPostTick(aBaseMetaTileEntity, aTick); |