Skip to content

Commit

Permalink
Added SizedFluidIngredientComponent, attempted fixing mixin bug, fixe…
Browse files Browse the repository at this point in the history
…d some recipe component bugs
  • Loading branch information
LatvianModder committed Jun 17, 2024
1 parent f0efecb commit a32e2a7
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ dependencies {
modApi("dev.latvian.mods:rhino:$rhino_version") { transitive(false) }

// todo: reevaluate if we want to depend on jei
modCompileOnly("mezz.jei:jei-1.20.6-neoforge:$jei_version") { transitive(false) }
modCompileOnly("mezz.jei:jei-1.21-neoforge:$jei_version") { transitive(false) }
modCompileOnly("me.shedaniel:RoughlyEnoughItems-neoforge:$rei_version") { transitive(false) }
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ rei_version=16.0.729
#rei_comp_version=9.0.16
#forge_bookshelf_version=11.0.3
#forge_gamestages_version=7.+
jei_version=18.0.0.62
jei_version=19.0.0.1
61 changes: 32 additions & 29 deletions src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import dev.latvian.mods.kubejs.recipe.component.NestedRecipeComponent;
import dev.latvian.mods.kubejs.recipe.component.NumberComponent;
import dev.latvian.mods.kubejs.recipe.component.RegistryComponent;
import dev.latvian.mods.kubejs.recipe.component.SizedFluidIngredientComponent;
import dev.latvian.mods.kubejs.recipe.component.SizedIngredientComponent;
import dev.latvian.mods.kubejs.recipe.component.StringComponent;
import dev.latvian.mods.kubejs.recipe.component.TagKeyComponent;
Expand Down Expand Up @@ -562,52 +563,54 @@ public void registerRecipeFactories(RecipeFactoryRegistry registry) {

@Override
public void registerRecipeComponents(RecipeComponentFactoryRegistry registry) {
registry.register("boolean", BooleanComponent.BOOLEAN);
registry.register(BooleanComponent.BOOLEAN);
registry.register(StringComponent.ANY);
registry.register(StringComponent.NON_EMPTY);
registry.register(StringComponent.NON_BLANK);
registry.register(StringComponent.ID);
registry.register(CharacterComponent.CHARACTER);

registry.register("int", NumberComponent.INT_FACTORY);
registry.register("long", NumberComponent.LONG_FACTORY);
registry.register("float", NumberComponent.FLOAT_FACTORY);
registry.register("double", NumberComponent.DOUBLE_FACTORY);

registry.register("string", StringComponent.ANY);
registry.register("non_empty_string", StringComponent.NON_EMPTY);
registry.register("non_blank_string", StringComponent.NON_BLANK);
registry.register("id", StringComponent.ID);
registry.register("character", CharacterComponent.CHARACTER);
registry.register(IngredientComponent.INGREDIENT);
registry.register(IngredientComponent.NON_EMPTY_INGREDIENT);
registry.register(IngredientComponent.UNWRAPPED_INGREDIENT_LIST);

registry.register("ingredient", IngredientComponent.INGREDIENT);
registry.register("non_empty_ingredient", IngredientComponent.NON_EMPTY_INGREDIENT);
registry.register("unwrapped_ingredient_list", IngredientComponent.UNWRAPPED_INGREDIENT_LIST);
registry.register(SizedIngredientComponent.FLAT);
registry.register(SizedIngredientComponent.NESTED);

registry.register("flat_sized_ingredient", SizedIngredientComponent.FLAT);
registry.register("nested_sized_ingredient", SizedIngredientComponent.NESTED);
registry.register(ItemStackComponent.ITEM_STACK);
registry.register(ItemStackComponent.STRICT_ITEM_STACK);

registry.register("item_stack", ItemStackComponent.ITEM_STACK);
registry.register("strict_item_stack", ItemStackComponent.STRICT_ITEM_STACK);
registry.register(FluidStackComponent.FLUID_STACK);
registry.register(FluidIngredientComponent.FLUID_INGREDIENT);

registry.register("fluid_stack", FluidStackComponent.FLUID_STACK);
registry.register("fluid_ingredient", FluidIngredientComponent.FLUID_INGREDIENT);
registry.register(SizedFluidIngredientComponent.FLAT);
registry.register(SizedFluidIngredientComponent.NESTED);

registry.register("block", BlockComponent.BLOCK);
registry.register(BlockComponent.BLOCK);

registry.register("block_state", BlockStateComponent.BLOCK);
registry.register("block_state_string", BlockStateComponent.BLOCK_STRING);
registry.register(BlockStateComponent.BLOCK);
registry.register(BlockStateComponent.BLOCK_STRING);

registry.register("ticks", TimeComponent.TICKS);
registry.register("seconds", TimeComponent.SECONDS);
registry.register("minutes", TimeComponent.MINUTES);
registry.register("hours", TimeComponent.HOURS);
registry.register(TimeComponent.TICKS);
registry.register(TimeComponent.SECONDS);
registry.register(TimeComponent.MINUTES);
registry.register(TimeComponent.HOURS);

registry.register("block_tag", TagKeyComponent.BLOCK);
registry.register("item_tag", TagKeyComponent.ITEM);
registry.register("fluid_tag", TagKeyComponent.FLUID);
registry.register("entity_type_tag", TagKeyComponent.ENTITY_TYPE);
registry.register("biome_tag", TagKeyComponent.BIOME);
registry.register("tag", TagKeyComponent.FACTORY);
registry.register(TagKeyComponent.BLOCK);
registry.register(TagKeyComponent.ITEM);
registry.register(TagKeyComponent.FLUID);
registry.register(TagKeyComponent.ENTITY_TYPE);
registry.register(TagKeyComponent.BIOME);
registry.register(NestedRecipeComponent.RECIPE);

registry.register("tag", TagKeyComponent.FACTORY);
registry.register("registry_element", RegistryComponent.FACTORY);
registry.register("enum", EnumComponent.FACTORY);
registry.register("nested_recipe", NestedRecipeComponent.RECIPE);
registry.register("map", MapRecipeComponent.FACTORY);
registry.register("pattern", MapRecipeComponent.PATTERN_FACTORY);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.latvian.mods.kubejs.core.mixin;

import dev.latvian.mods.kubejs.core.BlockKJS;
import dev.latvian.mods.rhino.util.RemapPrefixForJS;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
Expand All @@ -13,7 +14,7 @@

@Mixin(Block.class)
@RemapPrefixForJS("kjs$")
public abstract class BlockMixin extends BlockBehaviourMixin {
public abstract class BlockMixin extends BlockBehaviourMixin implements BlockKJS {
@Shadow
@Final
private Holder.Reference<Block> builtInRegistryHolder;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/fluid/FluidWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.fluids.crafting.EmptyFluidIngredient;
import net.neoforged.neoforge.fluids.crafting.FluidIngredient;
import net.neoforged.neoforge.fluids.crafting.SizedFluidIngredient;

import java.util.ArrayList;
import java.util.List;

public interface FluidWrapper {
TypeInfo TYPE_INFO = TypeInfo.of(FluidStack.class);
TypeInfo INGREDIENT_TYPE_INFO = TypeInfo.of(FluidIngredient.class);
TypeInfo SIZED_INGREDIENT_TYPE_INFO = TypeInfo.of(SizedFluidIngredient.class);

static FluidStack wrap(RegistryAccessContainer registries, Object o) {
if (o == null || o == FluidStack.EMPTY || o == Fluids.EMPTY || o == EmptyFluidIngredient.INSTANCE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.crafting.FluidIngredient;
import net.neoforged.neoforge.fluids.crafting.SizedFluidIngredient;
import org.jetbrains.annotations.Nullable;

public class FluidIngredientComponent implements RecipeComponent<FluidIngredient> {
Expand All @@ -29,7 +30,7 @@ public TypeInfo typeInfo() {

@Override
public boolean hasPriority(Context cx, KubeRecipe recipe, Object from) {
return from instanceof FluidIngredient || from instanceof FluidStack || from instanceof Fluid;
return from instanceof SizedFluidIngredient || from instanceof FluidIngredient || from instanceof FluidStack || from instanceof Fluid;
}

@Override
Expand All @@ -54,6 +55,6 @@ public String createUniqueId(FluidIngredient value) {

@Override
public String toString() {
return "fluid_stack";
return "fluid_ingredient";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import dev.latvian.mods.rhino.type.TypeInfo;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.crafting.FluidIngredient;
import net.neoforged.neoforge.fluids.crafting.SizedFluidIngredient;
import org.jetbrains.annotations.Nullable;

public class FluidStackComponent implements RecipeComponent<FluidStack> {
Expand All @@ -28,7 +30,7 @@ public TypeInfo typeInfo() {

@Override
public boolean hasPriority(Context cx, KubeRecipe recipe, Object from) {
return from instanceof FluidStack || from instanceof Fluid;
return from instanceof SizedFluidIngredient || from instanceof FluidIngredient || from instanceof FluidStack || from instanceof Fluid;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class IngredientComponent implements RecipeComponent<Ingredient> {
public static final IngredientComponent INGREDIENT = new IngredientComponent("ingredient", Ingredient.CODEC);
public static final IngredientComponent NON_EMPTY_INGREDIENT = new IngredientComponent("ingredient", Ingredient.CODEC_NONEMPTY);
public static final IngredientComponent NON_EMPTY_INGREDIENT = new IngredientComponent("non_empty_ingredient", Ingredient.CODEC_NONEMPTY);

public static final RecipeComponent<List<Ingredient>> UNWRAPPED_INGREDIENT_LIST = new RecipeComponentWithParent<>() {
private static final TypeInfo WRAP_TYPE = TypeInfo.RAW_LIST.withParams(TypeInfo.of(SizedIngredient.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.latvian.mods.kubejs.recipe.component;

import com.mojang.serialization.Codec;
import dev.latvian.mods.kubejs.fluid.FluidLike;
import dev.latvian.mods.kubejs.fluid.FluidWrapper;
import dev.latvian.mods.kubejs.recipe.KubeRecipe;
import dev.latvian.mods.kubejs.recipe.RecipeKey;
import dev.latvian.mods.kubejs.recipe.ReplacementMatch;
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchema;
import dev.latvian.mods.rhino.Context;
import dev.latvian.mods.rhino.type.TypeInfo;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.crafting.FluidIngredient;
import net.neoforged.neoforge.fluids.crafting.SizedFluidIngredient;
import org.jetbrains.annotations.Nullable;

public class SizedFluidIngredientComponent implements RecipeComponent<SizedFluidIngredient> {
public static final SizedFluidIngredientComponent FLAT = new SizedFluidIngredientComponent("flat_sized_fluid_ingredient", SizedFluidIngredient.FLAT_CODEC);
public static final SizedFluidIngredientComponent NESTED = new SizedFluidIngredientComponent("nested_sized_fluid_ingredient", SizedFluidIngredient.NESTED_CODEC);

public final String name;
public final Codec<SizedFluidIngredient> codec;

public SizedFluidIngredientComponent(String name, Codec<SizedFluidIngredient> codec) {
this.name = name;
this.codec = codec;
}

@Override
public Codec<SizedFluidIngredient> codec() {
return codec;
}

@Override
public TypeInfo typeInfo() {
return FluidWrapper.SIZED_INGREDIENT_TYPE_INFO;
}

@Override
public boolean hasPriority(Context cx, KubeRecipe recipe, Object from) {
return from instanceof SizedFluidIngredient || from instanceof FluidIngredient || from instanceof FluidStack || from instanceof Fluid;
}

@Override
public boolean matches(KubeRecipe recipe, SizedFluidIngredient value, ReplacementMatch match) {
return match instanceof FluidLike m && m.contains((FluidLike) value.ingredient());
}

@Override
public String checkEmpty(RecipeKey<SizedFluidIngredient> key, SizedFluidIngredient value) {
if (value.ingredient().isEmpty()) {
return "SizedIngredient '" + key.name + "' can't be empty!";
}

return "";
}

@Override
@Nullable
public String createUniqueId(SizedFluidIngredient value) {
return value == null || value.ingredient().isEmpty() || value.ingredient().hasNoFluids() ? null : RecipeSchema.normalizeId(value.ingredient().getStacks()[0].getFluid().kjs$getId()).replace('/', '_');
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public RecipeComponentFactoryRegistry(RecipeSchemaStorage storage) {
this.storage = storage;
}

public void register(String name, RecipeComponent<?> component) {
storage.simpleComponents.put(name, component);
public void register(RecipeComponent<?> component) {
storage.simpleComponents.put(component.toString(), component);
}

public void register(String name, RecipeComponentFactory componentFactory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.latvian.mods.kubejs.util;

// TODO: Remove
public enum JSObjectType {
ANY,
MAP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public <T> T decodeJson(MapCodec<T> mapCodec, JsonElement from) {
public <T> T decode(Context cx, Codec<T> codec, Object o) {
if (o instanceof Tag tag) {
return codec.decode(nbt, tag).result().orElseThrow().getFirst();
} else if (o instanceof Map<?, ?> map) {
} else if (o instanceof Map<?, ?>) {
return codec.decode(java, o).result().orElseThrow().getFirst();
} else {
return codec.decode(json, MapJS.json(cx, o)).result().orElseThrow().getFirst();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static void queueIO(Runnable runnable) {
}
}

// TODO: Remove this garbage
@Nullable
public static Object wrap(@Nullable Object o, JSObjectType type) {
//Primitives and already normalized objects
Expand Down

0 comments on commit a32e2a7

Please sign in to comment.