From 029f610b6e2d36f9700b0925f3784a614ea7232c Mon Sep 17 00:00:00 2001 From: kross <135918757+krossgg@users.noreply.github.com> Date: Fri, 20 Dec 2024 01:48:41 -0500 Subject: [PATCH] Fix Various KJS issues (#2596) --- .../registry/registrate/MachineBuilder.java | 4 +++ .../gtceu/common/data/GTMachines.java | 2 +- .../integration/kjs/GregTechKubeJSPlugin.java | 4 +++ .../kjs/builders/GTRecipeCategoryBuilder.java | 34 +++++++++++-------- .../machine/KJSSteamMachineBuilder.java | 15 ++++++-- .../machine/KJSTieredMachineBuilder.java | 10 ++++-- .../machine/KJSTieredMultiblockBuilder.java | 3 +- .../machine/KJSWrappingMachineBuilder.java | 7 ++++ .../machine/KJSWrappingMultiblockBuilder.java | 7 ++++ .../kjs/helpers/MachineModifiers.java | 28 +++++++++++++++ 10 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/integration/kjs/helpers/MachineModifiers.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/MachineBuilder.java b/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/MachineBuilder.java index 9485a37ecd..d0606c286e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/MachineBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/MachineBuilder.java @@ -220,6 +220,10 @@ public MachineBuilder workableTieredHullRenderer(ResourceLocation wo return renderer(() -> new WorkableTieredHullMachineRenderer(tier, workableModel)); } + public MachineBuilder simpleGeneratorMachineRenderer(ResourceLocation workableModel) { + return renderer(() -> new SimpleGeneratorMachineRenderer(tier, workableModel)); + } + public MachineBuilder workableSteamHullRenderer(boolean isHighPressure, ResourceLocation workableModel) { return renderer(() -> new WorkableSteamMachineRenderer(isHighPressure, workableModel)); diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java index f154164688..0e80b71b39 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java @@ -2322,7 +2322,7 @@ public static MachineDefinition[] registerSimpleGenerator(String name, .recipeModifier(SimpleGeneratorMachine::recipeModifier, true) .addOutputLimit(ItemRecipeCapability.CAP, 0) .addOutputLimit(FluidRecipeCapability.CAP, 0) - .renderer(() -> new SimpleGeneratorMachineRenderer(tier, GTCEu.id("block/generators/" + name))) + .simpleGeneratorMachineRenderer(GTCEu.id("block/generators/" + name)) .tooltips(workableTiered(tier, GTValues.V[tier], GTValues.V[tier] * 64, recipeType, tankScalingFunction.apply(tier), false)) .register(), diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java index a5702a4c06..081bec23c3 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/GregTechKubeJSPlugin.java @@ -45,6 +45,7 @@ import com.gregtechceu.gtceu.api.recipe.OverclockingLogic; import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.recipe.chance.logic.ChanceLogic; +import com.gregtechceu.gtceu.api.recipe.modifier.ModifierFunction; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.registry.registrate.MultiblockMachineBuilder; import com.gregtechceu.gtceu.common.data.*; @@ -59,6 +60,7 @@ import com.gregtechceu.gtceu.integration.kjs.builders.machine.*; import com.gregtechceu.gtceu.integration.kjs.builders.prefix.BasicTagPrefixBuilder; import com.gregtechceu.gtceu.integration.kjs.builders.prefix.OreTagPrefixBuilder; +import com.gregtechceu.gtceu.integration.kjs.helpers.MachineModifiers; import com.gregtechceu.gtceu.integration.kjs.helpers.MaterialStackWrapper; import com.gregtechceu.gtceu.integration.kjs.recipe.GTRecipeSchema; import com.gregtechceu.gtceu.integration.kjs.recipe.components.ExtendedOutputItem; @@ -280,6 +282,8 @@ public void registerBindings(BindingsEvent event) { event.add("GTOres", GTOres.class); event.add("GTRecipeModifiers", GTRecipeModifiers.class); event.add("OverclockingLogic", OverclockingLogic.class); + event.add("ModifierFunction", ModifierFunction.class); + event.add("MachineModifiers", MachineModifiers.class); event.add("GTWorldGenLayers", WorldGenLayers.class); } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java index d09e1d178a..23e9258deb 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/GTRecipeCategoryBuilder.java @@ -4,6 +4,7 @@ import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory; import com.gregtechceu.gtceu.api.registry.registrate.BuilderBase; import com.gregtechceu.gtceu.common.data.GTRecipeCategories; +import com.gregtechceu.gtceu.utils.FormattingUtil; import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; import com.lowdragmc.lowdraglib.gui.texture.ItemStackTexture; @@ -12,12 +13,22 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import dev.latvian.mods.kubejs.client.LangEventJS; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Accessors(chain = true, fluent = true) public class GTRecipeCategoryBuilder extends BuilderBase { - public transient String name; - public transient GTRecipeType recipeType; + private final transient String name; + @Setter + private transient GTRecipeType recipeType; + @Setter private transient IGuiTexture icon; + @Setter private transient boolean isXEIVisible; + @Setter + private transient String langValue; public GTRecipeCategoryBuilder(ResourceLocation id) { super(id); @@ -25,16 +36,7 @@ public GTRecipeCategoryBuilder(ResourceLocation id) { recipeType = null; icon = null; isXEIVisible = true; - } - - public GTRecipeCategoryBuilder recipeType(GTRecipeType recipeType) { - this.recipeType = recipeType; - return this; - } - - public GTRecipeCategoryBuilder setIcon(IGuiTexture guiTexture) { - this.icon = guiTexture; - return this; + langValue = null; } public GTRecipeCategoryBuilder setCustomIcon(ResourceLocation location) { @@ -47,9 +49,11 @@ public GTRecipeCategoryBuilder setItemIcon(ItemStack... stacks) { return this; } - public GTRecipeCategoryBuilder isXEIVisible(boolean flag) { - this.isXEIVisible = flag; - return this; + @Override + public void generateLang(LangEventJS lang) { + super.generateLang(lang); + if (langValue != null) lang.add(value.getLanguageKey(), langValue); + else lang.add(value.getLanguageKey(), FormattingUtil.toEnglishName(value.name)); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSSteamMachineBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSSteamMachineBuilder.java index ef856e831d..2a10eeac32 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSSteamMachineBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSSteamMachineBuilder.java @@ -12,6 +12,7 @@ import net.minecraft.resources.ResourceLocation; +import dev.latvian.mods.kubejs.client.LangEventJS; import lombok.Setter; import lombok.experimental.Accessors; @@ -24,6 +25,7 @@ public class KJSSteamMachineBuilder extends BuilderBase { public volatile SteamCreationFunction machine = SimpleSteamMachine::new; @Setter public volatile SteamDefinitionFunction definition = (isHP, def) -> def.tier(isHP ? 1 : 0); + private volatile MachineDefinition hp = null; public KJSSteamMachineBuilder(ResourceLocation id) { super(id); @@ -43,19 +45,28 @@ public MachineDefinition register() { if (hasHighPressure) { MachineBuilder highPressureBuilder = GTRegistration.REGISTRATE.machine( - String.format("lp_%s", this.id.getPath()), + String.format("hp_%s", this.id.getPath()), holder -> machine.create(holder, true)); highPressureBuilder.langValue("High Pressure " + FormattingUtil.toEnglishName(this.id.getPath())) .tier(1) .recipeModifier(SimpleSteamMachine::recipeModifier) .renderer(() -> new WorkableSteamMachineRenderer(true, id.withPrefix("block/machines/"))); definition.apply(true, highPressureBuilder); - var highPressure = highPressureBuilder.register(); + hp = highPressureBuilder.register(); } return value = lowPressure; } + @Override + public void generateLang(LangEventJS lang) { + super.generateLang(lang); + lang.add(value.getDescriptionId(), value.getLangValue()); + if (hp != null) { + lang.add(hp.getDescriptionId(), hp.getLangValue()); + } + } + @FunctionalInterface public interface SteamCreationFunction { diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMachineBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMachineBuilder.java index b7fed66ac4..d44104bc8d 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMachineBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMachineBuilder.java @@ -22,7 +22,9 @@ import java.util.Locale; import java.util.function.BiFunction; +import static com.gregtechceu.gtceu.api.GTValues.*; import static com.gregtechceu.gtceu.common.data.GTMachines.workableTiered; +import static com.gregtechceu.gtceu.utils.FormattingUtil.toEnglishName; @Accessors(fluent = true, chain = true) public class KJSTieredMachineBuilder extends BuilderBase { @@ -54,7 +56,8 @@ public KJSTieredMachineBuilder(ResourceLocation id, TieredCreationFunction machi @Override public void generateLang(LangEventJS lang) { super.generateLang(lang); - for (MachineDefinition def : this.value) { + for (int tier : tiers) { + MachineDefinition def = value[tier]; lang.add(def.getDescriptionId(), def.getLangValue()); } } @@ -67,14 +70,15 @@ public MachineDefinition[] register() { "example: `builder.machine((holder, tier) => new SimpleTieredMachine(holder, tier, t => t * 3200)`"); Preconditions.checkNotNull(definition, "You must set a definition function! " + "See GTMachines for examples"); - MachineDefinition[] definitions = new MachineDefinition[GTValues.TIER_COUNT]; + MachineDefinition[] definitions = new MachineDefinition[TIER_COUNT]; for (final int tier : tiers) { String tierName = GTValues.VN[tier].toLowerCase(Locale.ROOT); MachineBuilder builder = GTRegistration.REGISTRATE.machine( String.format("%s_%s", tierName, this.id.getPath()), holder -> machine.create(holder, tier, tankScalingFunction)); - builder.workableTieredHullRenderer(id.withPrefix("block/machines/")) + builder.langValue("%s %s %s".formatted(VLVH[tier], toEnglishName(this.id.getPath()), VLVT[tier])) + .workableTieredHullRenderer(id.withPrefix("block/machines/")) .tier(tier); this.definition.apply(tier, builder); if (builder.recipeTypes() != null && builder.recipeTypes().length > 0) { diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMultiblockBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMultiblockBuilder.java index a2905d0242..801652dc3e 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMultiblockBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSTieredMultiblockBuilder.java @@ -42,7 +42,8 @@ public KJSTieredMultiblockBuilder(ResourceLocation id, TieredCreationFunction ma @Override public void generateLang(LangEventJS lang) { super.generateLang(lang); - for (MachineDefinition def : this.value) { + for (int tier : tiers) { + MachineDefinition def = value[tier]; lang.add(def.getDescriptionId(), def.getLangValue()); } } diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMachineBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMachineBuilder.java index 864efe5b41..e891f7f70d 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMachineBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMachineBuilder.java @@ -5,6 +5,7 @@ import net.minecraft.resources.ResourceLocation; +import dev.latvian.mods.kubejs.client.LangEventJS; import dev.latvian.mods.rhino.util.HideFromJS; import it.unimi.dsi.fastutil.ints.Int2IntFunction; import lombok.Getter; @@ -47,6 +48,12 @@ public KJSWrappingMachineBuilder addDefaultTooltips(boolean addDefaultTooltips) return this; } + @Override + public void generateLang(LangEventJS lang) { + super.generateLang(lang); + tieredBuilder.generateLang(lang); + } + @Override public MachineDefinition register() { tieredBuilder.register(); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMultiblockBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMultiblockBuilder.java index eb1aef2ab6..c9b6c137cc 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMultiblockBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/builders/machine/KJSWrappingMultiblockBuilder.java @@ -12,6 +12,7 @@ import net.minecraft.resources.ResourceLocation; +import dev.latvian.mods.kubejs.client.LangEventJS; import dev.latvian.mods.rhino.util.HideFromJS; import lombok.Getter; @@ -43,6 +44,12 @@ public KJSWrappingMultiblockBuilder definition(KJSTieredMultiblockBuilder.Defini return this; } + @Override + public void generateLang(LangEventJS lang) { + super.generateLang(lang); + tieredBuilder.generateLang(lang); + } + @Override public MultiblockMachineDefinition register() { tieredBuilder.register(); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/kjs/helpers/MachineModifiers.java b/src/main/java/com/gregtechceu/gtceu/integration/kjs/helpers/MachineModifiers.java new file mode 100644 index 0000000000..e6cfc47aa0 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/kjs/helpers/MachineModifiers.java @@ -0,0 +1,28 @@ +package com.gregtechceu.gtceu.integration.kjs.helpers; + +import com.gregtechceu.gtceu.api.machine.SimpleGeneratorMachine; +import com.gregtechceu.gtceu.api.machine.steam.SimpleSteamMachine; +import com.gregtechceu.gtceu.api.machine.steam.SteamBoilerMachine; +import com.gregtechceu.gtceu.api.recipe.modifier.RecipeModifier; +import com.gregtechceu.gtceu.common.machine.multiblock.electric.FusionReactorMachine; +import com.gregtechceu.gtceu.common.machine.multiblock.generator.LargeCombustionEngineMachine; +import com.gregtechceu.gtceu.common.machine.multiblock.generator.LargeTurbineMachine; +import com.gregtechceu.gtceu.common.machine.multiblock.steam.LargeBoilerMachine; +import com.gregtechceu.gtceu.common.machine.multiblock.steam.SteamParallelMultiblockMachine; + +/** + * Collection of Recipe Modifiers for different machines + * Makes using them for KJS machines easier + */ +@SuppressWarnings("unused") +public final class MachineModifiers { + + public static RecipeModifier SIMPLE_STEAM = SimpleSteamMachine::recipeModifier; + public static RecipeModifier SIMPLE_GENERATOR = SimpleGeneratorMachine::recipeModifier; + public static RecipeModifier STEAM_BOILER = SteamBoilerMachine::recipeModifier; + public static RecipeModifier LARGE_BOILER = LargeBoilerMachine::recipeModifier; + public static RecipeModifier LARGE_TURBINE = LargeTurbineMachine::recipeModifier; + public static RecipeModifier LARGE_COMBUSTION_ENGINE = LargeCombustionEngineMachine::recipeModifier; + public static RecipeModifier STEAM_PARALLEL_MULTIBLOCK = SteamParallelMultiblockMachine::recipeModifier; + public static RecipeModifier FUSION_REACTOR = FusionReactorMachine::recipeModifier; +}