Skip to content

Commit

Permalink
Fix Various KJS issues (GregTechCEu#2596)
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg authored and omergunr100 committed Dec 25, 2024
1 parent ca22ea6 commit 029f610
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public MachineBuilder<DEFINITION> workableTieredHullRenderer(ResourceLocation wo
return renderer(() -> new WorkableTieredHullMachineRenderer(tier, workableModel));
}

public MachineBuilder<DEFINITION> simpleGeneratorMachineRenderer(ResourceLocation workableModel) {
return renderer(() -> new SimpleGeneratorMachineRenderer(tier, workableModel));
}

public MachineBuilder<DEFINITION> workableSteamHullRenderer(boolean isHighPressure,
ResourceLocation workableModel) {
return renderer(() -> new WorkableSteamMachineRenderer(isHighPressure, workableModel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,29 +13,30 @@
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<GTRecipeCategory> {

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);
name = id.getPath();
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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import net.minecraft.resources.ResourceLocation;

import dev.latvian.mods.kubejs.client.LangEventJS;
import lombok.Setter;
import lombok.experimental.Accessors;

Expand All @@ -24,6 +25,7 @@ public class KJSSteamMachineBuilder extends BuilderBase<MachineDefinition> {
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);
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MachineDefinition[]> {
Expand Down Expand Up @@ -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());
}
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 029f610

Please sign in to comment.