diff options
3 files changed, 323 insertions, 61 deletions
diff --git a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java index bba253ca48..3cf0974278 100644 --- a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java +++ b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java @@ -11,17 +11,17 @@ public class EyeOfHarmonyRecipe { private final List<Pair<ItemStack, Long>> output_items; private final FluidStack[] output_fluids; - private long hydrogen_requirement = Long.MAX_VALUE; - private long helium_requirement = Long.MAX_VALUE; + private long hydrogen_requirement; + private long helium_requirement; - private long eu_output = 0; - private long eu_start_cost = Long.MAX_VALUE; + private long eu_output; + private long eu_start_cost; - private long recipe_processing_time_in_ticks = Long.MAX_VALUE; + private long recipe_processing_time_in_ticks; - private double success_chance = 0; + private double base_success_chance; - private long spacetime_casing_tier_required = Long.MAX_VALUE; + private long spacetime_casing_tier_required; public EyeOfHarmonyRecipe(List<Pair<ItemStack, Long>> _output_items, FluidStack[] _output_fluids, @@ -30,7 +30,7 @@ public class EyeOfHarmonyRecipe { long _eu_output, long _eu_start_cost, long _recipe_processing_time_in_ticks, - double _success_chance, + double _base_success_chance, long _spacetime_casing_tier_required) { output_items = _output_items; @@ -44,7 +44,7 @@ public class EyeOfHarmonyRecipe { recipe_processing_time_in_ticks = _recipe_processing_time_in_ticks; - success_chance = _success_chance; + base_success_chance = _base_success_chance; // 0 - 7; spacetime_casing_tier_required = _spacetime_casing_tier_required; @@ -79,7 +79,7 @@ public class EyeOfHarmonyRecipe { } public double getBaseRecipeSuccessChance() { - return success_chance; + return base_success_chance; } public long getSpacetimeCasingTierRequired() { diff --git a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java index 72b67a2dd9..c6f192e467 100644 --- a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java +++ b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipeStorage.java @@ -1,29 +1,199 @@ package com.github.technus.tectech.recipe; import gregtech.api.enums.Materials; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.tuple.Pair; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.google.common.math.IntMath.pow; + public abstract class EyeOfHarmonyRecipeStorage { - public static EyeOfHarmonyRecipe recipe_0 = new EyeOfHarmonyRecipe( - Stream.of( - Pair.of(Materials.CosmicNeutronium.getDust(1), 100L), - Pair.of(Materials.Tin.getDust(1), 100L), - Pair.of(Materials.Iron.getDust(1), 100L)).collect(Collectors.toList()), - new FluidStack[] { - Materials.Iron.getPlasma(423_414_412), - Materials.Boron.getPlasma(32_314_391), - }, - 10_000_000L, - 10_000_000L, - 1_000_000_000_000L, - 1_000_000_000L, - 500, + static final long MILLION = pow(10, 6); + static final long BILLION = pow(10, 9); + static final long TRILLION = pow(10, 12); + static final long QUADRILLION = pow(10, 15); + static final long QUINTILLION = pow(10, 18); + static final long SEXTILLION = pow(10, 21); + + // VEGA B (approx), 36000 seconds, 3x multiplier on output (excluding 2x already from ore output): + // iron:490_898_412L + // gold:91_781_220L + // copper:156_028_074L + // antimony:24_912_048L + // lead:105_941_754L + // silver:26_223_204L + // naquadah:68_180_334L + // enriched naquadah:3_933_480L + // tungsten:22_289_724L + // lithium:1_311_162L + // uranium:94_403_538L + // arsenic:62_935_692L + // bismuth:71_327_118L + // infused gold:3_933_480L + // platinum:3_933_480L + // chrome:7_866_960L + // neutronium:18_880_710L + // adamantium:10_489_284L + // titanium:1_311_162L + // niobium:62_935_692L + // yttrium:62_935_692L + // gallium:15_733_926L + // thorium:62_935_692L + // uranium 238:62_935_692L + // plutonium 241:7_866_960L + // uranium 235:7_866_960L + // cadmium:41_957_130L + // caesium:41_957_130L + // lanthanum:5_244_642L + // cerium:5_244_642L + // awakened_draconium:2_097_858L + // black_plutonium:6_293_568L + // infinity_catalyst:6_293_568L + + static HashMap<Fluid, Long> plasma_energy_map = new HashMap<Fluid, Long>() {{ + put(Materials.Helium.getPlasma(1).getFluid(), 81_920L); + put(Materials.Boron.getPlasma(1).getFluid(), 112_640L); + put(Materials.Nitrogen.getPlasma(1).getFluid(), 129_024L); + put(Materials.Oxygen.getPlasma(1).getFluid(), 131_072L); + put(Materials.Sulfur.getPlasma(1).getFluid(), 170_393L); + put(Materials.Calcium.getPlasma(1).getFluid(), 188_416L); + put(Materials.Titanium.getPlasma(1).getFluid(), 196_608L); + put(Materials.Iron.getPlasma(1).getFluid(), 206_438L); + put(Materials.Nickel.getPlasma(1).getFluid(), 213_811L); + put(Materials.Zinc.getPlasma(1).getFluid(), 226_304L); + put(Materials.Niobium.getPlasma(1).getFluid(), 269_516L); + put(Materials.Silver.getPlasma(1).getFluid(), 282_685L); + put(Materials.Tin.getPlasma(1).getFluid(), 304_496L); + put(Materials.Americium.getPlasma(1).getFluid(), 501_760L); + put(Materials.Radon.getPlasma(1).getFluid(), 450_560L); + put(Materials.Bismuth.getPlasma(1).getFluid(), 425_984L); + }}; + + static long plasma_cost_calculator(FluidStack[] plasmas, double efficiency) { + long total = 0; + + for (FluidStack plasma : plasmas) { + total += (plasma_energy_map.get(plasma.getFluid()) * plasma.amount); + } + + return (long) (total * efficiency); + } + + static FluidStack[] valid_plasma_generator(final List<Pair<Materials, Long>> planet_list, final double multiplier) { + + List<FluidStack> plasma_list = new ArrayList<>(); + + for (Pair<Materials, Long> pair : planet_list) { + if (valid_plasmas.contains(pair.getLeft())) { + plasma_list.add(pair.getLeft().getPlasma((int) (pair.getRight() * multiplier))); + } + } + return plasma_list.toArray(new FluidStack[0]); + } + + static List<Pair<ItemStack, Long>> valid_dust_generator(final List<Pair<Materials, Long>> planet_list, final double multiplier) { + + List<Pair<ItemStack, Long>> dust_list = new ArrayList<>(); + + for (Pair<Materials, Long> pair : planet_list) { + if (valid_plasmas.contains(pair.getLeft())) { + dust_list.add(Pair.of(pair.getLeft().getDust(1), (long) (pair.getRight() * multiplier))); + } + } + return dust_list; + } + + static final List<Materials> valid_plasmas = Stream.of( + Materials.Copper, + Materials.Silver, + Materials.Helium, + Materials.Boron, + Materials.Nitrogen, + Materials.Oxygen, + Materials.Sulfur, + Materials.Calcium, + Materials.Titanium, + Materials.Iron, + Materials.Nickel, + Materials.Zinc, + Materials.Niobium, + Materials.Silver, + Materials.Tin, + Materials.Bismuth, + Materials.Americium, + Materials.Niobium + ).collect(Collectors.toList()); + + // Vega B weights (approximately). 36000 seconds, Og, UV VM, 2x for ore processing and a final 3x output bonus. + static final List<Pair<Materials, Long>> vega_b = Stream.of( + Pair.of(Materials.Iron, 490_898_412L), + Pair.of(Materials.Gold, 91_781_220L), + Pair.of(Materials.Copper, 156_028_074L), + Pair.of(Materials.Antimony, 24_912_048L), + Pair.of(Materials.Lead, 105_941_754L), + Pair.of(Materials.Silver, 26_223_204L), + Pair.of(Materials.Naquadah, 68_180_334L), + Pair.of(Materials.NaquadahEnriched, 3_933_480L), + Pair.of(Materials.Tungsten, 22_289_724L), + Pair.of(Materials.Lithium, 1_311_162L), + Pair.of(Materials.Uranium235, 94_403_538L + 156_028_074L), + Pair.of(Materials.Arsenic, 62_935_692L), + Pair.of(Materials.Bismuth, 71_327_118L), + Pair.of(Materials.InfusedGold, 3_933_480L), + Pair.of(Materials.Platinum, 3_933_480L), + Pair.of(Materials.Chrome, 7_866_960L), + Pair.of(Materials.Neutronium, 18_880_710L), + Pair.of(Materials.Adamantium, 10_489_284L), + Pair.of(Materials.Titanium, 1_311_162L), + Pair.of(Materials.Niobium, 62_935_692L), + Pair.of(Materials.Yttrium, 62_935_692L), + Pair.of(Materials.Gallium, 15_733_926L), + Pair.of(Materials.Thorium, 62_935_692L), + Pair.of(Materials.Uranium, 62_935_692L), + Pair.of(Materials.Plutonium241, 7_866_960L), + Pair.of(Materials.Cadmium, 41_957_130L), + Pair.of(Materials.Caesium, 41_957_130L), + Pair.of(Materials.Lanthanum, 5_244_642L), + Pair.of(Materials.Cerium, 5_244_642L), + Pair.of(Materials.DraconiumAwakened, 2_097_858L), + Pair.of(Materials.BlackPlutonium, 6_293_568L), + Pair.of(Materials.InfinityCatalyst, 6_293_568L) + ).collect(Collectors.toList()); + + static final FluidStack[] vega_b_plasmas = valid_plasma_generator(vega_b, 0.1); + + static final long vega_b_seconds = 36_000L; + + public static final EyeOfHarmonyRecipe recipe_0 = new EyeOfHarmonyRecipe( + valid_dust_generator(vega_b, 1), + vega_b_plasmas, + 100, + 100, + 1800 * TRILLION, + 524_288L * vega_b_seconds * 20 + 600 * TRILLION + plasma_cost_calculator(vega_b_plasmas, 1), + vega_b_seconds * 20, 0.40, 1 ); + + static final EyeOfHarmonyRecipe recipe_1 = new EyeOfHarmonyRecipe( + valid_dust_generator(vega_b, 1), + vega_b_plasmas, + 100 * BILLION, + 100 * BILLION, + 1800 * TRILLION, + 524_288L * vega_b_seconds * 20 + 600 * TRILLION + plasma_cost_calculator(vega_b_plasmas, 1), + vega_b_seconds * 20, + 0.40, + 1 + ); + } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java index f306848c36..9e740719f7 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java @@ -1,7 +1,6 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import com.github.technus.tectech.recipe.EyeOfHarmonyRecipe; -import com.github.technus.tectech.recipe.EyeOfHarmonyRecipeStorage; import com.github.technus.tectech.thing.casing.TT_Block_SpacetimeCompressionFieldGenerators; import com.github.technus.tectech.thing.casing.TT_Block_StabilisationFieldGenerators; import com.github.technus.tectech.thing.casing.TT_Block_TimeAccelerationFieldGenerators; @@ -32,6 +31,7 @@ import org.apache.commons.lang3.tuple.Pair; import java.util.*; +import static com.github.technus.tectech.recipe.EyeOfHarmonyRecipeStorage.recipe_0; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.textureOffset; import static com.github.technus.tectech.thing.casing.GT_Block_CasingsTT.texturePage; import static com.github.technus.tectech.thing.casing.TT_Container_Casings.sBlockCasingsTT; @@ -53,7 +53,9 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl private String user_uuid = ""; private String user_name = ""; - private long eu_output = 0; + private long euOutput = 0; + + private final long[] computationStack = new long[computationTickCacheSize]; // Multiblock structure. private static final IStructureDefinition<GT_MetaTileEntity_EM_EyeOfHarmony> STRUCTURE_DEFINITION = IStructureDefinition @@ -157,8 +159,8 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl private void calculateHydrogenHeliumInputExcessValues(long hydrogen_recipe_requirement, long helium_recipe_requirement) { - long hydrogen_stored = valid_fluid_map.get(Materials.Hydrogen.getGas(1L)); - long helium_stored = valid_fluid_map.get(Materials.Helium.getGas(1L)); + long hydrogen_stored = validFluidMap.get(Materials.Hydrogen.getGas(1L)); + long helium_stored = validFluidMap.get(Materials.Helium.getGas(1L)); double hydrogen_excess_percentage = abs(1 - hydrogen_stored / hydrogen_recipe_requirement); double helium_excess_percentage = abs(1 - helium_stored / helium_recipe_requirement); @@ -173,7 +175,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl + StabilisationFieldMetadata * 0.05 - hydrogen_overflow_probability_adjustment - helium_overflow_probability_adjustment - + max_percentage_chance_gain_from_computation_per_second * (1 - exp(-10e-5 * eAvailableData))); // eAvailableData = computation/s (kinda). + + max_percentage_chance_gain_from_computation_per_second * (1 - exp(-10e-5 * getComputation()))); return clamp_probability(chance); } @@ -199,7 +201,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl double double_recipe_time = (double) recipe_time; long spacetime_casing_difference = (recipe_spacetime_casing_required - SpacetimeCompressionFieldMetadata); - return (long) (double_recipe_time * pow(2, -TimeAccelerationFieldMetadata) * pow(1.03, spacetime_casing_difference)); + return (long) (double_recipe_time * pow(2, -TimeAccelerationFieldMetadata) * pow(0.97, spacetime_casing_difference)); } @Override @@ -229,11 +231,52 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl public GT_Multiblock_Tooltip_Builder createTooltip() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Spacetime Manipulator") + .addInfo(GOLD + "--------------------------------------------------------------------------------") .addInfo("Creates a pocket of spacetime that is bigger on the inside using") .addInfo("transdimensional engineering. Certified Time Lord regulation compliant.") .addInfo("This multi outputs too much EU to be handled with conventional means.") - .addInfo("All EU generated is directly deposited into your wireless EU network.") + .addInfo("All EU requirements are handled directly by your wireless EU network.") + .addInfo(GOLD + "--------------------------------------------------------------------------------") + .addInfo("This multiblock will constantly consume hydrogen and helium when it is") + .addInfo("not running. It will store this internally, you can see the totals by") + .addInfo("using a scanner. This multi also has three tiered blocks with " + RED + "7" + GRAY + " tiers") + .addInfo("each. They are as follows and have the associated effects on the multi.") + .addInfo(BLUE + "Spacetime Compression Field Generator:") + .addInfo("- The tier of this block determines what recipes can be run. If the multiblocks") + .addInfo(" spacetime compression field block exceeds the requirements of the recipe it") + .addInfo(" will decrease the processing time by " + RED + "3%" + GRAY + " per tier over the requirement. This") + .addInfo(" is multiplicative.") + .addInfo(BLUE + "Time Dilation Field Generator:") + .addInfo("- Decreases the time required by a recipe by a factor of " + RED + "2" + GRAY + " per tier of block.") + .addInfo(" Decreases the probability of a recipe succeeding by " + RED + "10%" + GRAY + " per tier (additive)") + .addInfo(BLUE + "Stabilisation Field Generator:") + .addInfo("- Increases the probability of a recipe succeeding by " + RED + "5%" + GRAY + " per tier (additive).") + .addInfo(" Decreases the yield of a recipe by " + RED + "5%" + GRAY + " per tier (additive). ") + .addInfo(GOLD + "--------------------------------------------------------------------------------") + .addInfo("Computation/s provided to the multiblock can increase the chance by up to " + RED + GT_Utility.formatNumbers(max_percentage_chance_gain_from_computation_per_second * 100) + GRAY + "%.") + .addInfo("The associated formula is " + GREEN + "additional_chance = 0.3 * exp(10^(-5) * computation_per_second)" + GRAY + ".") + .addInfo(GOLD + "--------------------------------------------------------------------------------") + .addInfo("Going over a recipe requirement on hydrogen or helium has a penalty on yield and recipe") + .addInfo("chance. All stored hydrogen and helium is consumed during a craft. The associated formulas are:") + .addInfo(GREEN + "percentage_overflow = abs(1 - fluid_stored/recipe_requirement)") + .addInfo(GREEN + "adjustment_value = 1 - exp(-(30 * percentage_overflow)^2)") + .addInfo("The value of adjustment_value is then subtracted from the total yield and recipe chance.") + .addInfo(GOLD + "--------------------------------------------------------------------------------") + .addInfo("It should be noted that base recipe chance is determined per recipe and yield always") + .addInfo("starts at 1 and subtracts depending on penalities. All fluid/item outputs are multiplied") + .addInfo("by the yield calculated.") + .addInfo(GOLD + "--------------------------------------------------------------------------------") + .addInfo("This multiblock requires a quantum chest to be placed in front each output bus for") + .addInfo("items to output properly. Items will be instantly deposited into them when the recipe") + .addInfo("finishes. If a quantum chest is full it will void any items over the max it can hold.") + .addInfo("If a quantum chest is occupied by another item it will be passed over. If no chest is") + .addInfo("avaliable the items will be " + UNDERLINE + DARK_RED + "voided" + RESET + GRAY + ".") + .addInfo(GOLD + "--------------------------------------------------------------------------------") + .addInfo("Recipes that fail will return a random amount of the fluid back from the recipe and some") + .addInfo("exotic materials that reject conventional physics.") + .addSeparator() + .beginStructureBlock(33, 33, 33, false) .toolTipFinisher(CommonValues.TEC_MARK_EM + " & " + AuthorColen.substring(8)); return tt; @@ -263,7 +306,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl structureBuild_EM("main", 16, 16, 0, stackSize, hintsOnly); } - private final Map<FluidStack, Long> valid_fluid_map = new HashMap<FluidStack, Long>() {{ + private final Map<FluidStack, Long> validFluidMap = new HashMap<FluidStack, Long>() {{ put(Materials.Hydrogen.getGas(1), 0L); put(Materials.Helium.getGas(1), 0L); }}; @@ -277,9 +320,9 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl } // Iterate over valid fluids and store them in a hashmap. - for (FluidStack valid_fluid : valid_fluid_map.keySet()) { + for (FluidStack valid_fluid : validFluidMap.keySet()) { if (fluid_in_hatch.isFluidEqual(valid_fluid)) { - valid_fluid_map.put(valid_fluid, valid_fluid_map.get(valid_fluid) + (long) fluid_in_hatch.amount); + validFluidMap.put(valid_fluid, validFluidMap.get(valid_fluid) + (long) fluid_in_hatch.amount); input_hatch.setFillableStack(null); } } @@ -289,24 +332,31 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl @Override public boolean checkRecipe_EM(ItemStack aStack) { + long hydrogen_stored = validFluidMap.get(Materials.Hydrogen.getGas(1)); + long helium_stored = validFluidMap.get(Materials.Helium.getGas(1)); - long hydrogen_stored = valid_fluid_map.get(Materials.Hydrogen.getGas(1)); - long helium_stored = valid_fluid_map.get(Materials.Helium.getGas(1)); + System.out.println("TEST123VC" + recipe_0.getEUOutput()); - EyeOfHarmonyRecipe recipe; - - recipe = EyeOfHarmonyRecipeStorage.recipe_0; - if ((hydrogen_stored >= recipe.getHydrogenRequirement()) & (helium_stored >= recipe.getHeliumRequirement())) { - return processRecipe(recipe); + if ((hydrogen_stored >= recipe_0.getHydrogenRequirement()) & (helium_stored >= recipe_0.getHeliumRequirement())) { + return processRecipe(recipe_0); } return false; } - public boolean processRecipe(EyeOfHarmonyRecipe recipeObject) { - mMaxProgresstime = (int) max(1, recipeProcessTimeCalculator(recipeObject.getRecipeTime(), recipeObject.getSpacetimeCasingTierRequired())); + // Check tier of spacetime compression blocks is high enough. + if (SpacetimeCompressionFieldMetadata <= recipeObject.getSpacetimeCasingTierRequired()) { + return false; + } + + // Remove EU from the users network. + if (!addEUToGlobalEnergyMap(user_uuid, -recipeObject.getEUStartCost())) { + return false; + } + + mMaxProgresstime = (int) Math.max(1, recipeProcessTimeCalculator(recipeObject.getRecipeTime(), recipeObject.getSpacetimeCasingTierRequired())); calculateHydrogenHeliumInputExcessValues(recipeObject.getHydrogenRequirement(), recipeObject.getHeliumRequirement()); // DEBUG ! DELETE THESE TWO LINES: @@ -315,17 +365,15 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl success_chance = recipeChanceCalculator(recipeObject.getBaseRecipeSuccessChance()); - // Remove EU from the users network. - if (!addEUToGlobalEnergyMap(user_uuid, -recipeObject.getEUStartCost())) { - return false; - } - // Determine EU recipe output. - eu_output = recipeObject.getEUOutput(); + euOutput = recipeObject.getEUOutput(); + + // Set expected recipe computation. + eRequiredData = getComputation(); // Reduce internal storage by hydrogen and helium quantity required for recipe. - valid_fluid_map.put(Materials.Hydrogen.getGas(1), 0L); - valid_fluid_map.put(Materials.Helium.getGas(1), 0L); + validFluidMap.put(Materials.Hydrogen.getGas(1), 0L); + validFluidMap.put(Materials.Helium.getGas(1), 0L); double yield = recipeYieldCalculator(); @@ -348,6 +396,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl mOutputFluids = tmp_fluids_output; updateSlots(); + recipeRunning = true; return true; } @@ -357,15 +406,23 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl } + @Override + public void stopMachine() { + super.stopMachine(); + recipeRunning = false; + } + public void outputAfterRecipe_EM() { + recipeRunning = false; + eRequiredData = 0L; if (success_chance > random()) { outputFailedChance(); return; } - addEUToGlobalEnergyMap(user_uuid, eu_output); - eu_output = 0; + addEUToGlobalEnergyMap(user_uuid, euOutput); + euOutput = 0; int index = 0; for (Pair<ItemStack, Long> item : output_items) { @@ -380,20 +437,53 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl super.outputAfterRecipe_EM(); } + private void pushComputation() { + // Add computation to finite "stack". + for (int i = computationTickCacheSize - 1 ; i > 2; i--) { + computationStack[i-1] = computationStack[i]; + } + computationStack[0] = eAvailableData; + } + @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPreTick(aBaseMetaTileEntity, aTick); if (aTick == 1) { + user_uuid = String.valueOf(getBaseMetaTileEntity().getOwnerUuid()); user_name = getBaseMetaTileEntity().getOwnerName(); strongCheckOrAddUser(user_uuid, user_name); } - if (aTick % ticks_between_hatch_drain == 0) { - drainFluidFromHatchesAndStoreInternally(); + // Add computation to stack. Prevents small interruptions causing issues. + pushComputation(); + + if (!recipeRunning) { + if (aTick % ticks_between_hatch_drain == 0) { + drainFluidFromHatchesAndStoreInternally(); + } + } + } + + private boolean recipeRunning = false; + private final static int computationTickCacheSize = 5; + + private long getComputation() { + return max(computationStack); + } + + private long max(long[] array) { + long max = array[0]; + + for (int i = 1; i < array.length; i++) { + if (array[i] > max) { + max = array[i]; + } } + + return max; } private void addItemsToQuantumChest(IGregTechTileEntity quantum_chest, long amount) { @@ -476,8 +566,6 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl return false; } - - @Override public String[] getInfoData() { ArrayList<String> str = new ArrayList<>(Arrays.asList(super.getInfoData())); @@ -486,7 +574,7 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl str.add("Time Dilation Field Grade: " + BLUE + TimeAccelerationFieldMetadata); str.add("Stabilisation Field Grade: " + BLUE + StabilisationFieldMetadata); str.add(GOLD + "----------------- Internal Fluids Stored ----------------"); - valid_fluid_map.forEach((key, value) -> str.add(BLUE + key.getLocalizedName() + RESET + + validFluidMap.forEach((key, value) -> str.add(BLUE + key.getLocalizedName() + RESET + " : " + RED + GT_Utility.formatNumbers(value))); str.add(GOLD + "-----------------------------------------------------"); return str.toArray(new String[0]); @@ -494,14 +582,16 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl @Override public String[] getStructureDescription(ItemStack stackSize) { - return new String[] {"?? No idea what this does."}; + return new String[] {"Eye of Harmony multiblock"}; } @Override public void saveNBTData(NBTTagCompound aNBT) { // Save the quantity of fluid stored inside the controller. - valid_fluid_map.forEach((key, value) -> aNBT.setLong("stored." + key.getUnlocalizedName(), value)); + validFluidMap.forEach((key, value) -> aNBT.setLong("stored." + key.getUnlocalizedName(), value)); + + aNBT.setBoolean("eye_of_harmony_recipeRunning", recipeRunning); super.saveNBTData(aNBT); } @@ -510,7 +600,9 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl public void loadNBTData(final NBTTagCompound aNBT) { // Load the quantity of fluid stored inside the controller. - valid_fluid_map.forEach((key, value) -> valid_fluid_map.put(key, aNBT.getLong("stored." + key.getUnlocalizedName()))); + validFluidMap.forEach((key, value) -> validFluidMap.put(key, aNBT.getLong("stored." + key.getUnlocalizedName()))); + + recipeRunning = aNBT.getBoolean("eye_of_harmony_recipeRunning"); super.loadNBTData(aNBT); } |