From de7a88cfae06d3760379b811130197894a274651 Mon Sep 17 00:00:00 2001 From: Reabstraction Date: Mon, 19 Feb 2024 15:38:24 +0100 Subject: [PATCH 1/4] Removed entry from class filter --- .../main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java b/common/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java index ff0d4b252..007f338b8 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java @@ -270,7 +270,6 @@ public void registerClasses(ScriptType type, ClassFilter filter) { filter.allow("java.lang.Comparable"); filter.allow("java.lang.CharSequence"); filter.allow("java.lang.Void"); - filter.allow("java.lang.Class"); filter.allow("java.lang.Package"); filter.allow("java.lang.Appendable"); filter.allow("java.lang.AutoCloseable"); From ef66307da1a9c1c7b3d7083ce69e2da635092418 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Wed, 21 Feb 2024 10:29:18 +0100 Subject: [PATCH 2/4] Added safety check for when recipes return null in output item instead of ItemStack.EMPTY. (why) --- .../java/dev/latvian/mods/kubejs/core/RecipeKJS.java | 9 ++++++++- .../dev/latvian/mods/kubejs/recipe/JsonRecipeJS.java | 7 ++----- .../java/dev/latvian/mods/kubejs/recipe/RecipeJS.java | 4 +++- .../dev/latvian/mods/kubejs/recipe/RecipesEventJS.java | 1 + .../mods/kubejs/recipe/special/KubeJSCraftingRecipe.java | 7 +++++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/core/RecipeKJS.java b/common/src/main/java/dev/latvian/mods/kubejs/core/RecipeKJS.java index 9add30656..7b7f9ef28 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/core/RecipeKJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/core/RecipeKJS.java @@ -9,6 +9,7 @@ import dev.latvian.mods.kubejs.registry.KubeJSRegistries; import dev.latvian.mods.rhino.util.RemapPrefixForJS; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; @RemapPrefixForJS("kjs$") @@ -54,7 +55,13 @@ default boolean replaceInput(ReplacementMatch match, InputReplacement with) { } default boolean hasOutput(ReplacementMatch match) { - return match instanceof ItemMatch m && m.contains(((Recipe) this).getResultItem()); + if (match instanceof ItemMatch m) { + var result = ((Recipe) this).getResultItem(); + //noinspection ConstantValue + return result != null && result != ItemStack.EMPTY && !result.isEmpty() && m.contains(result); + } + + return false; } default boolean replaceOutput(ReplacementMatch match, OutputReplacement with) { diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/JsonRecipeJS.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/JsonRecipeJS.java index 89f1bd398..d4e72f5a9 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/JsonRecipeJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/JsonRecipeJS.java @@ -32,14 +32,11 @@ public boolean replaceInput(ReplacementMatch match, InputReplacement with) { } @Override + @SuppressWarnings("ConstantValue") public boolean hasOutput(ReplacementMatch match) { if (CommonProperties.get().matchJsonRecipes && match instanceof ItemMatch m && getOriginalRecipe() != null) { var r = getOriginalRecipe().getResultItem(); - //noinspection ConstantValue - if (r == null) { - throw new NullPointerException("ItemStack should never be null, but recipe " + this + " returned null as the output!"); - } - return r != ItemStack.EMPTY && m.contains(r); + return r != null && r != ItemStack.EMPTY && m.contains(r); } return false; diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java index 7d080793c..0e0c1260b 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java @@ -544,7 +544,9 @@ public ItemStack getOriginalRecipeResult() { return ItemStack.EMPTY; } - return getOriginalRecipe().getResultItem(); + var result = getOriginalRecipe().getResultItem(); + //noinspection ConstantValue + return result == null ? ItemStack.EMPTY : result; } public List getOriginalRecipeIngredients() { diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java index 2f19afc9a..81123db43 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipesEventJS.java @@ -38,6 +38,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.Bootstrap; import net.minecraft.util.GsonHelper; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeSerializer; diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/special/KubeJSCraftingRecipe.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/special/KubeJSCraftingRecipe.java index a70a4a83c..3d6fbd542 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/special/KubeJSCraftingRecipe.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/special/KubeJSCraftingRecipe.java @@ -44,11 +44,14 @@ public interface KubeJSCraftingRecipe extends CraftingRecipe { } var modifyResult = kjs$getModifyResult(); + var result = getResultItem(); + //noinspection ConstantValue + result = result == null ? ItemStack.EMPTY : result.copy(); if (modifyResult != null) { - return modifyResult.modify(new ModifyRecipeCraftingGrid(container), getResultItem().copy()); + return modifyResult.modify(new ModifyRecipeCraftingGrid(container), result); } - return getResultItem().copy(); + return result.copy(); } @Nullable From 261bc1686156ff49a6329c1551a243a64a31adae Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Wed, 21 Feb 2024 11:31:03 +0200 Subject: [PATCH 3/4] Added recipe.consumeIngredient(filter) method for when you want to make sure item gets destroyed when normally it wouldn't, like water bucket -> bucket now can be water bucket -> air --- .../dev/latvian/mods/kubejs/recipe/RecipeJS.java | 5 +++++ .../recipe/ingredientaction/ConsumeAction.java | 16 ++++++++++++++++ .../ingredientaction/IngredientAction.java | 1 + 3 files changed, 22 insertions(+) create mode 100644 common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/ConsumeAction.java diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java index 0e0c1260b..9a790f7d4 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/RecipeJS.java @@ -16,6 +16,7 @@ import dev.latvian.mods.kubejs.recipe.component.MissingComponentException; import dev.latvian.mods.kubejs.recipe.component.RecipeComponentBuilderMap; import dev.latvian.mods.kubejs.recipe.component.RecipeComponentValue; +import dev.latvian.mods.kubejs.recipe.ingredientaction.ConsumeAction; import dev.latvian.mods.kubejs.recipe.ingredientaction.CustomIngredientAction; import dev.latvian.mods.kubejs.recipe.ingredientaction.DamageAction; import dev.latvian.mods.kubejs.recipe.ingredientaction.IngredientAction; @@ -589,6 +590,10 @@ public final RecipeJS keepIngredient(IngredientActionFilter filter) { return ingredientAction(filter, new KeepAction()); } + public final RecipeJS consumeIngredient(IngredientActionFilter filter) { + return ingredientAction(filter, new ConsumeAction()); + } + public final RecipeJS modifyResult(ModifyRecipeResultCallback callback) { modifyResult = callback; save(); diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/ConsumeAction.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/ConsumeAction.java new file mode 100644 index 000000000..807b92c1a --- /dev/null +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/ConsumeAction.java @@ -0,0 +1,16 @@ +package dev.latvian.mods.kubejs.recipe.ingredientaction; + +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.item.ItemStack; + +public class ConsumeAction extends IngredientAction { + @Override + public ItemStack transform(ItemStack old, int index, CraftingContainer container) { + return ItemStack.EMPTY; + } + + @Override + public String getType() { + return "consume"; + } +} diff --git a/common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/IngredientAction.java b/common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/IngredientAction.java index 6153374aa..98795c17e 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/IngredientAction.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/recipe/ingredientaction/IngredientAction.java @@ -27,6 +27,7 @@ public abstract class IngredientAction extends IngredientActionFilter { FACTORY_MAP.put("damage", json -> new DamageAction(json.get("damage").getAsInt())); FACTORY_MAP.put("replace", json -> new ReplaceAction(ItemStackJS.resultFromRecipeJson(json.get("item")))); FACTORY_MAP.put("keep", json -> new KeepAction()); + FACTORY_MAP.put("consume", json -> new ConsumeAction()); } public static List parseList(JsonElement json) { From 26d9636cbf149f82b8b026f037b81f4037d945ee Mon Sep 17 00:00:00 2001 From: LI Junyu Date: Thu, 22 Feb 2024 02:56:03 +0800 Subject: [PATCH 4/4] Support negative priority (#795) --- .../java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java b/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java index 226e0c581..b0ce570ab 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/script/ScriptFileInfo.java @@ -16,7 +16,7 @@ public class ScriptFileInfo { private static final Pattern FILE_FIXER = Pattern.compile("[^\\w./]"); - private static final Pattern PROPERTY_PATTERN = Pattern.compile("^(\\w+)\\s*[:=]?\\s*(\\w+)$"); + private static final Pattern PROPERTY_PATTERN = Pattern.compile("^(\\w+)\\s*[:=]?\\s*(-?\\w+)$"); public final ScriptPackInfo pack; public final String file;