From 9c4fb368a77ea73a2bafbd76e2212fe4d5be72d3 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Tue, 30 Jan 2024 11:43:42 +0200 Subject: [PATCH 01/15] Moved version check server --- common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java b/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java index 35e79ca45..27453fa7e 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java @@ -248,7 +248,7 @@ public void loadComplete() { .followRedirects(HttpClient.Redirect.ALWAYS) .connectTimeout(Duration.ofSeconds(5L)) .build() - .send(HttpRequest.newBuilder().uri(URI.create("https://kubejs.com/update-check?" + QUERY)).GET().build(), HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)); + .send(HttpRequest.newBuilder().uri(URI.create("https://v.kubejs.com/update-check?" + QUERY)).GET().build(), HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)); if (response.statusCode() == 200) { var body = response.body().trim(); From 3b7d06b2cbc8cad1d1d094fd8b42da37154c8241 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 4 Feb 2024 00:21:55 +0100 Subject: [PATCH 02/15] Fix builder translation keys not matching the style of vanilla --- .../java/dev/latvian/mods/kubejs/registry/BuilderBase.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java b/common/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java index cc6268f36..08a21be32 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java @@ -5,6 +5,7 @@ import dev.latvian.mods.kubejs.generator.DataJsonGenerator; import dev.latvian.mods.kubejs.typings.Info; import dev.latvian.mods.kubejs.util.UtilsJS; +import net.minecraft.Util; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; @@ -124,7 +125,7 @@ public void generateLang(Map lang) { public String getBuilderTranslationKey() { if (translationKey.isEmpty()) { - return getTranslationKeyGroup() + '.' + id.getNamespace() + '.' + id.getPath(); + return Util.makeDescriptionId(getTranslationKeyGroup(), id); } return translationKey; From ab4aabd34774a9d58d3ed8612d2e3e37c2369441 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 4 Feb 2024 00:32:50 +0100 Subject: [PATCH 03/15] Remove setting default locale (why was this here??) --- common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java b/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java index 27453fa7e..0bbce5659 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/KubeJS.java @@ -56,7 +56,6 @@ import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; -import java.util.Locale; public class KubeJS { public static final String MOD_ID = "kubejs"; @@ -92,7 +91,6 @@ public static ScriptManager getClientScriptManager() { public KubeJS() throws Throwable { instance = this; gameDirectory = Platform.getGameFolder().normalize().toAbsolutePath(); - Locale.setDefault(Locale.US); if (Files.notExists(KubeJSPaths.README)) { try { From 3f481aa9c2d2e124c128864015d208656c65a18d Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 5 Feb 2024 12:19:01 +0100 Subject: [PATCH 04/15] Add vanilla-named methods to TextWrapper, as well as some additional helpers --- .../mods/kubejs/bindings/TextWrapper.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java b/common/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java index 0b9f5afd4..0d421660d 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java @@ -14,6 +14,8 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.contents.ScoreContents; +import net.minecraft.network.chat.contents.SelectorContents; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; import org.jetbrains.annotations.Nullable; @@ -22,6 +24,7 @@ import java.util.Collection; import java.util.Map; import java.util.Objects; +import java.util.Optional; @Info("The hub for all things text components. Format text to your hearts content!") public class TextWrapper { @@ -180,6 +183,11 @@ public static MutableComponent join(MutableComponent separator, Iterable Date: Sun, 18 Feb 2024 19:43:32 +0100 Subject: [PATCH 05/15] Fix resource listing for virtual data pack as well Closes #777 --- .../mods/kubejs/script/data/VirtualKubeJSDataPack.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/script/data/VirtualKubeJSDataPack.java b/common/src/main/java/dev/latvian/mods/kubejs/script/data/VirtualKubeJSDataPack.java index 2ad5bd4a4..f1f6e9e29 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/script/data/VirtualKubeJSDataPack.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/script/data/VirtualKubeJSDataPack.java @@ -77,6 +77,10 @@ public IoSupplier getResource(PackType type, ResourceLocation locat @Override public void listResources(PackType packType, String namespace, String path, ResourceOutput visitor) { + if (!path.endsWith("/")) { + path = path + "/"; + } + for (ResourceLocation r : locationToData.keySet()) { if (!r.getPath().endsWith(".mcmeta")) { if (r.getNamespace().equals(namespace) && r.getPath().startsWith(path)) { From cf605d7160498514213374bccbbfa0413228e12c Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 18 Feb 2024 19:59:58 +0100 Subject: [PATCH 06/15] Add JsonIO.readJson / JsonIO.readString --- .../dev/latvian/mods/kubejs/util/JsonIO.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/util/JsonIO.java b/common/src/main/java/dev/latvian/mods/kubejs/util/JsonIO.java index 7bbf5ba62..49aad74d0 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/util/JsonIO.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/util/JsonIO.java @@ -6,6 +6,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonNull; import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSyntaxException; import com.google.gson.internal.Streams; @@ -101,27 +102,25 @@ public static Object toPrimitive(@Nullable JsonElement element) { return null; } - @Nullable - public static Map read(Path path) throws IOException { - if (Files.notExists(path)) { + public static JsonElement readJson(Path path) throws IOException { + if (!Files.isRegularFile(path)) { return null; } try (var fileReader = Files.newBufferedReader(path)) { - var jsonReader = new JsonReader(fileReader); - JsonElement element; - var lenient = jsonReader.isLenient(); - jsonReader.setLenient(true); - element = Streams.parse(jsonReader); - - if (!element.isJsonNull() && jsonReader.peek() != JsonToken.END_DOCUMENT) { - throw new JsonSyntaxException("Did not consume the entire document."); - } - - return MapJS.of(element); + return JsonParser.parseReader(fileReader); } } + public static String readString(Path path) throws IOException { + return toString(readJson(path)); + } + + @Nullable + public static Map read(Path path) throws IOException { + return MapJS.of(readJson(path)); + } + public static void write(Path path, @Nullable JsonObject json) throws IOException { if (json == null || json.isJsonNull()) { Files.deleteIfExists(path); From 4d4a95271ef5fed0aa9bca1cd4e1199d75f32be8 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 18 Feb 2024 20:02:35 +0100 Subject: [PATCH 07/15] Fix potentially reading non-file paths in NBTIO --- .../main/java/dev/latvian/mods/kubejs/util/NBTIOWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/util/NBTIOWrapper.java b/common/src/main/java/dev/latvian/mods/kubejs/util/NBTIOWrapper.java index a5692855a..b750a6feb 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/util/NBTIOWrapper.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/util/NBTIOWrapper.java @@ -11,7 +11,7 @@ public interface NBTIOWrapper { @Nullable static CompoundTag read(Path path) throws IOException { - if (Files.notExists(path)) { + if (!Files.isRegularFile(path)) { return null; } From 2d05590006141c568a999849dfaf7346bcac5ddf Mon Sep 17 00:00:00 2001 From: Reabstraction Date: Mon, 19 Feb 2024 15:38:24 +0100 Subject: [PATCH 08/15] 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 d30f7fc57..783a40345 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java @@ -281,7 +281,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 de7a88cfae06d3760379b811130197894a274651 Mon Sep 17 00:00:00 2001 From: Reabstraction Date: Mon, 19 Feb 2024 15:38:24 +0100 Subject: [PATCH 09/15] 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 c427dbc96ff0080f8a0f085ecce0f47f7d55f4c2 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Wed, 21 Feb 2024 11:29:18 +0200 Subject: [PATCH 10/15] 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 | 10 ++++------ .../java/dev/latvian/mods/kubejs/recipe/RecipeJS.java | 4 +++- .../dev/latvian/mods/kubejs/recipe/RecipesEventJS.java | 5 ++++- .../kubejs/recipe/special/KubeJSCraftingRecipe.java | 4 +++- 5 files changed, 22 insertions(+), 10 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 ea70da562..f5318f5d6 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 @@ -10,6 +10,7 @@ import dev.latvian.mods.kubejs.util.UtilsJS; 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$") @@ -55,7 +56,13 @@ default boolean replaceInput(ReplacementMatch match, InputReplacement with) { } default boolean hasOutput(ReplacementMatch match) { - return match instanceof ItemMatch m && m.contains(((Recipe) this).getResultItem(UtilsJS.staticRegistryAccess)); + if (match instanceof ItemMatch m) { + var result = ((Recipe) this).getResultItem(UtilsJS.staticRegistryAccess); + //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 468eb2f69..395937320 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 @@ -4,6 +4,7 @@ import dev.latvian.mods.kubejs.util.UtilsJS; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.Recipe; public class JsonRecipeJS extends RecipeJS { @Override @@ -33,14 +34,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(UtilsJS.staticRegistryAccess); - //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); + var result = ((Recipe) this).getResultItem(UtilsJS.staticRegistryAccess); + return result != null && result != ItemStack.EMPTY && !result.isEmpty() && m.contains(result); } 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 991bfcbd1..eebf81c9c 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(UtilsJS.staticRegistryAccess); + var result = getOriginalRecipe().getResultItem(UtilsJS.staticRegistryAccess); + //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 7a18d1d5e..6b2115233 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; @@ -109,7 +110,9 @@ private static String recipeToString(Recipe recipe) { } try { - map.put("out", recipe.getResultItem(UtilsJS.staticRegistryAccess).kjs$toItemString()); + var result = recipe.getResultItem(UtilsJS.staticRegistryAccess); + //noinspection ConstantValue + map.put("out", (result == null ? ItemStack.EMPTY : result).kjs$toItemString()); } catch (Exception ex) { map.put("out_error", ex.toString()); } 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 63ab1fa0d..ee408d295 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 @@ -46,7 +46,9 @@ public interface KubeJSCraftingRecipe extends CraftingRecipe { } var modifyResult = kjs$getModifyResult(); - var result = getResultItem(registryAccess).copy(); + var result = getResultItem(registryAccess); + //noinspection ConstantValue + result = (result == null || result.isEmpty()) ? ItemStack.EMPTY : result.copy(); if (modifyResult != null) { return modifyResult.modify(new ModifyRecipeCraftingGrid(container), result); } From c31bcda278254b5c900f133dd4d668501dc57c5a Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Wed, 21 Feb 2024 11:31:03 +0200 Subject: [PATCH 11/15] 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 eebf81c9c..a01fd91e4 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 ef66307da1a9c1c7b3d7083ce69e2da635092418 Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Wed, 21 Feb 2024 10:29:18 +0100 Subject: [PATCH 12/15] 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 13/15] 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 14/15] 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; From bf682e2ca1a4c93bb24a00bba4874395dd630446 Mon Sep 17 00:00:00 2001 From: pietro-lopes <97140255+pietro-lopes@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:03:24 -0300 Subject: [PATCH 15/15] fix Data Export (#794) --- .../dev/latvian/mods/kubejs/server/DataExport.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/server/DataExport.java b/common/src/main/java/dev/latvian/mods/kubejs/server/DataExport.java index 433874a4c..0b1be8dbf 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/server/DataExport.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/server/DataExport.java @@ -117,8 +117,10 @@ private void exportData0() throws Exception { appendLine(logStringBuilder, calendar, line); } - logStringBuilder.setLength(logStringBuilder.length() - 1); - addString("errors.log", logStringBuilder.toString()); + if (logStringBuilder.length() > 0) { + logStringBuilder.setLength(logStringBuilder.length() - 1); + addString("errors.log", logStringBuilder.toString()); + } logStringBuilder.setLength(0); @@ -126,8 +128,10 @@ private void exportData0() throws Exception { appendLine(logStringBuilder, calendar, line); } - logStringBuilder.setLength(logStringBuilder.length() - 1); - addString("warnings.log", logStringBuilder.toString()); + if (logStringBuilder.length() > 0) { + logStringBuilder.setLength(logStringBuilder.length() - 1); + addString("warnings.log", logStringBuilder.toString()); + } var modArr = new JsonArray();