diff options
Diffstat (limited to 'src/main/java/goodgenerator/blocks/tileEntity')
3 files changed, 49 insertions, 127 deletions
diff --git a/src/main/java/goodgenerator/blocks/tileEntity/ComponentAssemblyLine.java b/src/main/java/goodgenerator/blocks/tileEntity/ComponentAssemblyLine.java index 1a9d1b245f..65f0e23810 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/ComponentAssemblyLine.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/ComponentAssemblyLine.java @@ -2,13 +2,13 @@ package goodgenerator.blocks.tileEntity; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static gregtech.api.enums.GT_HatchElement.*; -import static gregtech.api.enums.GT_Values.VN; import static gregtech.api.enums.Textures.BlockIcons.*; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import goodgenerator.blocks.tileEntity.base.GT_MetaTileEntity_LongPowerUsageBase; import goodgenerator.loader.Loaders; import goodgenerator.util.MyRecipeAdder; import gregtech.api.GregTech_API; @@ -18,12 +18,10 @@ import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.render.TextureFactory; -import gregtech.api.util.*; -import java.util.ArrayList; -import java.util.List; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_StructureUtility; import java.util.stream.Collectors; import java.util.stream.IntStream; import net.minecraft.item.ItemStack; @@ -33,12 +31,11 @@ import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.tuple.Pair; -public class ComponentAssemblyLine extends GT_MetaTileEntity_EnhancedMultiBlockBase<ComponentAssemblyLine> +public class ComponentAssemblyLine extends GT_MetaTileEntity_LongPowerUsageBase<ComponentAssemblyLine> implements ISurvivalConstructable { private int casingTier; - private final double log4 = Math.log(4); - private long EU_per_tick = 0; + private GT_Recipe lastRecipe; protected static final String STRUCTURE_PIECE_MAIN = "main"; private static final IStructureDefinition<ComponentAssemblyLine> STRUCTURE_DEFINITION = StructureDefinition.<ComponentAssemblyLine>builder() @@ -557,42 +554,12 @@ public class ComponentAssemblyLine extends GT_MetaTileEntity_EnhancedMultiBlockB * */ @Override public String[] getInfoData() { - long storedEnergy = 0; - long maxEnergy = 0; - - for (GT_MetaTileEntity_Hatch tHatch : mExoticEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); - } - } - return new String[] { - "------------ Critical Information ------------", - StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + EnumChatFormatting.GREEN - + GT_Utility.formatNumbers(mProgresstime) + EnumChatFormatting.RESET + "t / " - + EnumChatFormatting.YELLOW - + GT_Utility.formatNumbers(mMaxProgresstime) + EnumChatFormatting.RESET + "t", - StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + EnumChatFormatting.GREEN - + GT_Utility.formatNumbers(storedEnergy) + EnumChatFormatting.RESET + " EU / " - + EnumChatFormatting.YELLOW - + GT_Utility.formatNumbers(maxEnergy) + EnumChatFormatting.RESET + " EU", - StatCollector.translateToLocal("GT5U.multiblock.usage") + ": " + EnumChatFormatting.RED - + GT_Utility.formatNumbers(-EU_per_tick) + EnumChatFormatting.RESET + " EU/t", - StatCollector.translateToLocal("GT5U.multiblock.mei") + ": " + EnumChatFormatting.YELLOW - + GT_Utility.formatNumbers( - GT_ExoticEnergyInputHelper.getMaxInputVoltageMulti(getExoticAndNormalEnergyHatchList())) - + EnumChatFormatting.RESET + " EU/t(*" + EnumChatFormatting.YELLOW - + GT_Utility.formatNumbers( - GT_ExoticEnergyInputHelper.getMaxInputAmpsMulti(getExoticAndNormalEnergyHatchList())) - + EnumChatFormatting.RESET + "A) " + StatCollector.translateToLocal("GT5U.machines.tier") - + ": " + EnumChatFormatting.YELLOW - + VN[ - GT_Utility.getTier(GT_ExoticEnergyInputHelper.getMaxInputVoltageMulti( - getExoticAndNormalEnergyHatchList()))] - + EnumChatFormatting.RESET, - StatCollector.translateToLocal("scanner.info.CASS.tier") - + (casingTier >= 0 ? GT_Values.VN[casingTier + 1] : "None!") - }; + String[] origin = super.getInfoData(); + String[] ret = new String[origin.length + 1]; + System.arraycopy(origin, 0, ret, 0, origin.length); + ret[origin.length] = StatCollector.translateToLocal("scanner.info.CASS.tier") + + (casingTier >= 0 ? GT_Values.VN[casingTier + 1] : "None!"); + return ret; } @Override @@ -640,57 +607,28 @@ public class ComponentAssemblyLine extends GT_MetaTileEntity_EnhancedMultiBlockB @Override public boolean checkRecipe(ItemStack aStack) { - long tVoltage = GT_ExoticEnergyInputHelper.getMaxInputVoltageMulti(getExoticAndNormalEnergyHatchList()); - long tAmps = GT_ExoticEnergyInputHelper.getMaxInputAmpsMulti(getExoticAndNormalEnergyHatchList()); - long totalEU = tVoltage * tAmps; + this.mEfficiencyIncrease = 10000; + this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000); + long totalEU = getRealVoltage(); ItemStack[] tItems = getStoredInputs().toArray(new ItemStack[0]); FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]); - GT_Recipe foundRecipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, totalEU, tFluids, tItems); - if (foundRecipe == null) return false; - if (foundRecipe.mSpecialValue > casingTier + 1) return false; - if (!foundRecipe.isRecipeInputEqual(true, tFluids, tItems)) return false; - - // Logic for overclocking calculations. - double EU_input_tier = Math.log(totalEU) / log4; - double EU_recipe_tier = Math.log(foundRecipe.mEUt) / log4; - long overclock_count = (long) Math.floor(EU_input_tier - EU_recipe_tier); - - // Vital recipe info. Calculate overclocks here if necessary. - EU_per_tick = (long) -(foundRecipe.mEUt * Math.pow(4, overclock_count)); - - mMaxProgresstime = (int) (foundRecipe.mDuration / Math.pow(2, overclock_count)); - mMaxProgresstime = Math.max(1, mMaxProgresstime); + this.lastRecipe = + getRecipeMap().findRecipe(getBaseMetaTileEntity(), this.lastRecipe, false, totalEU, tFluids, tItems); + if (this.lastRecipe == null) return false; + if (this.lastRecipe.mSpecialValue > casingTier + 1) return false; + if (!this.lastRecipe.isRecipeInputEqual(true, tFluids, tItems)) return false; + + calculateOverclockedNessMulti((long) this.lastRecipe.mEUt, this.lastRecipe.mDuration, 1, totalEU); + if (this.lEUt > 0) { + this.lEUt = (-this.lEUt); + } - mOutputItems = foundRecipe.mOutputs; + mOutputItems = this.lastRecipe.mOutputs; updateSlots(); return true; } @Override - public boolean onRunningTick(ItemStack aStack) { - if (EU_per_tick < 0) { - if (!drainEnergyInput(-EU_per_tick)) { - EU_per_tick = 0; - criticalStopMachine(); - return false; - } - } - return true; - } - - @Override - public boolean drainEnergyInput(long aEU) { - return GT_ExoticEnergyInputHelper.drainEnergy(aEU, getExoticAndNormalEnergyHatchList()); - } - - public List<GT_MetaTileEntity_Hatch> getExoticAndNormalEnergyHatchList() { - List<GT_MetaTileEntity_Hatch> tHatches = new ArrayList<>(); - tHatches.addAll(mExoticEnergyHatches); - tHatches.addAll(mEnergyHatches); - return tHatches; - } - - @Override public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { int realBudget = elementBudget >= 200 ? elementBudget : Math.min(200, elementBudget * 5); return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 4, 2, 0, realBudget, env, false, true); @@ -703,12 +641,6 @@ public class ComponentAssemblyLine extends GT_MetaTileEntity_EnhancedMultiBlockB } @Override - public void clearHatches() { - super.clearHatches(); - mExoticEnergyHatches.clear(); - } - - @Override public int getMaxEfficiency(ItemStack aStack) { return 10000; } @@ -731,14 +663,12 @@ public class ComponentAssemblyLine extends GT_MetaTileEntity_EnhancedMultiBlockB @Override public void saveNBTData(NBTTagCompound aNBT) { aNBT.setInteger("casingTier", casingTier); - aNBT.setLong("euPerTick", EU_per_tick); super.saveNBTData(aNBT); } @Override public void loadNBTData(final NBTTagCompound aNBT) { casingTier = aNBT.getInteger("casingTier"); - EU_per_tick = aNBT.getLong("euPerTick"); super.loadNBTData(aNBT); } } diff --git a/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java b/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java index aaec87d75c..7e2f9efbd1 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/PreciseAssembler.java @@ -203,7 +203,7 @@ public class PreciseAssembler extends GT_MetaTileEntity_LongPowerUsageBase<Preci this.getBaseMetaTileEntity(), this.lastRecipe, false, - Math.min(getMachineVoltageLimit(), getMaxInputEnergyPA()), + Math.min(getMachineVoltageLimit(), getRealVoltage()), inputFluids, getStoredItemFromHatch(bus)); if (this.lastRecipe != null && this.lastRecipe.mSpecialValue <= (casingTier + 1)) { @@ -211,8 +211,7 @@ public class PreciseAssembler extends GT_MetaTileEntity_LongPowerUsageBase<Preci this.mEfficiencyIncrease = 10000; this.lastRecipe.isRecipeInputEqual(true, inputFluids, getStoredItemFromHatch(bus)); mOutputItems = this.lastRecipe.mOutputs; - calculateOverclockedNessMulti( - this.lastRecipe.mEUt, this.lastRecipe.mDuration, 1, getMaxInputEnergyPA()); + calculateOverclockedNessMulti(this.lastRecipe.mEUt, this.lastRecipe.mDuration, 1, getRealVoltage()); this.updateSlots(); if (this.lEUt > 0) { this.lEUt = (-this.lEUt); @@ -228,13 +227,13 @@ public class PreciseAssembler extends GT_MetaTileEntity_LongPowerUsageBase<Preci this.getBaseMetaTileEntity(), this.lastRecipe, false, - Math.min(getMachineVoltageLimit(), getMaxInputEnergyPA()), + Math.min(getMachineVoltageLimit(), getRealVoltage()), inputFluids, getStoredItemFromHatch(bus)); if (this.lastRecipe != null) { this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; - long fullInput = getMaxInputEnergyPA(); + long fullInput = getRealVoltage(); int pall = handleParallelRecipe(this.lastRecipe, inputFluids, getStoredItemFromHatch(bus), (int) Math.min((long) Math.pow(2, 4 + (casingTier + 1)), fullInput / this.lastRecipe.mEUt)); if (pall <= 0) continue; @@ -244,7 +243,7 @@ public class PreciseAssembler extends GT_MetaTileEntity_LongPowerUsageBase<Preci (long) this.lastRecipe.mEUt * (long) pall, this.lastRecipe.mDuration / 2, 1, - getMaxInputEnergyPA()); + getRealVoltage()); this.updateSlots(); if (this.lEUt > 0) { this.lEUt = (-this.lEUt); @@ -256,25 +255,6 @@ public class PreciseAssembler extends GT_MetaTileEntity_LongPowerUsageBase<Preci return false; } - private long getMaxInputEnergyPA() { - long rEnergy = 0; - if (mEnergyHatches.size() == 1) { - // it works like most of the gt multies - return mEnergyHatches.get(0).getBaseMetaTileEntity().getInputVoltage(); - } - for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - rEnergy += tHatch.maxEUInput() * tHatch.maxAmperesIn(); - } - } - for (GT_MetaTileEntity_Hatch tHatch : mExoticEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - rEnergy += tHatch.maxEUInput() * ((GT_MetaTileEntity_Hatch_EnergyMulti) tHatch).Amperes; - } - } - return rEnergy; - } - @Override public int getMaxEfficiency(ItemStack aStack) { return 10000; @@ -302,11 +282,6 @@ public class PreciseAssembler extends GT_MetaTileEntity_LongPowerUsageBase<Preci } @Override - protected long getRealVoltage() { - return getMaxInputEnergyPA(); - } - - @Override public void construct(ItemStack stackSize, boolean hintsOnly) { buildPiece(mName, stackSize, hintsOnly, 4, 4, 0); } diff --git a/src/main/java/goodgenerator/blocks/tileEntity/base/GT_MetaTileEntity_LongPowerUsageBase.java b/src/main/java/goodgenerator/blocks/tileEntity/base/GT_MetaTileEntity_LongPowerUsageBase.java index b6e8f79ca8..79020d406a 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/base/GT_MetaTileEntity_LongPowerUsageBase.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/base/GT_MetaTileEntity_LongPowerUsageBase.java @@ -49,7 +49,24 @@ public abstract class GT_MetaTileEntity_LongPowerUsageBase<T extends GT_MetaTile return getInfoDataArray(this); } - protected abstract long getRealVoltage(); + protected long getRealVoltage() { + long rEnergy = 0; + if (mEnergyHatches.size() == 1 && mExoticEnergyHatches.isEmpty()) { + // it works like most of the gt multies + return mEnergyHatches.get(0).getBaseMetaTileEntity().getInputVoltage(); + } + for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { + if (isValidMetaTileEntity(tHatch)) { + rEnergy += tHatch.maxEUInput() * tHatch.maxAmperesIn(); + } + } + for (GT_MetaTileEntity_Hatch tHatch : mExoticEnergyHatches) { + if (isValidMetaTileEntity(tHatch)) { + rEnergy += tHatch.maxEUInput() * ((GT_MetaTileEntity_Hatch_EnergyMulti) tHatch).Amperes; + } + } + return rEnergy; + } protected long getMaxInputAmps() { long rAmps = 0; |