From f88503ebacc6a0c0621e427b394e62d81cf10080 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Sun, 23 Oct 2022 10:58:52 +0200 Subject: [PATCH 1/5] Fix a README link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fb7e95f..009ff55b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![curseforge downloads](http://cf.way2muchnoise.eu/full_nbt-crafting_downloads.svg?badge_style=flat)](https://minecraft.curseforge.com/projects/nbt-crafting) [![modrinth downloads](https://img.shields.io/modrinth/dt/nbt-crafting?color=30b27b&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAAAAAAAAQCEeRdzAAAFjElEQVR4nO2aaYhWVRjH3WpcinS0tHIMW0gM7CmXsLQFCnOBFq0PmS2klpZmSraYYFNEC7SZBYqipfWhSAyKVo0RTC1JCwn6kJW0ueWSWuOo%2Ff%2Bc5zLnPe%2B595773vvOfKgXfjBw733Oc855tvOcadPm%2F1%2F8T96b05a0th6pPyjZEZwDrgXTwDNgEXgDLAWvgLlgAhgCeoB2ra10B9AfPADeBz%2BDv8HxBI6CvWAzeBWMAbWtofhQXeFfwLEUpZM4DNaBKeC0llD%2BbPAS2Jmg1BGwD%2FwGtuskd6fsDr%2F5AowFNdVQvD24AXzjGZw78Af4EMxTJWjn5%2BuEzwUCRoDpYDn4XpV2ZR0AC8CZRSrfCTwE%2FvTY87dgDhhAR86wGHXgNvAROORZkDXgwiKU7yImorjbT9N4NO9K4fuTwM1gvS6IPQZ3e2ge4TXgSdDorA5XbbAUGN8h6wzwPPjLmQR3%2BOJKhU51tpc2u7Ba0QJyTwR3ewJEA%2BiTVdjl4FdLSBOYD06uhvLWuMzc48EuZxKLQn2MQrqDTx0BK0DXCpWiKXYLNTmdBPPCQWt8WsL40AGn64pHH38J%2BmZU%2BgRwHrgLrFQzuDTD9zW64%2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aUZuloN37UkDkcnCIBNbqYk1h%2Fdcz14i%2FJmXckt%2FLWoLxVYS2%2FJcax96ky83VFeZ3EayZ2OgaKSYa3gCfABxogfFmd9wO8vSzuismZCHufrF%2BSktsxNTlOipd7LNgOxigc0aQLME6qccnnTKLoa1beTrbMNatnIheIKcNpFts9zu6rm7gjbHixBGn5i%2B6YydAxeZ06SkyGflZK%2F9WAvvGYmATIViGjT%2Bv%2Bq0HILyQq%2Fed%2F%2FwIQ1cNLieDSBgAAAABJRU5ErkJggg%3D%3D&style=flat-square)](https://modrinth.com/mod/nbt-crafting) -[![latest maven release](https://img.shields.io/maven-metadata/v?color=0f9fbc&metadataUrl=https%3A%2F%2Fmaven.siphalor.de%2Fde%2Fsiphalor%2Fnbtcrafting-1.16%2Fmaven-metadata.xml&style=flat-square)](https://maven.siphalor.de/de/siphalor/nbtcrafting-1.15/) +[![latest maven release](https://img.shields.io/maven-metadata/v?color=0f9fbc&metadataUrl=https%3A%2F%2Fmaven.siphalor.de%2Fde%2Fsiphalor%2Fnbtcrafting-1.16%2Fmaven-metadata.xml&style=flat-square)](https://maven.siphalor.de/de/siphalor/nbtcrafting-1.16/) A 1.15+ Minecraft Fabric mod to let you work with NBT data in recipes, add brewing recipes and a lot more. From ce13178b3339fa531a1d2680209cadc32f68f733 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Tue, 22 Nov 2022 20:38:07 +0100 Subject: [PATCH 2/5] Minor recipe remainder performance improvements --- .../java/de/siphalor/nbtcrafting/mixin/MixinIngredient.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/de/siphalor/nbtcrafting/mixin/MixinIngredient.java b/src/main/java/de/siphalor/nbtcrafting/mixin/MixinIngredient.java index 64ef3647..520edabc 100644 --- a/src/main/java/de/siphalor/nbtcrafting/mixin/MixinIngredient.java +++ b/src/main/java/de/siphalor/nbtcrafting/mixin/MixinIngredient.java @@ -311,10 +311,7 @@ private static IngredientEntryCondition loadIngredientEntryCondition(JsonObject if (advancedEntries != null) { for (IngredientEntry entry : advancedEntries) { if (entry.matches(stack)) { - ItemStack remainder = entry.getRecipeRemainder(stack, reference); - if (remainder != null) { - return remainder; - } + return entry.getRecipeRemainder(stack, reference); } } } From 9eec96bb7a7312b0984057162b111760054401e0 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Tue, 22 Nov 2022 20:39:59 +0100 Subject: [PATCH 3/5] Expose ingredient to stack resolution in the NbtC recipe api --- .../siphalor/nbtcrafting/api/recipe/NBTCRecipe.java | 11 +++++++++++ .../de/siphalor/nbtcrafting/mixin/MixinRecipe.java | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/siphalor/nbtcrafting/api/recipe/NBTCRecipe.java b/src/main/java/de/siphalor/nbtcrafting/api/recipe/NBTCRecipe.java index 177637d7..b3690ac2 100644 --- a/src/main/java/de/siphalor/nbtcrafting/api/recipe/NBTCRecipe.java +++ b/src/main/java/de/siphalor/nbtcrafting/api/recipe/NBTCRecipe.java @@ -46,4 +46,15 @@ default Collection getIngredients() { * @return A map consisting of keys and belonging {@link net.minecraft.nbt.CompoundTag}s, {@link Number}s or {@link String}s */ Map buildDollarReference(I inv); + + /** + * An advanced form of the reference map, that allows to make use of the ingredient to stack resolution that Nbt Crafting does anyway. + * @implNote For backwards compatibility, you must still override the simpler form {@link #buildDollarReference(Inventory)} either way. + * @param inv the inventory for that this method is being called + * @param ingredientToStackResolution An array which resolves the ingredient indexes from {@link #getIngredients()} to the stacks in the inventory. + * @return A map consisting of keys and belonging {@link net.minecraft.nbt.CompoundTag}s, {@link Number}s or {@link String}s + */ + default Map buildDollarReference(I inv, int[] ingredientToStackResolution) { + return buildDollarReference(inv); + } } diff --git a/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java b/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java index 96fe4314..ba62d5d7 100644 --- a/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java +++ b/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java @@ -52,9 +52,9 @@ default DefaultedList getRemainingStacks(Inventory inventory) { int[] resolvedIngredientStacks; if (this instanceof NBTCRecipe) { ingredients = new ArrayList<>(((NBTCRecipe) this).getIngredients()); - // noinspection unchecked - reference = ((NBTCRecipe) this).buildDollarReference(inventory); resolvedIngredientStacks = RecipeUtil.resolveIngredients(ingredients, inventory); + // noinspection unchecked + reference = ((NBTCRecipe) this).buildDollarReference(inventory, resolvedIngredientStacks); } else { ingredients = getPreviewInputs(); resolvedIngredientStacks = RecipeUtil.resolveIngredients(ingredients, inventory); From daa9ab0ab3c1850fbe078238846da2a28b40e657 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Tue, 22 Nov 2022 21:26:17 +0100 Subject: [PATCH 4/5] Fix #126 (Compatibility with Fabric API 0.67.0+) --- gradle.properties | 2 +- .../nbtcrafting/mixin/MixinRecipe.java | 70 ++++++++++++------- src/main/resources/fabric.mod.json | 2 +- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6c49bbfe..03052cc8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ org.gradle.jvmargs=-Xmx1G minecraft_version=1.17.1 minecraft_major_version = 1.17 yarn_mappings=1:v2 - loader_version=0.11.6 + loader_version=0.14.10 # Mod Properties mod_version = 2.2.2 diff --git a/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java b/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java index d6b0f573..fa3189ca 100644 --- a/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java +++ b/src/main/java/de/siphalor/nbtcrafting/mixin/MixinRecipe.java @@ -17,9 +17,9 @@ package de.siphalor.nbtcrafting.mixin; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import de.siphalor.nbtcrafting.api.RecipeUtil; +import de.siphalor.nbtcrafting.api.recipe.NBTCRecipe; +import de.siphalor.nbtcrafting.ingredient.IIngredient; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; @@ -28,36 +28,51 @@ import net.minecraft.util.collection.DefaultedList; import org.apache.commons.lang3.ArrayUtils; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import de.siphalor.nbtcrafting.api.RecipeUtil; -import de.siphalor.nbtcrafting.api.recipe.NBTCRecipe; -import de.siphalor.nbtcrafting.ingredient.IIngredient; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; @Mixin(Recipe.class) public interface MixinRecipe { @Shadow DefaultedList getIngredients(); - /** - * @reason Returns the recipe remainders. Sadly has to overwrite since this is an interface. - * @author Siphalor - */ - @Overwrite - default DefaultedList getRemainder(Inventory inventory) { - final DefaultedList stackList = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY); - Map reference; + @Inject(method = "getRemainder", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILSOFT) + default void modifyRemainingStacks(Inventory inventory, CallbackInfoReturnable> cir, DefaultedList stackList) { + // The stackList is already pre-populated with Vanilla and Fabric API remainders List ingredients; - int[] resolvedIngredientStacks; - if (this instanceof NBTCRecipe) { + boolean customRecipe = this instanceof NBTCRecipe; + if (customRecipe) { ingredients = new ArrayList<>(((NBTCRecipe) this).getIngredients()); - resolvedIngredientStacks = RecipeUtil.resolveIngredients(ingredients, inventory); - // noinspection unchecked - reference = ((NBTCRecipe) this).buildDollarReference(inventory, resolvedIngredientStacks); } else { ingredients = getIngredients(); - resolvedIngredientStacks = RecipeUtil.resolveIngredients(ingredients, inventory); + } + + boolean shallContinue = false; + for (Ingredient ingredient : ingredients) { + if (((IIngredient) (Object) ingredient).nbtCrafting$isAdvanced()) { + shallContinue = true; + break; + } + } + if (!shallContinue) { + return; + } + + // Resolve the ingredient indexes to the belonging stack indices + int[] resolvedIngredientStacks = RecipeUtil.resolveIngredients(ingredients, inventory); + Map reference; + + if (customRecipe) { + // noinspection unchecked + reference = ((NBTCRecipe) this).buildDollarReference(inventory, resolvedIngredientStacks); + } else { reference = RecipeUtil.buildReferenceMapFromResolvedIngredients(resolvedIngredientStacks, inventory); } @@ -65,16 +80,17 @@ default DefaultedList getRemainder(Inventory inventory) { ItemStack stack = inventory.getStack(i); int ingredientIndex = ArrayUtils.indexOf(resolvedIngredientStacks, i); if (ingredientIndex >= 0) { - ItemStack remainder = ((IIngredient) (Object) ingredients.get(ingredientIndex)).nbtCrafting$getRecipeRemainder(stack, reference); + IIngredient ingredient = (IIngredient) (Object) ingredients.get(ingredientIndex); + // Simple, Vanilla-ish entries should already be set + if (!ingredient.nbtCrafting$isAdvanced()) { + continue; + } + + ItemStack remainder = ingredient.nbtCrafting$getRecipeRemainder(stack, reference); if (remainder != null) { stackList.set(i, remainder); - continue; } } - if (stack.getItem().hasRecipeRemainder()) { - stackList.set(i, new ItemStack(stack.getItem().getRecipeRemainder())); - } } - return stackList; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 614d3dd6..c536e41f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -43,7 +43,7 @@ ] }, "depends": { - "fabricloader": ">=0.4.0" + "fabricloader": ">=0.13.0" }, "custom": { "modmenu": { From a1d9499c67daaea78e2de1405e382a70e73c0661 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Tue, 22 Nov 2022 21:34:50 +0100 Subject: [PATCH 5/5] Version 2.2.3 **For versions 1.18 and above:** Critical compatibility fix with the latest Fabric API versions (0.67.0+). Also contains a bunch of minor internal improvements around recipe remainders. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5b324e7d..8ad3ede7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.11.6 # Mod Properties - mod_version = 2.2.2 + mod_version = 2.2.3 mod_release = release mod_mc_version_specifier = 1.15.x mod_mc_versions = 1.15;1.15.1;1.15.2