|
|
|
@ -1,14 +1,17 @@
|
|
|
|
|
package me.loganb1max.minionsplus.model.minions;
|
|
|
|
|
|
|
|
|
|
import lombok.val;
|
|
|
|
|
import me.loganb1max.minionsplus.MinionsPlus;
|
|
|
|
|
import me.loganb1max.minionsplus.model.Minion;
|
|
|
|
|
import me.loganb1max.minionsplus.util.Replacer;
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
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.*;
|
|
|
|
|
|
|
|
|
@ -49,15 +52,56 @@ public class MinerMinion extends Minion {
|
|
|
|
|
@Override
|
|
|
|
|
public void tick() {
|
|
|
|
|
if (getEnergy() < getEnergyPerUse(getLevel())) return;
|
|
|
|
|
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);
|
|
|
|
|
// 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();
|
|
|
|
|
// float pitch = 0;
|
|
|
|
|
// switch (direction) {
|
|
|
|
|
// case NORTH:
|
|
|
|
|
// pitch = 180;
|
|
|
|
|
// break;
|
|
|
|
|
// case SOUTH:
|
|
|
|
|
// pitch = 360;
|
|
|
|
|
// break;
|
|
|
|
|
// case EAST:
|
|
|
|
|
// pitch = 270;
|
|
|
|
|
// break;
|
|
|
|
|
// case WEST:
|
|
|
|
|
// pitch = 90;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// val l = getStand().getLocation();
|
|
|
|
|
// l.setYaw(pitch);
|
|
|
|
|
// getStand().teleport(l);
|
|
|
|
|
// 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();
|
|
|
|
|
// drops.clear();
|
|
|
|
|
// drops.addAll(remaining);
|
|
|
|
|
// });
|
|
|
|
|
// if (!drops.isEmpty()) {
|
|
|
|
|
// drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
int radius = 1;
|
|
|
|
|
int y = getLocation().getBlockY();
|
|
|
|
|
for (int x = getLocation().getBlockX() - radius; x <= getLocation().getBlockX() + radius; x++) {
|
|
|
|
|
for (int z = getLocation().getBlockZ() - radius; z <= getLocation().getBlockZ() + radius; z++) {
|
|
|
|
|
Block blk = getLocation().getWorld().getBlockAt(x, y, z);
|
|
|
|
|
if (!VALID_BLOCKS.contains(blk.getType())) continue;
|
|
|
|
|
Location l = getStand().getLocation();
|
|
|
|
|
l.setYaw(getNewDirection(x - getLocation().getBlockX(), z - getLocation().getBlockZ()));
|
|
|
|
|
getStand().teleport(l);
|
|
|
|
|
final Collection<ItemStack> drops = blk.getDrops();
|
|
|
|
|
blk.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();
|
|
|
|
@ -67,21 +111,21 @@ public class MinerMinion extends Minion {
|
|
|
|
|
if (!drops.isEmpty()) {
|
|
|
|
|
drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*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);
|
|
|
|
|
});
|
|
|
|
|
if (!drops.isEmpty()) {
|
|
|
|
|
drops.forEach(item -> getLocation().getWorld().dropItemNaturally(getLocation(), item));
|
|
|
|
|
}
|
|
|
|
|
});*/
|
|
|
|
|
|
|
|
|
|
private float getNewDirection(int x, int y) {
|
|
|
|
|
if (x == 1 && y == -1) return 225;
|
|
|
|
|
if (x == 1 && y == 0) return 270;
|
|
|
|
|
if (x == 1 && y == 1) return 315;
|
|
|
|
|
if (x == 0 && y == -1) return 180;
|
|
|
|
|
if (x == 0 && y == 1) return 0;
|
|
|
|
|
if (x == -1 && y == -1) return 135;
|
|
|
|
|
if (x == -1 && y == 0) return 90;
|
|
|
|
|
if (x == -1 && y == 1) return 45;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|