Skip to content

Commit

Permalink
Fix producing enchanted books without enchantments, Closes #437
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jul 31, 2016
1 parent cbbe58d commit e154b6d
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean work(TilePurifier tile) {
Enchantment enchantment = getRandomEnchantment(world, enchantments);
setResultingEnchantmentBook(tile, enchantments, enchantment);
removePriorWorkPenalty(enchantments, purifyItem);
setRemainingEnchantmentsOnPurifiedItem(enchantments, enchantment, purifyItem);
purifyItem = setRemainingEnchantmentsOnPurifiedItem(enchantments, enchantment, purifyItem);
tile.setPurifyItem(purifyItem);
}
tile.setBuckets(0, tile.getBucketsRest());
Expand Down Expand Up @@ -93,12 +93,19 @@ private void removePriorWorkPenalty(Map<Enchantment, Integer> enchantments, Item
purifyItem.setRepairCost(remainingPenalty);
}

private void setRemainingEnchantmentsOnPurifiedItem(Map<Enchantment, Integer> enchantments, Enchantment enchantment, ItemStack purifyItem) {
private ItemStack setRemainingEnchantmentsOnPurifiedItem(Map<Enchantment, Integer> enchantments, Enchantment enchantment, ItemStack purifyItem) {
Map<Enchantment, Integer> remainingEnchantments = Maps.newHashMap(enchantments);
remainingEnchantments.remove(enchantment);

// Hardcoded conversion to a regular book when enchantment list of enchanted book is empty.
if (remainingEnchantments.isEmpty() && purifyItem.getItem() == Items.ENCHANTED_BOOK) {
purifyItem = new ItemStack(Items.BOOK);
}

if (purifyItem.hasTagCompound() && purifyItem.getTagCompound().hasKey("StoredEnchantments")) {
purifyItem.getTagCompound().removeTag("StoredEnchantments");
}
EnchantmentHelper.setEnchantments(remainingEnchantments, purifyItem);
return purifyItem;
}
}

0 comments on commit e154b6d

Please sign in to comment.