From fe0e98b1e835ce3325018ce9ae18eaf6df95da18 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 22 Jun 2022 09:01:13 +0100 Subject: Add customizable EBF gas recipe time and gas consumption multipliers (#137) * Add customizable EBF gas recipe time and gas consumption multipliers * Add missing variables to equals&hashCode Former-commit-id: b5abf76d28994a85961a39e379cba9a4166248cd --- build.gradle | 46 +++++--- dependencies.gradle | 8 +- .../common/loaders/StaticRecipeChangeLoaders.java | 123 +++++++++++++++++---- .../bartworks/system/material/Werkstoff.java | 34 +++++- 4 files changed, 164 insertions(+), 47 deletions(-) diff --git a/build.gradle b/build.gradle index 5906f8fc98..c09bee22f3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1644894948 +//version: 1652851397 /* DO NOT CHANGE THIS FILE! @@ -6,12 +6,11 @@ Also, you may replace this file at any time if there is an update available. Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates. */ -import org.gradle.internal.logging.text.StyledTextOutput -import org.gradle.internal.logging.text.StyledTextOutputFactory -import org.gradle.internal.logging.text.StyledTextOutput.Style import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.internal.logging.text.StyledTextOutput.Style +import org.gradle.internal.logging.text.StyledTextOutputFactory import java.util.concurrent.TimeUnit @@ -45,13 +44,14 @@ plugins { id 'eclipse' id 'scala' id 'maven-publish' - id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false - id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false + id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false + id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false + id 'com.google.devtools.ksp' version '1.5.30-1.0.0' apply false id 'org.ajoberstar.grgit' version '4.1.1' id 'com.github.johnrengelman.shadow' version '4.0.4' - id 'com.palantir.git-version' version '0.13.0' apply false + id 'com.palantir.git-version' version '0.13.0' apply false id 'de.undercouch.download' version '5.0.1' - id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false + id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false } if (project.file('.git/HEAD').isFile()) { @@ -104,6 +104,7 @@ checkPropertyExists("usesShadowedDependencies") checkPropertyExists("developmentEnvironmentUserName") boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false +boolean usesMixinDebug = project.findProperty('usesMixinDebug') ?: project.usesMixins.toBoolean() String javaSourceDir = "src/main/java/" String scalaSourceDir = "src/main/scala/" @@ -214,13 +215,17 @@ else { def arguments = [] def jvmArguments = [] -if(usesMixins.toBoolean()) { +if (usesMixins.toBoolean()) { arguments += [ - "--tweakClass org.spongepowered.asm.launch.MixinTweaker" - ] - jvmArguments += [ - "-Dmixin.debug.countInjections=true", "-Dmixin.debug.verbose=true", "-Dmixin.debug.export=true" + "--tweakClass org.spongepowered.asm.launch.MixinTweaker" ] + if (usesMixinDebug.toBoolean()) { + jvmArguments += [ + "-Dmixin.debug.countInjections=true", + "-Dmixin.debug.verbose=true", + "-Dmixin.debug.export=true" + ] + } } minecraft { @@ -312,18 +317,23 @@ def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + mixingConfig def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg" task generateAssets { - if(usesMixins.toBoolean()) { - getFile("/src/main/resources/mixins." + modId + ".json").text = """{ + if (usesMixins.toBoolean()) { + def mixinConfigFile = getFile("/src/main/resources/mixins." + modId + ".json"); + if (!mixinConfigFile.exists()) { + mixinConfigFile.text = """{ "required": true, "minVersion": "0.7.11", "package": "${modGroup}.${mixinsPackage}", "plugin": "${modGroup}.${mixinPlugin}", "refmap": "${mixingConfigRefMap}", "target": "@env(DEFAULT)", - "compatibilityLevel": "JAVA_8" + "compatibilityLevel": "JAVA_8", + "mixins": [], + "client": [], + "server": [] } - """ + } } } @@ -559,7 +569,7 @@ publishing { artifact source: shadowJar, classifier: "" } if(!noPublishedSources) { - artifact source: sourcesJar, classifier: "src" + artifact source: sourcesJar, classifier: "sources" } artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev" if (apiPackage) { diff --git a/dependencies.gradle b/dependencies.gradle index 34df9bf9d4..3e93aaf029 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,10 +1,10 @@ // Add your dependencies here dependencies { - compile("com.github.GTNewHorizons:GT5-Unofficial:5.09.40.42:dev") - compile("com.github.GTNewHorizons:StructureLib:1.0.15:dev") + compile("com.github.GTNewHorizons:GT5-Unofficial:5.09.40.49:dev") + compile("com.github.GTNewHorizons:StructureLib:1.0.16:dev") compile("com.github.GTNewHorizons:TecTech:4.10.18:dev") - compile("com.github.GTNewHorizons:NotEnoughItems:2.2.12-GTNH:dev") + compile("com.github.GTNewHorizons:NotEnoughItems:2.2.15-GTNH:dev") compile("com.github.GTNewHorizons:TinkersConstruct:1.9.0.13-GTNH:dev") compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.3:dev") compile("com.github.GTNewHorizons:CodeChickenCore:1.1.3:dev") @@ -14,7 +14,7 @@ dependencies { } compile("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev") - compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-75-GTNH:dev") { + compileOnly("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-86-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:AppleCore:3.1.9:dev") { diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java index 6282852d58..154d2a03d6 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/StaticRecipeChangeLoaders.java @@ -33,7 +33,12 @@ import com.github.bartimaeusnek.bartworks.util.log.DebugLog; import com.github.bartimaeusnek.crossmod.BartWorksCrossmod; import com.google.common.collect.ArrayListMultimap; import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.enums.*; +import gnu.trove.map.hash.TObjectDoubleHashMap; +import gregtech.api.enums.Element; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SubTag; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; @@ -46,23 +51,51 @@ import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.reflect.FieldUtils; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import static com.github.bartimaeusnek.bartworks.common.tileentities.multis.GT_TileEntity_ElectricImplosionCompressor.eicMap; -import static com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader.*; +import static com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader.ANAEROBE_GAS; +import static com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader.NOBLE_GAS; +import static com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader.Oganesson; +import static com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader.fluids; +import static com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader.molten; import static gregtech.api.enums.GT_Values.VN; public class StaticRecipeChangeLoaders { + private static TObjectDoubleHashMap gtEbfGasRecipeTimeMultipliers = null; + private static TObjectDoubleHashMap gtEbfGasRecipeConsumptionMultipliers = null; + private StaticRecipeChangeLoaders() { } public static void addEBFGasRecipes() { + if (gtEbfGasRecipeTimeMultipliers == null) { + // For Werkstoff gases, use Werkstoff.Stats.setEbfGasRecipeTimeMultiplier + gtEbfGasRecipeTimeMultipliers = new TObjectDoubleHashMap<>(10, 0.5F, -1.0D); // keep default value as -1 + // Example to make Argon cut recipe times into a third of the original: + // gtEbfGasRecipeTimeMultipliers.put(Materials.Argon, 1.0D / 3.0D); + } + if (gtEbfGasRecipeConsumptionMultipliers == null) { + // For Werkstoff gases, use Werkstoff.Stats.setEbfGasRecipeConsumedAmountMultiplier + gtEbfGasRecipeConsumptionMultipliers = new TObjectDoubleHashMap<>(10, 0.5F, 1.0D); // keep default value as 1 + // Example to make Argon recipes use half the gas amount of the primary recipe (1000L->500L, 2000L->1000L etc.): + // gtEbfGasRecipeConsumptionMultipliers.put(Materials.Argon, 1.0D / 2.0D); + } ArrayListMultimap toChange = getRecipesToChange(NOBLE_GAS, ANAEROBE_GAS); editRecipes(toChange, getNoGasItems(toChange)); } @@ -281,12 +314,16 @@ public class StaticRecipeChangeLoaders { } } + /** + * Constructs a list of recipes to change by scanning all EBF recipes for uses of noble gases. + * @param GasTags list of gas tags to look out for in EBF recipes + * @return A multimap from the gas tag (noble and/or anaerobic) to all the recipes containing a gas with that tag + */ private static ArrayListMultimap getRecipesToChange(SubTag... GasTags) { ArrayListMultimap toAdd = ArrayListMultimap.create(); for (GT_Recipe recipe : GT_Recipe.GT_Recipe_Map.sBlastRecipes.mRecipeList) { if (recipe.mFluidInputs != null && recipe.mFluidInputs.length > 0) { - String FluidString = recipe.mFluidInputs[0].getFluid().getName().replaceAll("molten", "").replaceAll("fluid", ""); - Materials mat = Materials.get(FluidString.substring(0, 1).toUpperCase() + FluidString.substring(1)); + Materials mat = getMaterialFromInputFluid(recipe); if (mat != Materials._NULL) { for (SubTag tag : GasTags) { if (mat.contains(tag)) { @@ -300,6 +337,12 @@ public class StaticRecipeChangeLoaders { return toAdd; } + /** + * Scans EBF recipes for no-gas variants of the recipes present in base. + * Adds these recipes to the base multimap. + * @param base The recipe multimap to scan and modify + * @return Set of item outputs (recipe.mOutputs[0]) of the no-gas recipes + */ private static HashSet getNoGasItems(ArrayListMultimap base) { HashSet toAdd = new HashSet<>(); ArrayListMultimap repToAdd = ArrayListMultimap.create(); @@ -321,25 +364,54 @@ public class StaticRecipeChangeLoaders { return toAdd; } - private static void editEBFMaterialRecipes(SubTag GasTag, GT_Recipe recipe, Materials mat, HashSet toAdd) { - for (Materials materials : Materials.values()) { - if (materials.contains(GasTag)) { - int time = (int) ((double) recipe.mDuration / 200D * (200D + (materials.getProtons() >= mat.getProtons() ? (double) mat.getProtons() - (double) materials.getProtons() : (double) mat.getProtons() * 2.75D - (double) materials.getProtons()))); - toAdd.add(new BWRecipes.DynamicGTRecipe(false, recipe.mInputs, recipe.mOutputs, recipe.mSpecialItems, recipe.mChances, new FluidStack[]{materials.getGas(recipe.mFluidInputs[0].amount)}, recipe.mFluidOutputs, time, recipe.mEUt, recipe.mSpecialValue)); + private static int transformEBFGasRecipeTime(int originalDuration, long originalGasProtons, long newGasProtons) { + double protonTerm = (double) originalGasProtons * (newGasProtons >= originalGasProtons ? 1.0D : 2.75D) - (double) newGasProtons; + return Math.max(1, (int) ((double) originalDuration / 200D * Math.max(200D + protonTerm, 1D))); + } + + private static int transformEBFGasRecipeTime(GT_Recipe recipe, Materials originalGas, Materials newGas) { + double newEbfMul = gtEbfGasRecipeTimeMultipliers.get(newGas); + if (newEbfMul < 0.0D) { + return transformEBFGasRecipeTime(recipe.mDuration, originalGas.getProtons(), newGas.getProtons()); + } else { + return Math.max(1, (int) ((double) recipe.mDuration * newEbfMul)); + } + } + + private static int transformEBFGasRecipeTime(GT_Recipe recipe, Materials originalGas, Werkstoff newGas) { + double newEbfMul = newGas.getStats().getEbfGasRecipeTimeMultiplier(); + if (newEbfMul < 0.0D) { + return transformEBFGasRecipeTime(recipe.mDuration, originalGas.getProtons(), newGas.getStats().getProtons()); + } else { + return Math.max(1, (int) ((double) recipe.mDuration * newEbfMul)); + } + } + + private static int transformEBFNoGasRecipeTime(GT_Recipe recipe, Materials originalGas) { + return transformEBFGasRecipeTime(recipe.mDuration, originalGas.getProtons(), 0); + } + + private static void editEBFMaterialRecipes(SubTag GasTag, GT_Recipe recipe, Materials originalGas, HashSet toAdd) { + for (Materials newGas : Materials.values()) { + if (newGas.contains(GasTag)) { + int time = transformEBFGasRecipeTime(recipe, originalGas, newGas); + int gasAmount = Math.max(1, (int) Math.round((double) recipe.mFluidInputs[0].amount * gtEbfGasRecipeConsumptionMultipliers.get(newGas))); + toAdd.add(new BWRecipes.DynamicGTRecipe(false, recipe.mInputs, recipe.mOutputs, recipe.mSpecialItems, recipe.mChances, new FluidStack[]{newGas.getGas(gasAmount)}, recipe.mFluidOutputs, time, recipe.mEUt, recipe.mSpecialValue)); } } } - private static void editEBFWerkstoffRecipes(SubTag GasTag, GT_Recipe recipe, Materials mat, HashSet toAdd) { - for (Werkstoff werkstoff : Werkstoff.werkstoffHashMap.values()) { - if (werkstoff.contains(GasTag)) { - int time = (int) ((double) recipe.mDuration / 200D * (200D + (werkstoff.getStats().getProtons() >= mat.getProtons() ? (double) mat.getProtons() - (double) werkstoff.getStats().getProtons() : (double) mat.getProtons() * 2.75D - (double) werkstoff.getStats().getProtons()))); - toAdd.add(new BWRecipes.DynamicGTRecipe(false, recipe.mInputs, recipe.mOutputs, recipe.mSpecialItems, recipe.mChances, new FluidStack[]{new FluidStack(Objects.requireNonNull(fluids.get(werkstoff)), recipe.mFluidInputs[0].amount)}, recipe.mFluidOutputs, time, recipe.mEUt, recipe.mSpecialValue)); + private static void editEBFWerkstoffRecipes(SubTag GasTag, GT_Recipe recipe, Materials originalGas, HashSet toAdd) { + for (Werkstoff newGas : Werkstoff.werkstoffHashMap.values()) { + if (newGas.contains(GasTag)) { + int time = transformEBFGasRecipeTime(recipe, originalGas, newGas); + int gasAmount = Math.max(1, (int) Math.round((double) recipe.mFluidInputs[0].amount * newGas.getStats().getEbfGasRecipeConsumedAmountMultiplier())); + toAdd.add(new BWRecipes.DynamicGTRecipe(false, recipe.mInputs, recipe.mOutputs, recipe.mSpecialItems, recipe.mChances, new FluidStack[]{new FluidStack(Objects.requireNonNull(fluids.get(newGas)), gasAmount)}, recipe.mFluidOutputs, time, recipe.mEUt, recipe.mSpecialValue)); } } } - private static void editEBFNoGasRecipes(GT_Recipe recipe, Materials mat, HashSet toAdd, HashSet noGas) { + private static void editEBFNoGasRecipes(GT_Recipe recipe, Materials originalGas, HashSet toAdd, HashSet noGas) { for (ItemStack is : noGas) { byte circuitConfiguration = 1; if (GT_Utility.areStacksEqual(is, recipe.mOutputs[0])) { @@ -351,7 +423,7 @@ public class StaticRecipeChangeLoaders { inputs.add(stack); } inputs.add(GT_Utility.getIntegratedCircuit(circuitConfiguration)); - toAdd.add(new BWRecipes.DynamicGTRecipe(false, inputs.toArray(new ItemStack[0]), recipe.mOutputs, recipe.mSpecialItems, recipe.mChances, null, recipe.mFluidOutputs, (int) ((double) recipe.mDuration / 200D * (200D + ((double) mat.getProtons() * 2.75D))), recipe.mEUt, recipe.mSpecialValue)); + toAdd.add(new BWRecipes.DynamicGTRecipe(false, inputs.toArray(new ItemStack[0]), recipe.mOutputs, recipe.mSpecialItems, recipe.mChances, null, recipe.mFluidOutputs, transformEBFNoGasRecipeTime(recipe, originalGas), recipe.mEUt, recipe.mSpecialValue)); break; } } @@ -380,8 +452,11 @@ public class StaticRecipeChangeLoaders { } private static Materials getMaterialFromInputFluid(GT_Recipe recipe) { - String materialString = recipe.mFluidInputs[0].getFluid().getName().replaceAll("molten", "").replaceAll("fluid", ""); - return Materials.get(materialString.substring(0, 1).toUpperCase() + materialString.substring(1)); + String materialString = recipe.mFluidInputs[0].getFluid().getName(); + materialString = StringUtils.removeStart(materialString, "molten"); + materialString = StringUtils.removeStart(materialString, "fluid"); + materialString = StringUtils.capitalize(materialString); + return Materials.get(materialString); } private static void editRecipes(ArrayListMultimap base, HashSet noGas) { @@ -393,11 +468,11 @@ public class StaticRecipeChangeLoaders { for (SubTag gasTag : base.keySet()) { for (GT_Recipe recipe : base.get(gasTag)) { if (recipe.mFluidInputs != null && recipe.mFluidInputs.length > 0) { - Materials mat = getMaterialFromInputFluid(recipe); - if (mat != Materials._NULL) { - editEBFWerkstoffRecipes(gasTag, recipe, mat, toAdd); - editEBFMaterialRecipes(gasTag, recipe, mat, toAdd); - editEBFNoGasRecipes(recipe, mat, toAdd, noGas); + Materials originalGas = getMaterialFromInputFluid(recipe); + if (originalGas != Materials._NULL) { + editEBFWerkstoffRecipes(gasTag, recipe, originalGas, toAdd); + editEBFMaterialRecipes(gasTag, recipe, originalGas, toAdd); + editEBFNoGasRecipes(recipe, originalGas, toAdd, noGas); } } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/Werkstoff.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/Werkstoff.java index 17b390713f..49672d3706 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/Werkstoff.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/Werkstoff.java @@ -22,6 +22,7 @@ package com.github.bartimaeusnek.bartworks.system.material; +import com.github.bartimaeusnek.bartworks.common.loaders.StaticRecipeChangeLoaders; import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler; import com.github.bartimaeusnek.bartworks.util.BW_ColorUtil; import com.github.bartimaeusnek.bartworks.util.BW_Util; @@ -855,6 +856,33 @@ public class Werkstoff implements IColorModulationContainer, ISubTagContainer { return this; } + public double getEbfGasRecipeTimeMultiplier() { + return this.ebfGasRecipeTimeMultiplier; + } + + /** + * The generated EBF recipes using this gas will have their duration multiplied by this number. + * If set to a negative value, the default proton count-based logic is used. + * For GT Materials gases, add the overrides to {@link StaticRecipeChangeLoaders#addEBFGasRecipes()} + */ + public Werkstoff.Stats setEbfGasRecipeTimeMultiplier(double timeMultiplier) { + this.ebfGasRecipeTimeMultiplier = timeMultiplier; + return this; + } + + public double getEbfGasRecipeConsumedAmountMultiplier() { + return this.ebfGasRecipeConsumedAmountMultiplier; + } + + /** + * The generated EBF recipes using this gas will have the amount of gas consumed multiplied by this number. + * For GT Materials gases, add the overrides to {@link StaticRecipeChangeLoaders#addEBFGasRecipes()} + */ + public Werkstoff.Stats setEbfGasRecipeConsumedAmountMultiplier(double amountMultiplier) { + this.ebfGasRecipeConsumedAmountMultiplier = amountMultiplier; + return this; + } + public int getDurOverride() { return durOverride; } @@ -891,6 +919,8 @@ public class Werkstoff implements IColorModulationContainer, ISubTagContainer { private long neutrons; private long electrons; private long mass; + private double ebfGasRecipeTimeMultiplier = -1.0; + private double ebfGasRecipeConsumedAmountMultiplier = 1.0; float durMod = 1f; @@ -934,12 +964,14 @@ public class Werkstoff implements IColorModulationContainer, ISubTagContainer { if (this.protons != that.protons) return false; if (this.neutrons != that.neutrons) return false; if (this.electrons != that.electrons) return false; + if (Math.abs(this.ebfGasRecipeTimeMultiplier - that.ebfGasRecipeTimeMultiplier) > 1.0e-6D) return false; + if (Math.abs(this.ebfGasRecipeConsumedAmountMultiplier - that.ebfGasRecipeConsumedAmountMultiplier) > 1.0e-6D) return false; return this.quality == that.quality; } @Override public int hashCode() { - return MurmurHash3.murmurhash3_x86_32(ByteBuffer.allocate(49).put(this.quality).putInt(this.boilingPoint).putInt(this.meltingPoint).putLong(this.protons).putLong(this.neutrons).putLong(this.electrons).putLong(this.mass).array(), 0, 49, 31); + return MurmurHash3.murmurhash3_x86_32(ByteBuffer.allocate(49).put(this.quality).putInt(this.boilingPoint).putInt(this.meltingPoint).putLong(this.protons).putLong(this.neutrons).putLong(this.electrons).putLong(this.mass).putDouble(this.ebfGasRecipeTimeMultiplier).putDouble(this.ebfGasRecipeConsumedAmountMultiplier).array(), 0, 49, 31); } public Werkstoff.Stats setMass(long mass) { -- cgit