diff --git a/src/main/java/com/klin/holoItems/abstractClasses/BatteryPack.java b/src/main/java/com/klin/holoItems/abstractClasses/BatteryPack.java index 95151a2..c0c7ca4 100644 --- a/src/main/java/com/klin/holoItems/abstractClasses/BatteryPack.java +++ b/src/main/java/com/klin/holoItems/abstractClasses/BatteryPack.java @@ -36,6 +36,10 @@ public BatteryPack(String name, Material material, String lore, int durability, this.cap = cap; } + protected boolean isFuelAccepted(ItemStack fuel, Material content) { + return fuel.getType() == content; + } + public int ability(Inventory inv, ItemStack item, Player player){ int count = 0; Location loc = player.getLocation(); @@ -46,7 +50,7 @@ public int ability(Inventory inv, ItemStack item, Player player){ for(ItemStack fuel : inv.getContents()) { if(fuel==null || fuel.getType()==Material.AIR) continue; - if(fuel.getType()!=content) { + if (!isFuelAccepted(fuel, content)) { world.dropItemNaturally(loc, fuel); continue; } @@ -54,16 +58,16 @@ public int ability(Inventory inv, ItemStack item, Player player){ } count *= perCharge; int excess = count-cap; - excess = (int) (excess/perCharge); - if(excess>0) { - int stackSize = content.getMaxStackSize(); - if(stackSize==64) + excess = (int) (excess / perCharge + (excess % perCharge > 0 ? 1 : 0)); + + int stackSize = content.getMaxStackSize(); + while (excess > 0) { + if (excess > stackSize) { + world.dropItemNaturally(loc, new ItemStack(content, stackSize)); + excess -= stackSize; + } else { world.dropItemNaturally(loc, new ItemStack(content, excess)); - else{ - while(excess>0){ - world.dropItemNaturally(loc, new ItemStack(content, Math.min(stackSize, excess))); - excess -= stackSize; - } + excess = 0; } } @@ -78,18 +82,20 @@ public int ability(Inventory inv, ItemStack item, Player player){ protected void repack(ItemStack item, Inventory inv) { Integer amount = item.getItemMeta(). getPersistentDataContainer().get(Utility.pack, PersistentDataType.INTEGER); - if (amount != null) { + if (amount != null && amount > 0) { Material content = this.content; if (content == null) content = item.getType(); int stackSize = content.getMaxStackSize(); amount = (int) (amount / perCharge); - if(stackSize==64) - inv.addItem(new ItemStack(content, amount)); - else{ - while(amount>0){ - inv.addItem(new ItemStack(content, Math.min(stackSize, amount))); + + while (amount > 0) { + if (amount > stackSize) { + inv.addItem(new ItemStack(content, stackSize)); amount -= stackSize; + } else { + inv.addItem(new ItemStack(content, amount)); + amount = 0; } } } diff --git a/src/main/java/com/klin/holoItems/collections/en1/watsonCollection/items/GemKnife.java b/src/main/java/com/klin/holoItems/collections/en1/watsonCollection/items/GemKnife.java index 6fed094..1cd22d9 100644 --- a/src/main/java/com/klin/holoItems/collections/en1/watsonCollection/items/GemKnife.java +++ b/src/main/java/com/klin/holoItems/collections/en1/watsonCollection/items/GemKnife.java @@ -91,4 +91,15 @@ public void effect(PlayerInteractEvent event) { block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(material, amount)); } + + @Override + protected boolean isFuelAccepted(ItemStack fuel, Material content) { + // Stop a different gem knife being consumed as fuel + // (Also stops items with any metadata) + if (fuel.hasItemMeta()) { + return false; + } + + return super.isFuelAccepted(fuel, content); + } }