Skip to content

Commit

Permalink
fix crafting recipe complaining about fluid stack size
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Oct 6, 2024
1 parent a0b95a0 commit d4047b4
Showing 1 changed file with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.IResourceStack;
import com.cleanroommc.groovyscript.api.documentation.annotations.Comp;
import com.cleanroommc.groovyscript.api.documentation.annotations.Property;
import com.cleanroommc.groovyscript.api.documentation.annotations.RecipeBuilderMethodDescription;
Expand All @@ -20,6 +19,7 @@
import it.unimi.dsi.fastutil.chars.CharOpenHashSet;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.Nullable;
Expand All @@ -31,13 +31,20 @@

public abstract class AbstractCraftingRecipeBuilder<R> {

@Property(value = "groovyscript.wiki.craftingrecipe.output.value", comp = @Comp(not = "null"), priority = 700, hierarchy = 20)
@Property(value = "groovyscript.wiki.craftingrecipe.output.value",
comp = @Comp(not = "null"),
priority = 700,
hierarchy = 20)
protected ItemStack output;
@Property(value = "groovyscript.wiki.name.value", priority = 100, hierarchy = 20)
protected ResourceLocation name;
@Property(value = "groovyscript.wiki.craftingrecipe.recipeFunction.value", priority = 1500, hierarchy = 20)
@Property(value = "groovyscript.wiki.craftingrecipe.recipeFunction.value",
priority = 1500,
hierarchy = 20)
protected Closure<ItemStack> recipeFunction;
@Property(value = "groovyscript.wiki.craftingrecipe.recipeAction.value", priority = 1550, hierarchy = 20)
@Property(value = "groovyscript.wiki.craftingrecipe.recipeAction.value",
priority = 1550,
hierarchy = 20)
protected Closure<Void> recipeAction;
@Property(value = "groovyscript.wiki.craftingrecipe.replace.value", needsOverride = true, hierarchy = 20)
protected byte replace;
Expand Down Expand Up @@ -113,9 +120,7 @@ protected void handleReplace() {
} else if (replace == 2) {
if (name == null) {
GroovyLog.msg("Error replacing Minecraft Crafting recipe")
.add("Name must not be null when replacing by name")
.error()
.post();
.add("Name must not be null when replacing by name").error().post();
return;
}
ReloadableRegistryManager.removeRegistryEntry(ForgeRegistries.RECIPES, name);
Expand All @@ -136,7 +141,8 @@ public void validateName() {

@GroovyBlacklist
@Nullable
protected <T> T validateShape(GroovyLog.Msg msg, List<String> errors, String[] keyBasedMatrix, Char2ObjectOpenHashMap<IIngredient> keyMap, IRecipeCreator<T> recipeCreator) {
protected <T> T validateShape(GroovyLog.Msg msg, List<String> errors, String[] keyBasedMatrix,
Char2ObjectOpenHashMap<IIngredient> keyMap, IRecipeCreator<T> recipeCreator) {
List<IIngredient> ingredients = new ArrayList<>();
if (keyBasedMatrix.length > height) {
msg.add("Defined matrix has %d rows, but should only have %d rows", keyBasedMatrix.length, height);
Expand Down Expand Up @@ -187,7 +193,9 @@ protected <T> T validateShape(GroovyLog.Msg msg, List<String> errors, String[] k
protected void checkStackSizes(GroovyLog.Msg msg, Collection<IIngredient> ingredients) {
if (GroovyScriptConfig.compat.checkInputStackCounts) {
for (IIngredient ingredient : ingredients) {
msg.add(IngredientHelper.overMaxSize(ingredient, 1), "Expected stack size 1 for {}, got {}", ingredient.toString(), ingredient.getAmount());
if (!(ingredient instanceof FluidStack)) {
msg.add(IngredientHelper.overMaxSize(ingredient, 1), "Expected stack size 1 for {}, got {}", ingredient.toString(), ingredient.getAmount());
}
}
}
}
Expand Down Expand Up @@ -226,14 +234,22 @@ public interface IRecipeCreator<T> {

public abstract static class AbstractShaped<T> extends AbstractCraftingRecipeBuilder<T> {

@Property(value = "groovyscript.wiki.craftingrecipe.keyMap.value", defaultValue = "' ' = IIngredient.EMPTY", priority = 210, hierarchy = 20)
@Property(value = "groovyscript.wiki.craftingrecipe.keyMap.value",
defaultValue = "' ' = IIngredient.EMPTY",
priority = 210,
hierarchy = 20)
protected final Char2ObjectOpenHashMap<IIngredient> keyMap = new Char2ObjectOpenHashMap<>();
protected final List<String> errors = new ArrayList<>();
@Property(value = "groovyscript.wiki.craftingrecipe.mirrored.value", hierarchy = 20)
protected boolean mirrored;
@Property(value = "groovyscript.wiki.craftingrecipe.keyBasedMatrix.value", comp = @Comp(unique = "groovyscript.wiki.craftingrecipe.matrix.required"), priority = 200, hierarchy = 20)
@Property(value = "groovyscript.wiki.craftingrecipe.mirrored.value", hierarchy = 20) protected boolean mirrored;
@Property(value = "groovyscript.wiki.craftingrecipe.keyBasedMatrix.value",
comp = @Comp(unique = "groovyscript.wiki.craftingrecipe.matrix.required"),
priority = 200,
hierarchy = 20)
protected String[] keyBasedMatrix;
@Property(value = "groovyscript.wiki.craftingrecipe.ingredientMatrix.value", comp = @Comp(gte = 1, lte = 9, unique = "groovyscript.wiki.craftingrecipe.matrix.required"), priority = 200, hierarchy = 20)
@Property(value = "groovyscript.wiki.craftingrecipe.ingredientMatrix.value",
comp = @Comp(gte = 1, lte = 9, unique = "groovyscript.wiki.craftingrecipe.matrix.required"),
priority = 200,
hierarchy = 20)
protected List<List<IIngredient>> ingredientMatrix;

public AbstractShaped(int width, int height) {
Expand Down Expand Up @@ -315,7 +331,9 @@ public AbstractShaped<T> shape(List<List<IIngredient>> matrix) {
public abstract static class AbstractShapeless<T> extends AbstractCraftingRecipeBuilder<T> {

@Property(value = "groovyscript.wiki.craftingrecipe.ingredients.value",
comp = @Comp(gte = 1, lte = 9), priority = 250, hierarchy = 20)
comp = @Comp(gte = 1, lte = 9),
priority = 250,
hierarchy = 20)
protected final List<IIngredient> ingredients = new ArrayList<>();

public AbstractShapeless(int width, int height) {
Expand All @@ -330,17 +348,21 @@ public AbstractShapeless<T> input(IIngredient ingredient) {

@RecipeBuilderMethodDescription(field = "ingredients")
public AbstractShapeless<T> input(IIngredient... ingredients) {
if (ingredients != null)
for (IIngredient ingredient : ingredients)
if (ingredients != null) {
for (IIngredient ingredient : ingredients) {
input(ingredient);
}
}
return this;
}

@RecipeBuilderMethodDescription(field = "ingredients")
public AbstractShapeless<T> input(Collection<IIngredient> ingredients) {
if (ingredients != null && !ingredients.isEmpty())
for (IIngredient ingredient : ingredients)
if (ingredients != null && !ingredients.isEmpty()) {
for (IIngredient ingredient : ingredients) {
input(ingredient);
}
}
return this;
}
}
Expand Down

0 comments on commit d4047b4

Please sign in to comment.