From 255bea441606848dfac7ba2918c8044d9ef6a4ba Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 26 Nov 2010 21:23:51 -0800 Subject: [PATCH] Added item dropping to the super pickaxe. --- src/ServerInterface.java | 88 ++++++++++++++++++++++++++++++++++++++ src/WorldEditListener.java | 39 +++++++++++------ 2 files changed, 113 insertions(+), 14 deletions(-) diff --git a/src/ServerInterface.java b/src/ServerInterface.java index 05647436d..df9703733 100644 --- a/src/ServerInterface.java +++ b/src/ServerInterface.java @@ -267,6 +267,94 @@ public class ServerInterface { pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); } + /** + * Drop an item. + * + * @param pt + * @param type + * @param count + * @param times + */ + public static void dropItem(Vector pt, int type, int count, int times) { + for (int i = 0; i < times; i++) { + etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), + type, count); + } + } + + /** + * Drop an item. + * + * @param pt + * @param type + * @param count + * @param times + */ + public static void dropItem(Vector pt, int type, int count) { + etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), + type, count); + } + + /** + * Drop an item. + * + * @param pt + * @param type + * @param count + * @param times + */ + public static void dropItem(Vector pt, int type) { + etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), + type, 1); + } + + /** + * Simulate a block being mined. + * + * @param pt + */ + public static void simulateBlockMine(Vector pt) { + int type = getBlockType(pt); + setBlockType(pt, 0); + + if (type == 1) { dropItem(pt, 4); } // Stone + else if (type == 2) { dropItem(pt, 3); } // Grass + else if (type == 13) { // Gravel + dropItem(pt, type); + + if (random.nextDouble() >= 0.9) { + dropItem(pt, 318); + } + } + else if (type == 16) { dropItem(pt, 263); } // Coal ore + else if (type == 18) { // Leaves + if (random.nextDouble() > 0.95) { + dropItem(pt, 6); + } + } + else if (type == 20) { } // Glass + else if (type == 43) { dropItem(pt, 44); } // Double step + else if (type == 47) { } // Bookshelves + else if (type == 52) { } // Mob spawner + else if (type == 53) { dropItem(pt, 5); } // Wooden stairs + else if (type == 55) { dropItem(pt, 331); } // Redstone wire + else if (type == 56) { dropItem(pt, 264); } // Diamond ore + else if (type == 60) { dropItem(pt, 3); } // Soil + else if (type == 63) { dropItem(pt, 323); } // Sign post + else if (type == 67) { dropItem(pt, 4); } // Cobblestone stairs + else if (type == 68) { dropItem(pt, 323); } // Wall sign + else if (type == 73) { dropItem(pt, 331, 1, 4); } // Redstone ore + else if (type == 74) { dropItem(pt, 331, 1, 4); } // Glowing redstone ore + else if (type == 78) { } // Snow + else if (type == 79) { } // Ice + else if (type == 82) { dropItem(pt, 337, 1, 4); } // Clay + else if (type == 83) { dropItem(pt, 338); } // Reed + else if (type == 89) { dropItem(pt, 348); } // Lightstone + else if (type != 0) { + dropItem(pt, type); + } + } + /** * Instantiate a class without calling its constructor. * diff --git a/src/WorldEditListener.java b/src/WorldEditListener.java index 99f8a2e9e..cf8ae9f42 100755 --- a/src/WorldEditListener.java +++ b/src/WorldEditListener.java @@ -90,6 +90,8 @@ public class WorldEditListener extends PluginListener { private boolean logComands = false; private boolean registerHelp = true; private int wandItem = 271; + private boolean superPickaxeDrop = true; + private boolean superPickaxeManyDrop = true; /** * Construct an instance of the plugin. @@ -1779,7 +1781,11 @@ public class WorldEditListener extends PluginListener { return false; } - ServerInterface.setBlockType(pos, 0); + if (superPickaxeDrop) { + ServerInterface.simulateBlockMine(pos); + } else { + ServerInterface.setBlockType(pos, 0); + } // Area super pickaxe } else if (session.getSuperPickaxeMode() == @@ -1801,7 +1807,11 @@ public class WorldEditListener extends PluginListener { for (int z = oz - size; z <= oz + size; z++) { Vector pos = new Vector(x, y, z); if (ServerInterface.getBlockType(pos) == initialType) { - ServerInterface.setBlockType(pos, 0); + if (superPickaxeManyDrop) { + ServerInterface.simulateBlockMine(pos); + } else { + ServerInterface.setBlockType(pos, 0); + } } } } @@ -1853,7 +1863,11 @@ public class WorldEditListener extends PluginListener { visited.add(pos); if (ServerInterface.getBlockType(pos) == initialType) { - ServerInterface.setBlockType(pos, 0); + if (superPickaxeManyDrop) { + ServerInterface.simulateBlockMine(pos); + } else { + ServerInterface.setBlockType(pos, 0); + } } else { return; } @@ -1992,9 +2006,15 @@ public class WorldEditListener extends PluginListener { } profile = properties.getBoolean("debug-profile", false); - wandItem = properties.getInt("wand-item", 271); - + defaultChangeLimit = Math.max(-1, properties.getInt("max-blocks-changed", -1)); + maxRadius = Math.max(-1, properties.getInt("max-radius", -1)); + maxSuperPickaxeSize = Math.max(1, properties.getInt("max-super-pickaxe-size", 5)); + registerHelp = properties.getBoolean("register-help", true); + logComands = properties.getBoolean("log-commands", false); + superPickaxeDrop = properties.getBoolean("super-pickaxe-drop-items", true); + superPickaxeManyDrop = properties.getBoolean("super-pickaxe-many-drop-items", false); + // Get allowed blocks allowedBlocks = new HashSet(); for (String b : properties.getString("allowed-blocks", @@ -2005,11 +2025,6 @@ public class WorldEditListener extends PluginListener { } } - defaultChangeLimit = Math.max(-1, properties.getInt("max-blocks-changed", -1)); - - maxRadius = Math.max(-1, properties.getInt("max-radius", -1)); - - maxSuperPickaxeSize = Math.max(1, properties.getInt("max-super-pickaxe-size", 5)); String snapshotsDir = properties.getString("snapshots-dir", ""); if (!snapshotsDir.trim().equals("")) { @@ -2021,10 +2036,6 @@ public class WorldEditListener extends PluginListener { String type = properties.getString("shell-save-type", "").trim(); shellSaveType = type.equals("") ? null : type; - registerHelp = properties.getBoolean("register-help", true); - - logComands = properties.getBoolean("log-commands", false); - String logFile = properties.getString("log-file", ""); if (!logFile.equals("")) { try {