|
|
|
@ -6,9 +6,11 @@ import me.loganb1max.minionsplus.util.Replacer;
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
|
import org.bukkit.inventory.InventoryHolder;
|
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
public class MinerMinion extends Minion {
|
|
|
|
@ -48,9 +50,15 @@ public class MinerMinion extends Minion {
|
|
|
|
|
@Override
|
|
|
|
|
public void tick() {
|
|
|
|
|
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
|
|
|
|
getLinkedBlocks().stream().filter(block -> !(block.getState() instanceof InventoryHolder)).filter(block -> VALID_BLOCKS.contains(block.getType())).limit(getBlockLimit(getLevel())).forEachOrdered(block -> {
|
|
|
|
|
Block block = getLocation().getBlock();
|
|
|
|
|
for (BlockFace direction: new BlockFace[] {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
|
|
|
|
|
if (!VALID_BLOCKS.contains(block.getRelative(direction).getType())) continue;
|
|
|
|
|
block = block.getRelative(direction);
|
|
|
|
|
final Collection<ItemStack> drops = block.getDrops();
|
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
|
|
|
|
|
|
if (!drops.isEmpty()) consumeEnergy(getEnergyPerUse(getLevel()));
|
|
|
|
|
|
|
|
|
|
getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> {
|
|
|
|
|
InventoryHolder inv = (InventoryHolder) b.getState();
|
|
|
|
|
final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values();
|
|
|
|
@ -60,15 +68,29 @@ public class MinerMinion extends Minion {
|
|
|
|
|
if (!drops.isEmpty()) {
|
|
|
|
|
drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/*getLinkedBlocks().stream().filter(block -> !(block.getState() instanceof InventoryHolder)).filter(block -> VALID_BLOCKS.contains(block.getType())).limit(getBlockLimit(getLevel())).forEachOrdered(block -> {
|
|
|
|
|
final Collection<ItemStack> drops = block.getDrops();
|
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
|
getLinkedBlocks().stream().filter(b -> b.getState() instanceof InventoryHolder).forEachOrdered(b -> {
|
|
|
|
|
InventoryHolder inv = (InventoryHolder) b.getState();
|
|
|
|
|
final Collection<ItemStack> remaining = inv.getInventory().addItem(drops.toArray(new ItemStack[] {})).values();
|
|
|
|
|
drops.clear();
|
|
|
|
|
drops.addAll(remaining);
|
|
|
|
|
});
|
|
|
|
|
consumeEnergy(getEnergyPerUse(getLevel()));
|
|
|
|
|
if (!drops.isEmpty()) {
|
|
|
|
|
drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
|
|
|
|
}
|
|
|
|
|
});*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Replacer getReplacer() {
|
|
|
|
|
final DecimalFormat format = new DecimalFormat("#.#");
|
|
|
|
|
return Replacer.create()
|
|
|
|
|
.add("%level%", String.valueOf(getLevel()))
|
|
|
|
|
.add("%energy%", String.valueOf(getEnergy()))
|
|
|
|
|
.add("%energy%", format.format(getEnergy()))
|
|
|
|
|
.add("%owner%", getOwnerName())
|
|
|
|
|
.add("%blocklimit%", String.valueOf(getBlockLimit(getLevel())));
|
|
|
|
|
}
|
|
|
|
|