Fixed not being able to craft upgrades that require enchanted books. Fixes #1960

This commit is contained in:
raoulvdberge
2018-08-27 19:20:05 +02:00
parent 58d6daedb4
commit c9288a0968
2 changed files with 18 additions and 4 deletions

View File

@@ -4,6 +4,7 @@
- Rewrote autocrafting again (raoulvdberge) - Rewrote autocrafting again (raoulvdberge)
- Reworked the Crafting Monitor (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) - 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 ### 1.6.3
- Fixed crash with Wireless Fluid Grid (raoulvdberge) - Fixed crash with Wireless Fluid Grid (raoulvdberge)

View File

@@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage.recipe;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSItems; import com.raoulvdberge.refinedstorage.RSItems;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData; import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@@ -11,13 +10,15 @@ import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
// MC JSON recipes don't like comparing to NBT, that's why we need a custom recipe class. // 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. // We need to compare to NBT for the enchanted book.
public class RecipeUpgradeWithEnchantedBook extends ShapedRecipes { public class RecipeUpgradeWithEnchantedBook extends ShapedRecipes {
private ItemStack enchantedBook; private EnchantmentData enchant;
public RecipeUpgradeWithEnchantedBook(String enchantmentId, int enchantmentLevel, int upgradeId) { public RecipeUpgradeWithEnchantedBook(String enchantmentId, int enchantmentLevel, int upgradeId) {
super(RS.ID, 3, 3, NonNullList.from(Ingredient.EMPTY, 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)) Ingredient.fromStacks(new ItemStack(RSItems.QUARTZ_ENRICHED_IRON))
), new ItemStack(RSItems.UPGRADE, 1, upgradeId)); ), 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 @Override
public boolean matches(InventoryCrafting inv, World world) { 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;
} }
} }