diff --git a/CHANGELOG.md b/CHANGELOG.md index 37ac15cdd..038749f9c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Rewrote autocrafting again (raoulvdberge) - Reworked the Crafting Monitor (raoulvdberge) - Removed left / right click functionality on filter slots to increase / decrease the amount, replaced that functionality with a dialog (raoulvdberge) +- Fixed not being able to craft upgrades that require enchanted books (raoulvdberge) ### 1.6.3 - Fixed crash with Wireless Fluid Grid (raoulvdberge) diff --git a/src/main/java/com/raoulvdberge/refinedstorage/recipe/RecipeUpgradeWithEnchantedBook.java b/src/main/java/com/raoulvdberge/refinedstorage/recipe/RecipeUpgradeWithEnchantedBook.java index 35931c200..d9a039bd5 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/recipe/RecipeUpgradeWithEnchantedBook.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/recipe/RecipeUpgradeWithEnchantedBook.java @@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage.recipe; import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RSItems; -import com.raoulvdberge.refinedstorage.apiimpl.API; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentData; import net.minecraft.init.Blocks; @@ -11,13 +10,15 @@ import net.minecraft.item.ItemEnchantedBook; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.ShapedRecipes; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.NonNullList; import net.minecraft.world.World; // MC JSON recipes don't like comparing to NBT, that's why we need a custom recipe class. // We need to compare to NBT for the enchanted book. public class RecipeUpgradeWithEnchantedBook extends ShapedRecipes { - private ItemStack enchantedBook; + private EnchantmentData enchant; public RecipeUpgradeWithEnchantedBook(String enchantmentId, int enchantmentLevel, int upgradeId) { super(RS.ID, 3, 3, NonNullList.from(Ingredient.EMPTY, @@ -32,11 +33,23 @@ public class RecipeUpgradeWithEnchantedBook extends ShapedRecipes { Ingredient.fromStacks(new ItemStack(RSItems.QUARTZ_ENRICHED_IRON)) ), new ItemStack(RSItems.UPGRADE, 1, upgradeId)); - this.enchantedBook = ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(Enchantment.getEnchantmentByLocation(enchantmentId), enchantmentLevel)); + this.enchant = new EnchantmentData(Enchantment.getEnchantmentByLocation(enchantmentId), enchantmentLevel); } @Override public boolean matches(InventoryCrafting inv, World world) { - return super.matches(inv, world) && API.instance().getComparer().isEqualNoQuantity(inv.getStackInSlot(1), enchantedBook); + if (super.matches(inv, world)) { + NBTTagList enchantments = ItemEnchantedBook.getEnchantments(inv.getStackInSlot(1)); + + for (int i = 0; i < enchantments.tagCount(); ++i) { + NBTTagCompound enchantmentNbt = enchantments.getCompoundTagAt(i); + + if (Enchantment.getEnchantmentByID(enchantmentNbt.getShort("id")) == enchant.enchantment && enchantmentNbt.getShort("lvl") == enchant.enchantmentLevel) { + return true; + } + } + } + + return false; } }