Fixed not being able to craft upgrades that require enchanted books. Fixes #1960
This commit is contained in:
@@ -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)
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user