Skip to content

Commit

Permalink
Fix ItemStackFromIngredient always having empty tags
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed May 28, 2024
1 parent 6b6b4cf commit ed0106f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.fluids.FluidStack;
import org.apache.commons.lang3.tuple.Pair;
import org.cyclops.cyclopscore.item.IngredientPublicConstructor;
import org.cyclops.cyclopscore.recipe.ItemStackFromIngredient;

import java.util.Collections;
Expand All @@ -36,6 +37,7 @@
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
* Helpers related to recipe serialization.
Expand Down Expand Up @@ -83,7 +85,7 @@ public static Codec<ItemStackFromIngredient> getCodecItemStackFromIngredient(Sup
Codec.STRING.fieldOf("tag").forGetter(ItemStackFromIngredient::getTag),
ExtraCodecs.strictOptionalField(Codec.INT, "count").forGetter(i -> Optional.of(i.getCount()))
)
.apply(builder, (tag, count) -> new ItemStackFromIngredient(modPriorities.get(), tag, Ingredient.of(TagKey.create(Registries.ITEM, new ResourceLocation(tag))), count.orElse(1)))
.apply(builder, (tag, count) -> new ItemStackFromIngredient(modPriorities.get(), tag, new IngredientPublicConstructor(Stream.of(new Ingredient.TagValue(TagKey.create(Registries.ITEM, new ResourceLocation(tag))))), count.orElse(1)))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cyclops.cyclopscore.item;

import net.minecraft.world.item.crafting.Ingredient;
import net.neoforged.neoforge.common.crafting.IngredientType;

import java.util.function.Supplier;
import java.util.stream.Stream;

/**
* An {@link Ingredient} with public constructors.
* This is needed for ingredients that are created before tags are initialized,
* and for which we need to skip the isEmpty check in fromValues.
* @author rubensworks
*/
public class IngredientPublicConstructor extends Ingredient {
public IngredientPublicConstructor(Stream<? extends Value> p_43907_) {
super(p_43907_);
}

public IngredientPublicConstructor(Stream<? extends Value> p_43907_, Supplier<? extends IngredientType<?>> type) {
super(p_43907_, type);
}
}

0 comments on commit ed0106f

Please sign in to comment.