Added /butcher and mob killing to the super pickaxe.

This commit is contained in:
sk89q 2010-11-16 23:24:30 -08:00
parent f810b18f07
commit fd5a7abb1c
2 changed files with 65 additions and 0 deletions

View File

@ -56,6 +56,8 @@ public void initialize() {
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.LOGIN, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.ARM_SWING, listener, this,
PluginListener.Priority.MEDIUM);
logger.log(Level.INFO, "WorldEdit version " + getVersion() + " loaded");
}

View File

@ -162,6 +162,7 @@ public WorldEditListener() {
commands.put("/listchunks", "Print a list of used chunks");
commands.put("/delchunks", "Generate a shell script to delete chunks");
commands.put("/listsnapshots", "<Num> - List the 5 newest snapshots");
commands.put("/butcher", "<Radius> - Kill nearby mobs");
commands.put("//use", "[SnapshotID] - Use a particular snapshot");
commands.put("//restore", "<SnapshotID> - Restore a particular snapshot");
}
@ -1218,6 +1219,29 @@ public boolean performCommand(WorldEditPlayer player,
return true;
// Kill mobs
} else if (split[0].equalsIgnoreCase("/butcher")) {
checkArgs(split, 0, 1, split[0]);
int radius = split.length > 1 ?
Math.max(1, Integer.parseInt(split[1])) : -1;
Vector origin = session.getPlacementPosition(player);
int killed = 0;
for (Mob mob : etc.getServer().getMobList()) {
Vector mobPos = new Vector(mob.getX(), mob.getY(), mob.getZ());
if (mob.getHealth() > 0
&& (radius == -1 || mobPos.distance(origin) <= radius)) {
mob.setHealth(0);
killed++;
}
}
player.print("Killed " + killed + " mobs.");
return true;
// Get chunk filename
} else if (split[0].equalsIgnoreCase("/chunkinfo")) {
checkArgs(split, 0, 0, split[0]);
@ -1545,6 +1569,45 @@ public void onDisconnect(Player player) {
removeSession(new WorldEditPlayer(player));
}
/**
* Called on arm swing.
*
* @param player
*/
public void onArmSwing(Player modPlayer) {
if (!canUseCommand(modPlayer, "//")) { return; }
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
WorldEditSession session = getSession(player);
if (player.isHoldingPickAxe()) {
if (session.hasSuperPickAxe()) {
HitBlox hitBlox = new HitBlox(modPlayer, 5, 0.2);
Block block = null;
Set<BlockVector> pathBlocks = new HashSet<BlockVector>();
// Get blocks along the way.
while (hitBlox.getNextBlock() != null
&& BlockType.canPassThrough(hitBlox.getCurBlock().getType())) {
block = hitBlox.getCurBlock();
pathBlocks.add(new BlockVector(block.getX(), block.getY(), block.getZ()));
}
if (pathBlocks.size() > 0) {
// Loop through the list of mobs and find the ones to kill
for (Mob mob : etc.getServer().getMobList()) {
Vector mobPos = new BlockVector(mob.getX(), mob.getY(), mob.getZ());
if (mob.getHealth() > 0 && pathBlocks.contains(mobPos.toBlockVector())
|| pathBlocks.contains(mobPos.add(0, 1, 0).toBlockVector())
|| pathBlocks.contains(mobPos.add(0, -1, 0).toBlockVector())) {
mob.setHealth(0);
}
}
}
}
}
}
/**
* Called on right click.
*