Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/main/java/com/klin/holoItems/abstractClasses/BatteryPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -46,24 +50,24 @@ 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;
}
count += fuel.getAmount();
}
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;
}
}

Expand All @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}