mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Bring across repair cost in the disenchanter
This commit is contained in:
parent
fc6bd05b4f
commit
d88291e215
@ -26,6 +26,8 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
|||||||
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||||
import me.mrCookieSlime.Slimefun.utils.MachineHelper;
|
import me.mrCookieSlime.Slimefun.utils.MachineHelper;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.Repairable;
|
||||||
|
|
||||||
public class AutoDisenchanter extends AContainer {
|
public class AutoDisenchanter extends AContainer {
|
||||||
|
|
||||||
@ -51,7 +53,7 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
@Override
|
@Override
|
||||||
protected void tick(Block b) {
|
protected void tick(Block b) {
|
||||||
BlockMenu menu = BlockStorage.getInventory(b);
|
BlockMenu menu = BlockStorage.getInventory(b);
|
||||||
|
|
||||||
if (isProcessing(b)) {
|
if (isProcessing(b)) {
|
||||||
int timeleft = progress.get(b);
|
int timeleft = progress.get(b);
|
||||||
if (timeleft > 0) {
|
if (timeleft > 0) {
|
||||||
@ -76,14 +78,14 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
MachineRecipe recipe = null;
|
MachineRecipe recipe = null;
|
||||||
Map<Enchantment, Integer> enchantments = new HashMap<>();
|
Map<Enchantment, Integer> enchantments = new HashMap<>();
|
||||||
Set<ItemEnchantment> enchantments2 = new HashSet<>();
|
Set<ItemEnchantment> enchantments2 = new HashSet<>();
|
||||||
|
|
||||||
for (int slot: getInputSlots()) {
|
for (int slot: getInputSlots()) {
|
||||||
ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1]: getInputSlots()[0]);
|
ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1]: getInputSlots()[0]);
|
||||||
ItemStack item = menu.getItemInSlot(slot);
|
ItemStack item = menu.getItemInSlot(slot);
|
||||||
|
|
||||||
// Check if disenchantable
|
// Check if disenchantable
|
||||||
SlimefunItem sfItem = null;
|
SlimefunItem sfItem = null;
|
||||||
|
|
||||||
// stops endless checks of getByItem for empty book stacks.
|
// stops endless checks of getByItem for empty book stacks.
|
||||||
if ((item != null) && (item.getType() != Material.BOOK)) {
|
if ((item != null) && (item.getType() != Material.BOOK)) {
|
||||||
sfItem = SlimefunItem.getByItem(item);
|
sfItem = SlimefunItem.getByItem(item);
|
||||||
@ -91,7 +93,7 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
if (sfItem != null && !sfItem.isDisenchantable()) {
|
if (sfItem != null && !sfItem.isDisenchantable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disenchanting
|
// Disenchanting
|
||||||
if (item != null && target != null && target.getType() == Material.BOOK) {
|
if (item != null && target != null && target.getType() == Material.BOOK) {
|
||||||
int amount = 0;
|
int amount = 0;
|
||||||
@ -112,8 +114,16 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
ItemStack book = target.clone();
|
ItemStack book = target.clone();
|
||||||
book.setAmount(1);
|
book.setAmount(1);
|
||||||
book.setType(Material.ENCHANTED_BOOK);
|
book.setType(Material.ENCHANTED_BOOK);
|
||||||
|
|
||||||
|
ItemMeta itemMeta = newItem.getItemMeta();
|
||||||
|
ItemMeta bookMeta = book.getItemMeta();
|
||||||
|
((Repairable) itemMeta).setRepairCost(0);
|
||||||
|
((Repairable) bookMeta).setRepairCost(((Repairable) itemMeta).getRepairCost());
|
||||||
|
newItem.setItemMeta(itemMeta);
|
||||||
|
book.setItemMeta(bookMeta);
|
||||||
|
|
||||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta();
|
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta();
|
||||||
|
|
||||||
for (Map.Entry<Enchantment,Integer> e: enchantments.entrySet()) {
|
for (Map.Entry<Enchantment,Integer> e: enchantments.entrySet()) {
|
||||||
newItem.removeEnchantment(e.getKey());
|
newItem.removeEnchantment(e.getKey());
|
||||||
meta.addStoredEnchant(e.getKey(), e.getValue(), true);
|
meta.addStoredEnchant(e.getKey(), e.getValue(), true);
|
||||||
@ -124,7 +134,7 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(book, e.getEnchantment(), e.getLevel());
|
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(book, e.getEnchantment(), e.getLevel());
|
||||||
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(newItem, e.getEnchantment(), 0);
|
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(newItem, e.getEnchantment(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
recipe = new MachineRecipe(100 * amount, new ItemStack[] {target, item}, new ItemStack[] {newItem, book});
|
recipe = new MachineRecipe(100 * amount, new ItemStack[] {target, item}, new ItemStack[] {newItem, book});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -133,11 +143,11 @@ public class AutoDisenchanter extends AContainer {
|
|||||||
|
|
||||||
if (recipe != null) {
|
if (recipe != null) {
|
||||||
if (!fits(b, recipe.getOutput())) return;
|
if (!fits(b, recipe.getOutput())) return;
|
||||||
|
|
||||||
for (int slot: getInputSlots()) {
|
for (int slot: getInputSlots()) {
|
||||||
menu.replaceExistingItem(slot, InvUtils.decreaseItem(menu.getItemInSlot(slot), 1));
|
menu.replaceExistingItem(slot, InvUtils.decreaseItem(menu.getItemInSlot(slot), 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
processing.put(b, recipe);
|
processing.put(b, recipe);
|
||||||
progress.put(b, recipe.getTicks());
|
progress.put(b, recipe.getTicks());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user