Skip to content

Commit 6a002de

Browse files
add kjs$toFlatJson and kjs$toNestedJson for sized ingr types (NOTE: will be removed in 1.21.2+)
1 parent c9664e9 commit 6a002de

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/main/java/dev/latvian/mods/kubejs/core/FluidIngredientKJS.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package dev.latvian.mods.kubejs.core;
22

3+
import com.mojang.serialization.Codec;
34
import dev.latvian.mods.kubejs.error.KubeRuntimeException;
45
import dev.latvian.mods.kubejs.recipe.filter.RecipeMatchContext;
56
import dev.latvian.mods.kubejs.recipe.match.FluidMatch;
7+
import dev.latvian.mods.kubejs.util.WithCodec;
8+
import dev.latvian.mods.rhino.Context;
69
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
710
import net.neoforged.neoforge.fluids.FluidStack;
811
import net.neoforged.neoforge.fluids.crafting.FluidIngredient;
912

1013
@RemapPrefixForJS("kjs$")
11-
public interface FluidIngredientKJS extends FluidMatch {
14+
public interface FluidIngredientKJS extends WithCodec, FluidMatch {
15+
@Override
16+
default Codec<?> getCodec(Context cx) {
17+
return FluidIngredient.CODEC;
18+
}
19+
1220
@Override
1321
default boolean matches(RecipeMatchContext cx, FluidStack s, boolean exact) {
1422
return !s.isEmpty() && ((FluidIngredient) this).test(s);

src/main/java/dev/latvian/mods/kubejs/core/SizedFluidIngredientKJS.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.latvian.mods.kubejs.core;
22

3+
import com.google.gson.JsonElement;
4+
import dev.latvian.mods.kubejs.codec.KubeJSCodecs;
35
import dev.latvian.mods.kubejs.fluid.FluidWrapper;
46
import dev.latvian.mods.kubejs.recipe.RecipeScriptContext;
57
import dev.latvian.mods.kubejs.recipe.filter.RecipeMatchContext;
@@ -27,6 +29,14 @@ default Object replaceThisWith(RecipeScriptContext cx, Object with) {
2729
return this;
2830
}
2931

32+
default JsonElement kjs$toFlatJson() {
33+
return KubeJSCodecs.toJsonOrThrow(kjs$self(), SizedFluidIngredient.FLAT_CODEC);
34+
}
35+
36+
default JsonElement kjs$toNestedJson() {
37+
return KubeJSCodecs.toJsonOrThrow(kjs$self(), SizedFluidIngredient.NESTED_CODEC);
38+
}
39+
3040
@Override
3141
default boolean matches(RecipeMatchContext cx, FluidStack s, boolean exact) {
3242
return ((FluidMatch) kjs$self().ingredient()).matches(cx, s, exact);

src/main/java/dev/latvian/mods/kubejs/core/SizedIngredientKJS.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.latvian.mods.kubejs.core;
22

3+
import com.google.gson.JsonElement;
4+
import dev.latvian.mods.kubejs.codec.KubeJSCodecs;
35
import dev.latvian.mods.kubejs.plugin.builtin.wrapper.IngredientWrapper;
46
import dev.latvian.mods.kubejs.recipe.RecipeScriptContext;
57
import dev.latvian.mods.kubejs.recipe.filter.RecipeMatchContext;
@@ -39,4 +41,12 @@ default boolean matches(RecipeMatchContext cx, ItemStack item, boolean exact) {
3941
default boolean matches(RecipeMatchContext cx, Ingredient in, boolean exact) {
4042
return kjs$self().ingredient().matches(cx, in, exact);
4143
}
44+
45+
default JsonElement kjs$toFlatJson() {
46+
return KubeJSCodecs.toJsonOrThrow(kjs$self(), SizedIngredient.FLAT_CODEC);
47+
}
48+
49+
default JsonElement kjs$toNestedJson() {
50+
return KubeJSCodecs.toJsonOrThrow(kjs$self(), SizedIngredient.NESTED_CODEC);
51+
}
4252
}

0 commit comments

Comments
 (0)