Skip to content

Commit a7bab49

Browse files
committed
Update KubeJS support
This git commit adds support for KubeJS 2101.7.2-build.246 This does break compatibility with older versions As such; this should only be committed to the main branch once KubeJS releases a new version
1 parent d1f7194 commit a7bab49

File tree

9 files changed

+98
-45
lines changed

9 files changed

+98
-45
lines changed

gradle/forge.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jei = "19.21.0.247"
77
rei = "16.0.799"
88
emi = "1.1.21+1.21.1"
99
ae2 = "19.2.8"
10-
kubejs = "2101.7.1-build.181"
10+
kubejs = "2101.7.2-build.246"
1111
rhino = "2101.2.7-build.74"
1212
architectury = "13.0.8"
1313
clothconfig = "15.0.140"

src/main/java/com/gregtechceu/gtceu/data/recipe/GTRecipes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import net.minecraft.world.item.crafting.Recipe;
2020
import net.neoforged.neoforge.common.conditions.ICondition;
2121

22-
import dev.latvian.mods.kubejs.bindings.event.ServerEvents;
22+
import dev.latvian.mods.kubejs.plugin.builtin.event.ServerEvents;
2323
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
2424
import org.jetbrains.annotations.NotNull;
2525
import org.jetbrains.annotations.Nullable;

src/main/java/com/gregtechceu/gtceu/integration/kjs/GTKubeJSPlugin.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
import dev.latvian.mods.kubejs.event.EventGroupRegistry;
116116
import dev.latvian.mods.kubejs.plugin.ClassFilter;
117117
import dev.latvian.mods.kubejs.plugin.KubeJSPlugin;
118-
import dev.latvian.mods.kubejs.recipe.schema.RecipeComponentFactoryRegistry;
118+
import dev.latvian.mods.kubejs.recipe.component.RecipeComponentTypeRegistry;
119119
import dev.latvian.mods.kubejs.recipe.schema.RecipeFactoryRegistry;
120120
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchemaRegistry;
121121
import dev.latvian.mods.kubejs.registry.BuilderTypeRegistry;
@@ -162,7 +162,7 @@ public void registerBuilderTypes(BuilderTypeRegistry registry) {
162162
registry.addDefault(GTRegistries.MATERIAL_REGISTRY, MaterialBuilderWrapper.class, MaterialBuilderWrapper::new);
163163
registry.of(GTRegistries.TAG_PREFIX_REGISTRY, reg -> {
164164
reg.addDefault(TagPrefixBuilder.class, TagPrefixBuilder::new);
165-
reg.add("ore", OreTagPrefixBuilder.class, OreTagPrefixBuilder::new);
165+
reg.add(ResourceLocation.parse("ore"), OreTagPrefixBuilder.class, OreTagPrefixBuilder::new);
166166
});
167167

168168
registry.addDefault(GTRegistries.RECIPE_TYPE_REGISTRY, GTRecipeTypeBuilder.class, GTRecipeTypeBuilder::new);
@@ -175,24 +175,25 @@ public void registerBuilderTypes(BuilderTypeRegistry registry) {
175175
new KJSTieredMachineBuilder(id, SimpleTieredMachine::new,
176176
SimpleTieredMachine.EDITABLE_UI_CREATOR, false)));
177177

178-
reg.add("custom", KJSWrappingMachineBuilder.class,
178+
reg.add(ResourceLocation.parse("custom"), KJSWrappingMachineBuilder.class,
179179
(id) -> new KJSWrappingMachineBuilder(id, new KJSTieredMachineBuilder(id)));
180-
reg.add("steam", KJSSteamMachineBuilder.class, KJSSteamMachineBuilder::new);
181-
reg.add("generator", KJSWrappingMachineBuilder.class,
180+
reg.add(ResourceLocation.parse("steam"), KJSSteamMachineBuilder.class, KJSSteamMachineBuilder::new);
181+
reg.add(ResourceLocation.parse("generator"), KJSWrappingMachineBuilder.class,
182182
(id) -> new KJSWrappingMachineBuilder(id,
183183
new KJSTieredMachineBuilder(id, SimpleGeneratorMachine::new,
184184
SimpleGeneratorMachine.EDITABLE_UI_CREATOR, true)));
185185

186-
reg.add("multiblock", MultiblockMachineBuilderWrapper.class,
186+
reg.add(ResourceLocation.parse("multiblock"), MultiblockMachineBuilderWrapper.class,
187187
MultiblockMachineBuilderWrapper::createKJSMulti);
188-
reg.add("tiered_multiblock", KJSWrappingMultiblockBuilder.class, KJSWrappingMultiblockBuilder::new);
189-
reg.add("primitive", MultiblockMachineBuilderWrapper.class,
188+
reg.add(ResourceLocation.parse("tiered_multiblock"), KJSWrappingMultiblockBuilder.class,
189+
KJSWrappingMultiblockBuilder::new);
190+
reg.add(ResourceLocation.parse("primitive"), MultiblockMachineBuilderWrapper.class,
190191
(id) -> MultiblockMachineBuilderWrapper.createKJSMulti(id, PrimitiveFancyUIWorkableMachine::new));
191192
});
192193

193194
registry.of(Registries.BLOCK, reg -> {
194-
reg.add("gtceu:active", ActiveBlockBuilder.class, ActiveBlockBuilder::new);
195-
reg.add("gtceu:coil", CoilBlockBuilder.class, CoilBlockBuilder::new);
195+
reg.add(ResourceLocation.parse("gtceu:active"), ActiveBlockBuilder.class, ActiveBlockBuilder::new);
196+
reg.add(ResourceLocation.parse("gtceu:coil"), CoilBlockBuilder.class, CoilBlockBuilder::new);
196197
});
197198

198199
registry.addDefault(GTRegistries.ORE_VEIN_REGISTRY, OreVeinDefinitionBuilder.class,
@@ -262,17 +263,17 @@ public void registerRecipeFactories(RecipeFactoryRegistry registry) {
262263
}
263264

264265
@Override
265-
public void registerRecipeComponents(RecipeComponentFactoryRegistry registry) {
266-
registry.register(GTRecipeComponents.TAG);
267-
registry.register(GTRecipeComponents.RECIPE_CONDITION);
268-
registry.register(GTRecipeComponents.RESOURCE_LOCATION);
269-
registry.register(GTRecipeComponents.RECIPE_CAPABILITY);
270-
registry.register(GTRecipeComponents.CHANCE_LOGIC);
271-
registry.register(CapabilityMapComponent.INSTANCE);
272-
273-
registry.register(GTRecipeComponents.ITEM);
274-
registry.register(GTRecipeComponents.FLUID);
275-
registry.register(GTRecipeComponents.EU);
266+
public void registerRecipeComponents(RecipeComponentTypeRegistry registry) {
267+
registry.register(GTRecipeComponents.TAG.type());
268+
registry.register(GTRecipeComponents.RECIPE_CONDITION.type());
269+
registry.register(GTRecipeComponents.RESOURCE_LOCATION.type());
270+
registry.register(GTRecipeComponents.RECIPE_CAPABILITY.type());
271+
registry.register(GTRecipeComponents.CHANCE_LOGIC.type());
272+
registry.register(CapabilityMapComponent.INSTANCE.type());
273+
274+
registry.register(GTRecipeComponents.ITEM.type());
275+
registry.register(GTRecipeComponents.FLUID.type());
276+
registry.register(GTRecipeComponents.EU.type());
276277
}
277278

278279
@Override
@@ -459,7 +460,7 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) {
459460

460461
registry.register(IWorldGenLayer.RuleTestSupplier.class, (cx, o, t) -> {
461462
if (o instanceof IWorldGenLayer.RuleTestSupplier supplier) return supplier;
462-
return () -> BlockStatePredicate.ruleTestOf(cx, o);
463+
return () -> BlockStatePredicate.wrapRuleTest(cx, o);
463464
});
464465
registry.register(CraftingComponent.class, o -> {
465466
if (o instanceof CraftingComponent comp) return comp;

src/main/java/com/gregtechceu/gtceu/integration/kjs/events/CraftingComponentsKubeEvent.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
import net.minecraft.world.item.ItemStack;
1515

1616
import dev.latvian.mods.kubejs.event.KubeStartupEvent;
17-
import dev.latvian.mods.kubejs.item.ItemStackJS;
1817
import dev.latvian.mods.kubejs.script.ConsoleJS;
1918
import dev.latvian.mods.kubejs.util.ID;
20-
import dev.latvian.mods.kubejs.util.RegistryAccessContainer;
2119
import dev.latvian.mods.rhino.Context;
2220
import lombok.NoArgsConstructor;
2321
import org.jetbrains.annotations.NotNull;
@@ -135,9 +133,12 @@ public void removeTiers(CraftingComponent craftingComponent, int... tiers) {
135133
}
136134

137135
private static ItemStack parseItemStack(Context cx, Object o) {
138-
ItemStack stack = ItemStackJS.wrap(RegistryAccessContainer.of(cx), o);
139-
if (stack == null || stack.isEmpty()) return null;
140-
return stack;
136+
if (o instanceof ItemStack) {
137+
ItemStack stack = (ItemStack) o;
138+
if (stack == null || stack.isEmpty()) return null;
139+
return stack;
140+
}
141+
return null;
141142
}
142143

143144
@SuppressWarnings("unchecked")

src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/GTShapedRecipeSchema.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchemaFunction;
2020
import dev.latvian.mods.kubejs.recipe.special.KubeJSCraftingRecipe;
2121
import dev.latvian.mods.kubejs.script.ConsoleJS;
22+
import dev.latvian.mods.kubejs.util.ErrorStack;
2223
import dev.latvian.mods.kubejs.util.TinyMap;
2324
import dev.latvian.mods.rhino.util.HideFromJS;
2425
import it.unimi.dsi.fastutil.chars.CharArrayList;
@@ -52,8 +53,8 @@ public List<IngredientActionHolder> getIngredientActions() {
5253

5354
// Adapted from KJS's ShapedRecipeSchema#ShapedKubeRecipe
5455
@Override
55-
public void afterLoaded() {
56-
super.afterLoaded();
56+
public void afterLoaded(ErrorStack stack) {
57+
super.afterLoaded(stack);
5758
var pattern = new ArrayList<>(getValue(PATTERN));
5859
var key = getValue(KEY);
5960

@@ -120,9 +121,9 @@ public RecipeTypeFunction getSerializationTypeFunction() {
120121
// spotless:off
121122
KubeRecipeFactory RECIPE_FACTORY = new KubeRecipeFactory(GTCEu.id("shaped"), ShapedKubeRecipe.class, ShapedKubeRecipe::new);
122123

123-
RecipeKey<ItemStack> RESULT = ItemStackComponent.STRICT_ITEM_STACK.outputKey("result");
124+
RecipeKey<ItemStack> RESULT = ItemStackComponent.ITEM_STACK.outputKey("result");
124125
RecipeKey<List<String>> PATTERN = StringGridComponent.STRING_GRID.otherKey("pattern");
125-
RecipeKey<TinyMap<Character, Ingredient>> KEY = IngredientComponent.INGREDIENT.asPatternKey().inputKey("key");
126+
RecipeKey<TinyMap<Character, Ingredient>> KEY = IngredientComponent.INGREDIENT.instance().asPatternKey().inputKey("key");
126127
RecipeKey<Boolean> MIRROR = BooleanComponent.BOOLEAN.otherKey(KubeJSCraftingRecipe.MIRROR_KEY).optional(true).exclude()
127128
.functionNames(List.of("kjsMirror"));
128129
RecipeKey<Boolean> SHRINK = BooleanComponent.BOOLEAN.otherKey("kubejs:shrink").optional(true).exclude()

src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/CapabilityMapComponent.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import com.gregtechceu.gtceu.api.capability.recipe.RecipeCapability;
44
import com.gregtechceu.gtceu.api.recipe.content.Content;
55

6+
import net.minecraft.resources.ResourceLocation;
7+
68
import com.mojang.serialization.Codec;
79
import dev.latvian.mods.kubejs.recipe.KubeRecipe;
810
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
11+
import dev.latvian.mods.kubejs.recipe.component.RecipeComponentType;
912
import dev.latvian.mods.kubejs.recipe.match.ReplacementMatchInfo;
1013
import dev.latvian.mods.rhino.Context;
1114
import dev.latvian.mods.rhino.type.TypeInfo;
@@ -51,4 +54,8 @@ public CapabilityMap replace(Context cx, KubeRecipe recipe, CapabilityMap origin
5154
});
5255
return changed.get() ? new CapabilityMap(original) : original;
5356
}
57+
58+
public @Override RecipeComponentType<CapabilityMap> type() {
59+
return RecipeComponentType.<CapabilityMap>unit(ResourceLocation.parse("capability_map"), this);
60+
}
5461
}

src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/ContentJS.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
import com.mojang.serialization.Codec;
77
import dev.latvian.mods.kubejs.recipe.KubeRecipe;
88
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
9+
import dev.latvian.mods.kubejs.recipe.component.RecipeComponentType;
910
import dev.latvian.mods.kubejs.recipe.match.ReplacementMatchInfo;
1011
import dev.latvian.mods.rhino.Context;
1112
import dev.latvian.mods.rhino.type.TypeInfo;
1213

13-
public record ContentJS<T>(RecipeComponent<T> baseComponent, RecipeCapability<?> capability)
14+
public record ContentJS<T>(RecipeComponentType<T> baseComponent, RecipeCapability<?> capability)
1415
implements RecipeComponent<Content> {
1516

16-
public static <T> ContentJS<T> create(RecipeComponent<T> baseComponent, RecipeCapability<?> capability) {
17+
public static <T> ContentJS<T> create(RecipeComponentType<T> baseComponent, RecipeCapability<?> capability) {
1718
return new ContentJS<>(baseComponent, capability);
1819
}
1920

@@ -30,12 +31,18 @@ public TypeInfo typeInfo() {
3031
@Override
3132
public Content replace(Context cx, KubeRecipe recipe, Content original, ReplacementMatchInfo match, Object with) {
3233
return new Content(
33-
baseComponent.replace(cx, recipe, baseComponent.wrap(cx, recipe, original.content), match, with),
34+
baseComponent.instance().replace(cx, recipe,
35+
baseComponent.instance().wrap(cx, recipe, original.content), match, with),
3436
original.chance, original.maxChance, original.tierChanceBoost);
3537
}
3638

3739
@Override
3840
public String toString() {
3941
return baseComponent.toString() + "_content";
4042
}
43+
44+
@Override
45+
public RecipeComponentType<?> type() {
46+
return baseComponent;
47+
}
4148
}

src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/GTRecipeComponents.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616

1717
import com.mojang.serialization.Codec;
1818
import dev.latvian.mods.kubejs.recipe.component.*;
19-
import dev.latvian.mods.kubejs.recipe.component.RecipeComponent;
2019
import dev.latvian.mods.rhino.type.TypeInfo;
2120

2221
import java.util.*;
2322

2423
public class GTRecipeComponents {
2524

26-
public static final RecipeComponent<CompoundTag> TAG = new RecipeComponent<>() {
25+
public static final RecipeComponent<CompoundTag> TAG = new RecipeComponent<CompoundTag>() {
2726

2827
@Override
2928
public Codec<CompoundTag> codec() {
@@ -39,8 +38,13 @@ public TypeInfo typeInfo() {
3938
public String toString() {
4039
return "tag";
4140
}
41+
42+
@Override
43+
public RecipeComponentType<CompoundTag> type() {
44+
return RecipeComponentType.<CompoundTag>unit(ResourceLocation.parse("tag"), this);
45+
}
4246
};
43-
public static final RecipeComponent<ResourceLocation> RESOURCE_LOCATION = new RecipeComponent<>() {
47+
public static final RecipeComponent<ResourceLocation> RESOURCE_LOCATION = new RecipeComponent<ResourceLocation>() {
4448

4549
@Override
4650
public Codec<ResourceLocation> codec() {
@@ -56,8 +60,13 @@ public TypeInfo typeInfo() {
5660
public String toString() {
5761
return "resource_location";
5862
}
63+
64+
@Override
65+
public RecipeComponentType<ResourceLocation> type() {
66+
return RecipeComponentType.<ResourceLocation>unit(ResourceLocation.parse("resource_location"), this);
67+
}
5968
};
60-
public static final RecipeComponent<RecipeCapability<?>> RECIPE_CAPABILITY = new RecipeComponent<>() {
69+
public static final RecipeComponent<RecipeCapability<?>> RECIPE_CAPABILITY = new RecipeComponent<RecipeCapability<?>>() {
6170

6271
@Override
6372
public Codec<RecipeCapability<?>> codec() {
@@ -73,8 +82,13 @@ public TypeInfo typeInfo() {
7382
public String toString() {
7483
return "recipe_capability";
7584
}
85+
86+
@Override
87+
public RecipeComponentType<RecipeCapability<?>> type() {
88+
return RecipeComponentType.<RecipeCapability<?>>unit(ResourceLocation.parse("recipe_capability"), this);
89+
}
7690
};
77-
public static final RecipeComponent<ChanceLogic> CHANCE_LOGIC = new RecipeComponent<>() {
91+
public static final RecipeComponent<ChanceLogic> CHANCE_LOGIC = new RecipeComponent<ChanceLogic>() {
7892

7993
@Override
8094
public Codec<ChanceLogic> codec() {
@@ -90,9 +104,14 @@ public TypeInfo typeInfo() {
90104
public String toString() {
91105
return "chance_logic";
92106
}
107+
108+
@Override
109+
public RecipeComponentType<ChanceLogic> type() {
110+
return RecipeComponentType.<ChanceLogic>unit(ResourceLocation.parse("chance_logic"), this);
111+
}
93112
};
94113

95-
public static final RecipeComponent<RecipeCondition<?>> RECIPE_CONDITION = new RecipeComponent<>() {
114+
public static final RecipeComponent<RecipeCondition<?>> RECIPE_CONDITION = new RecipeComponent<RecipeCondition<?>>() {
96115

97116
@Override
98117
public Codec<RecipeCondition<?>> codec() {
@@ -108,9 +127,14 @@ public TypeInfo typeInfo() {
108127
public String toString() {
109128
return "recipe_condition";
110129
}
130+
131+
@Override
132+
public RecipeComponentType<RecipeCondition<?>> type() {
133+
return RecipeComponentType.<RecipeCondition<?>>unit(ResourceLocation.parse("recipe_condition"), this);
134+
}
111135
};
112136

113-
public static final RecipeComponent<EnergyStack.WithIO> ENERGY_STACK = new RecipeComponent<>() {
137+
public static final RecipeComponent<EnergyStack.WithIO> ENERGY_STACK = new RecipeComponent<EnergyStack.WithIO>() {
114138

115139
@Override
116140
public Codec<EnergyStack.WithIO> codec() {
@@ -129,14 +153,20 @@ public TypeInfo typeInfo() {
129153
public String toString() {
130154
return "energy_stack";
131155
}
156+
157+
@Override
158+
public RecipeComponentType<EnergyStack.WithIO> type() {
159+
return RecipeComponentType.<EnergyStack.WithIO>unit(ResourceLocation.parse("energy_stack"), this);
160+
}
132161
};
133162

134163
public static final ContentJS<SizedIngredient> ITEM = ContentJS.create(SizedIngredientComponent.NESTED,
135164
GTRecipeCapabilities.ITEM);
136165
public static final ContentJS<SizedFluidIngredient> FLUID = ContentJS.create(SizedFluidIngredientComponent.NESTED,
137166
GTRecipeCapabilities.FLUID);
138-
public static final ContentJS<EnergyStack.WithIO> EU = ContentJS.create(ENERGY_STACK, GTRecipeCapabilities.EU);
139-
public static final ContentJS<Integer> CWU = ContentJS.create(NumberComponent.INT, GTRecipeCapabilities.CWU);
167+
public static final ContentJS<EnergyStack.WithIO> EU = ContentJS
168+
.create((RecipeComponentType<EnergyStack.WithIO>) ENERGY_STACK.type(), GTRecipeCapabilities.EU);
169+
public static final ContentJS<Integer> CWU = ContentJS.create(NumberComponent.INT_TYPE, GTRecipeCapabilities.CWU);
140170

141171
public static final RecipeComponent<Map<RecipeCapability<?>, ChanceLogic>> CHANCE_LOGIC_MAP = new JavaMapRecipeComponent<>(
142172
RECIPE_CAPABILITY, CHANCE_LOGIC);

src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/components/JavaMapRecipeComponent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.gregtechceu.gtceu.integration.kjs.recipe.components;
22

3+
import net.minecraft.resources.ResourceLocation;
4+
35
import com.mojang.serialization.Codec;
46
import dev.latvian.mods.kubejs.recipe.KubeRecipe;
57
import dev.latvian.mods.kubejs.recipe.component.*;
@@ -45,4 +47,8 @@ public Codec<Map<K, V>> codec() {
4547
public TypeInfo typeInfo() {
4648
return TypeInfo.RAW_MAP.withParams(key.typeInfo(), value.typeInfo());
4749
}
50+
51+
public @Override RecipeComponentType<Map<K, V>> type() {
52+
return RecipeComponentType.<Map<K, V>>unit(ResourceLocation.parse("java_map{" + key + ":" + value + "}"), this);
53+
}
4854
}

0 commit comments

Comments
 (0)