Skip to content

Commit

Permalink
Add multiblock constructors to KJS + lang (#2667)
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg authored Dec 29, 2024
1 parent 80ffd9c commit c2448cd
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gregtechceu.gtceu.api.registry.registrate;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.block.IMachineBlock;
import com.gregtechceu.gtceu.api.capability.recipe.RecipeCapability;
import com.gregtechceu.gtceu.api.data.RotationState;
Expand Down Expand Up @@ -42,6 +43,7 @@
import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.util.nullness.NonNullConsumer;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import dev.latvian.mods.kubejs.client.LangEventJS;
import dev.latvian.mods.rhino.util.HideFromJS;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.Getter;
Expand Down Expand Up @@ -376,6 +378,14 @@ public MultiblockMachineBuilder onBlockEntityRegister(NonNullConsumer<BlockEntit
return (MultiblockMachineBuilder) super.onBlockEntityRegister(onBlockEntityRegister);
}

@Override
public void generateLang(LangEventJS lang) {
super.generateLang(lang);
if (langValue() != null) {
lang.add(GTCEu.MOD_ID, value.getDescriptionId(), value.getLangValue());
}
}

@Override
@HideFromJS
public MultiblockMachineDefinition register() {
Expand All @@ -399,6 +409,6 @@ public MultiblockMachineDefinition register() {
}
definition.setPartAppearance(partAppearance);
definition.setAdditionalDisplay(additionalDisplay);
return definition;
return value = definition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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.MachineConstructors;
import com.gregtechceu.gtceu.integration.kjs.helpers.MachineModifiers;
import com.gregtechceu.gtceu.integration.kjs.helpers.MaterialStackWrapper;
import com.gregtechceu.gtceu.integration.kjs.recipe.GTRecipeSchema;
Expand Down Expand Up @@ -267,6 +268,7 @@ public void registerBindings(BindingsEvent event) {
event.add("GTMedicalConditions", GTMedicalConditions.class);
event.add("GTRecipeModifiers", GTRecipeModifiers.class);
event.add("OverclockingLogic", OverclockingLogic.class);
event.add("MachineConstructors", MachineConstructors.class);
event.add("MachineModifiers", MachineModifiers.class);
event.add("ModifierFunction", ModifierFunction.class);
event.add("RecipeCapability", RecipeCapability.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public MachineDefinition register() {
@Override
public void generateLang(LangEventJS lang) {
super.generateLang(lang);
lang.add(value.getDescriptionId(), value.getLangValue());
lang.add(GTCEu.MOD_ID, value.getDescriptionId(), value.getLangValue());
if (hp != null) {
lang.add(GTCEu.MOD_ID, hp.getDescriptionId(), hp.getLangValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public void generateLang(LangEventJS lang) {
super.generateLang(lang);
for (int tier : tiers) {
MachineDefinition def = value[tier];
lang.add(GTCEu.MOD_ID, def.getDescriptionId(), def.getLangValue());
if (def.getLangValue() != null) {
lang.add(GTCEu.MOD_ID, def.getDescriptionId(), def.getLangValue());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.gregtechceu.gtceu.integration.kjs.helpers;

import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.multiblock.MultiblockControllerMachine;
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.SteamParallelMultiblockMachine;

/**
* Collection of functions that can be used in the Machine Creation Functions in KJS definitions
* Makes using them for KJS easier, as loading the relevant class won't be required.
*/
@SuppressWarnings("unused")
public final class MachineConstructors {

// This one in particular stops a crash when trying to define a new LCE
// The crash is caused by the static FluidStack members in LargeCombustionEngine.class
public static MultiblockControllerMachine createLargeCombustionEngine(IMachineBlockEntity holder, int tier) {
return new LargeCombustionEngineMachine(holder, tier);
}

public static MultiblockControllerMachine createLargeTurbine(IMachineBlockEntity holder, int tier) {
return new LargeTurbineMachine(holder, tier);
}

public static MultiblockControllerMachine createFusionReactor(IMachineBlockEntity holder, int tier) {
return new FusionReactorMachine(holder, tier);
}

public static MultiblockControllerMachine createSteamMultiblock(IMachineBlockEntity holder, int parallels) {
return new SteamParallelMultiblockMachine(holder, parallels);
}
}

0 comments on commit c2448cd

Please sign in to comment.