diff --git a/src/HMPlayer.java b/src/HMPlayer.java index 46d09acb6..12372c476 100644 --- a/src/HMPlayer.java +++ b/src/HMPlayer.java @@ -17,9 +17,11 @@ * along with this program. If not, see . */ +import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.ServerInterface; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditPlayer; +import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.blocks.BlockType; @@ -38,8 +40,8 @@ public class HMPlayer extends WorldEditPlayer { * * @param player */ - public HMPlayer(Player player) { - super(); + public HMPlayer(ServerInterface server, Player player) { + super(server); this.player = player; } @@ -58,13 +60,13 @@ public class HMPlayer extends WorldEditPlayer { * @param range * @return point */ - public Vector getBlockTrace(int range) { + public WorldVector getBlockTrace(int range) { HitBlox hitBlox = new HitBlox(player,range, 0.2); Block block = hitBlox.getTargetBlock(); if (block == null) { return null; } - return new Vector(block.getX(), block.getY(), block.getZ()); + return new WorldVector(null, block.getX(), block.getY(), block.getZ()); } /** @@ -73,7 +75,7 @@ public class HMPlayer extends WorldEditPlayer { * @param range * @return point */ - public Vector getSolidBlockTrace(int range) { + public WorldVector getSolidBlockTrace(int range) { HitBlox hitBlox = new HitBlox(player,range, 0.2); Block block = null; @@ -85,7 +87,7 @@ public class HMPlayer extends WorldEditPlayer { if (block == null) { return null; } - return new Vector(block.getX(), block.getY(), block.getZ()); + return new WorldVector(null, block.getX(), block.getY(), block.getZ()); } /** @@ -130,8 +132,17 @@ public class HMPlayer extends WorldEditPlayer { * * @return point */ - public Vector getPosition() { - return new Vector(player.getX(), player.getY(), player.getZ()); + public WorldVector getPosition() { + return new WorldVector(null, player.getX(), player.getY(), player.getZ()); + } + + /** + * Get the player's world. + * + * @return point + */ + public LocalWorld getWorld() { + return null; } /** @@ -174,6 +185,7 @@ public class HMPlayer extends WorldEditPlayer { boolean foundNext = false; int searchDist = 0; HitBlox hitBlox = new HitBlox(player,range, 0.2); + LocalWorld world = getPosition().getWorld(); Block block; while ((block = hitBlox.getNextBlock()) != null) { searchDist++; @@ -183,7 +195,7 @@ public class HMPlayer extends WorldEditPlayer { if (block.getType() == 0) { if (foundNext) { Vector v = new Vector(block.getX(), block.getY() - 1, block.getZ()); - if (server.getBlockType(v) == 0) { + if (server.getBlockType(world, v) == 0) { setPosition(v.add(0.5, 0, 0.5)); return true; } diff --git a/src/HMServerInterface.java b/src/HMServerInterface.java index 8c4812d24..9d0478e4c 100644 --- a/src/HMServerInterface.java +++ b/src/HMServerInterface.java @@ -43,7 +43,7 @@ public class HMServerInterface extends ServerInterface { * @param type * @return */ - public boolean setBlockType(Vector pt, int type) { + public boolean setBlockType(LocalWorld world, Vector pt, int type) { // Can't set colored cloth or crash if ((type >= 21 && type <= 34) || type == 36) { return false; @@ -58,7 +58,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @return */ - public int getBlockType(Vector pt) { + public int getBlockType(LocalWorld world, Vector pt) { return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); } @@ -70,7 +70,7 @@ public class HMServerInterface extends ServerInterface { * @param data * @return */ - public void setBlockData(Vector pt, int data) { + public void setBlockData(LocalWorld world, Vector pt, int data) { etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), data); } @@ -81,7 +81,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @return */ - public int getBlockData(Vector pt) { + public int getBlockData(LocalWorld world, Vector pt) { return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); } @@ -92,7 +92,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @param text */ - public void setSignText(Vector pt, String[] text) { + public void setSignText(LocalWorld world, Vector pt, String[] text) { Sign signData = (Sign)etc.getServer().getComplexBlock( pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (signData == null) { @@ -110,7 +110,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @return */ - public String[] getSignText(Vector pt) { + public String[] getSignText(LocalWorld world, Vector pt) { Sign signData = (Sign)etc.getServer().getComplexBlock( pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (signData == null) { @@ -130,7 +130,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @return */ - public BaseItemStack[] getChestContents(Vector pt) { + public BaseItemStack[] getChestContents(LocalWorld world, Vector pt) { ComplexBlock cblock = etc.getServer().getOnlyComplexBlock( pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); @@ -165,7 +165,7 @@ public class HMServerInterface extends ServerInterface { * @param contents * @return */ - public boolean setChestContents(Vector pt, + public boolean setChestContents(LocalWorld world, Vector pt, BaseItemStack[] contents) { ComplexBlock cblock = etc.getServer().getOnlyComplexBlock( @@ -197,7 +197,7 @@ public class HMServerInterface extends ServerInterface { * * @param pt */ - public boolean clearChest(Vector pt) { + public boolean clearChest(LocalWorld world, Vector pt) { ComplexBlock cblock = etc.getServer().getOnlyComplexBlock( pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); @@ -247,7 +247,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @param mobType */ - public void setMobSpawnerType(Vector pt, String mobType) { + public void setMobSpawnerType(LocalWorld world, Vector pt, String mobType) { ComplexBlock cblock = etc.getServer().getComplexBlock( pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); @@ -266,7 +266,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @param mobType */ - public String getMobSpawnerType(Vector pt) { + public String getMobSpawnerType(LocalWorld world, Vector pt) { try { return MinecraftServerInterface.getMobSpawnerType(pt); } catch (Throwable t) { @@ -282,7 +282,7 @@ public class HMServerInterface extends ServerInterface { * @param pt * @return */ - public boolean generateTree(EditSession editSession, Vector pt) { + public boolean generateTree(EditSession editSession, LocalWorld world, Vector pt) { try { return MinecraftServerInterface.generateTree(editSession, pt); } catch (Throwable t) { @@ -300,7 +300,7 @@ public class HMServerInterface extends ServerInterface { * @param count * @param times */ - public void dropItem(Vector pt, int type, int count, int times) { + public void dropItem(LocalWorld world, 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); @@ -315,7 +315,7 @@ public class HMServerInterface extends ServerInterface { * @param count * @param times */ - public void dropItem(Vector pt, int type, int count) { + public void dropItem(LocalWorld world, Vector pt, int type, int count) { etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, count); } @@ -328,7 +328,7 @@ public class HMServerInterface extends ServerInterface { * @param count * @param times */ - public void dropItem(Vector pt, int type) { + public void dropItem(LocalWorld world, Vector pt, int type) { etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, 1); } @@ -338,57 +338,57 @@ public class HMServerInterface extends ServerInterface { * * @param pt */ - public void simulateBlockMine(Vector pt) { - int type = getBlockType(pt); - setBlockType(pt, 0); + public void simulateBlockMine(LocalWorld world, Vector pt) { + int type = getBlockType(world, pt); + setBlockType(world, pt, 0); - if (type == 1) { dropItem(pt, 4); } // Stone - else if (type == 2) { dropItem(pt, 3); } // Grass + if (type == 1) { dropItem(world, pt, 4); } // Stone + else if (type == 2) { dropItem(world, pt, 3); } // Grass else if (type == 7) { } // Bedrock else if (type == 8) { } // Water else if (type == 9) { } // Water else if (type == 10) { } // Lava else if (type == 11) { } // Lava else if (type == 13) { // Gravel - dropItem(pt, type); + dropItem(world, pt, type); if (random.nextDouble() >= 0.9) { - dropItem(pt, 318); + dropItem(world, pt, 318); } } - else if (type == 16) { dropItem(pt, 263); } // Coal ore + else if (type == 16) { dropItem(world, pt, 263); } // Coal ore else if (type == 18) { // Leaves if (random.nextDouble() > 0.95) { - dropItem(pt, 6); + dropItem(world, pt, 6); } } else if (type == 20) { } // Glass - else if (type == 43) { dropItem(pt, 44); } // Double step + else if (type == 43) { dropItem(world, pt, 44); } // Double step else if (type == 47) { } // Bookshelves else if (type == 51) { } // Fire 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 == 59) { dropItem(pt, 295); } // Crops - else if (type == 60) { dropItem(pt, 3); } // Soil - else if (type == 62) { dropItem(pt, 61); } // Furnace - else if (type == 63) { dropItem(pt, 323); } // Sign post - else if (type == 64) { dropItem(pt, 324); } // Wood door - else if (type == 67) { dropItem(pt, 4); } // Cobblestone stairs - else if (type == 68) { dropItem(pt, 323); } // Wall sign - else if (type == 71) { dropItem(pt, 330); } // Iron door - 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 == 75) { dropItem(pt, 76); } // Redstone torch + else if (type == 53) { dropItem(world, pt, 5); } // Wooden stairs + else if (type == 55) { dropItem(world, pt, 331); } // Redstone wire + else if (type == 56) { dropItem(world, pt, 264); } // Diamond ore + else if (type == 59) { dropItem(world, pt, 295); } // Crops + else if (type == 60) { dropItem(world, pt, 3); } // Soil + else if (type == 62) { dropItem(world, pt, 61); } // Furnace + else if (type == 63) { dropItem(world, pt, 323); } // Sign post + else if (type == 64) { dropItem(world, pt, 324); } // Wood door + else if (type == 67) { dropItem(world, pt, 4); } // Cobblestone stairs + else if (type == 68) { dropItem(world, pt, 323); } // Wall sign + else if (type == 71) { dropItem(world, pt, 330); } // Iron door + else if (type == 73) { dropItem(world, pt, 331, 1, 4); } // Redstone ore + else if (type == 74) { dropItem(world, pt, 331, 1, 4); } // Glowing redstone ore + else if (type == 75) { dropItem(world, pt, 76); } // Redstone torch 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 == 82) { dropItem(world, pt, 337, 1, 4); } // Clay + else if (type == 83) { dropItem(world, pt, 338); } // Reed + else if (type == 89) { dropItem(world, pt, 348); } // Lightstone else if (type == 90) { } // Portal else if (type != 0) { - dropItem(pt, type); + dropItem(world, pt, type); } } @@ -409,7 +409,7 @@ public class HMServerInterface extends ServerInterface { * @param radius * @return */ - public int killMobs(Vector origin, int radius) { + public int killMobs(LocalWorld world, Vector origin, int radius) { int killed = 0; for (Mob mob : etc.getServer().getMobList()) { diff --git a/src/HMWorldEditListener.java b/src/HMWorldEditListener.java index a2acae535..14d4227fe 100755 --- a/src/HMWorldEditListener.java +++ b/src/HMWorldEditListener.java @@ -17,11 +17,7 @@ * along with this program. If not, see . */ -import java.util.List; -import java.util.ArrayList; import java.util.Map; -import java.util.HashMap; -import java.util.Set; import java.util.HashSet; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,16 +25,10 @@ import java.util.logging.Handler; import java.util.logging.FileHandler; import java.io.*; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.bags.BlockBag; -import com.sk89q.worldedit.blocks.*; -import com.sk89q.worldedit.data.*; -import com.sk89q.worldedit.filters.*; import com.sk89q.worldedit.snapshots.*; -import com.sk89q.worldedit.regions.*; -import com.sk89q.worldedit.patterns.*; /** - * Plugin base. + * The event listener for WorldEdit in hMod. * * @author sk89q */ @@ -47,23 +37,36 @@ public class HMWorldEditListener extends PluginListener { * Logger. */ private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); - /** - * WorldEditLibrary's properties file. + * Properties file. */ private PropertiesFile properties; - /** * Main WorldEdit controller. */ - private WorldEditController controller = new WorldEditController(); + private WorldEditController controller; + /** + * A copy of the server instance. This is where all world<->WorldEdit calls + * will go through. + */ + private ServerInterface server; + + /** + * Constructs an instance. + * + * @param server + */ + public HMWorldEditListener(ServerInterface server) { + this.server = server; + } + /** * * @param player */ @Override public void onDisconnect(Player player) { - controller.handleDisconnect(new HMPlayer(player)); + controller.handleDisconnect(wrapPlayer(player)); } /** @@ -72,7 +75,7 @@ public class HMWorldEditListener extends PluginListener { * @param player */ public void onArmSwing(Player player) { - controller.handleArmSwing(new HMPlayer(player)); + controller.handleArmSwing(wrapPlayer(player)); } /** @@ -91,7 +94,7 @@ public class HMWorldEditListener extends PluginListener { Vector pos = new Vector(blockClicked.getX(), blockClicked.getY(), blockClicked.getZ()); - return controller.handleBlockRightClick(new HMPlayer(player), pos); + return controller.handleBlockRightClick(wrapPlayer(player), pos); } /** @@ -107,7 +110,7 @@ public class HMWorldEditListener extends PluginListener { Vector pos = new Vector(blockClicked.getX(), blockClicked.getY(), blockClicked.getZ()); - return controller.handleBlockLeftClick(new HMPlayer(player), pos); + return controller.handleBlockLeftClick(wrapPlayer(player), pos); } /** @@ -118,7 +121,7 @@ public class HMWorldEditListener extends PluginListener { */ @Override public boolean onCommand(Player player, String[] split) { - return controller.handleCommand(new HMPlayer(player), split); + return controller.handleCommand(wrapPlayer(player), split); } /** @@ -222,6 +225,10 @@ public class HMWorldEditListener extends PluginListener { * @return */ public WorldEditSession _bridgeSession(Player player) { - return controller.getBridgeSession(new HMPlayer(player)); + return controller.getBridgeSession(wrapPlayer(player)); + } + + private WorldEditPlayer wrapPlayer(Player player) { + return new HMPlayer(server, player); } } diff --git a/src/WorldEdit.java b/src/WorldEdit.java index 66b1fa696..bf6cb8ed8 100644 --- a/src/WorldEdit.java +++ b/src/WorldEdit.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ import java.util.logging.Level; import java.util.logging.Logger; @@ -31,22 +31,28 @@ public class WorldEdit extends Plugin { /** * Logger. */ - private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); - /** - * WorldEditLibrary instance. - */ - private static HMWorldEditListener listener; + private static final Logger logger = Logger + .getLogger("Minecraft.WorldEdit"); /** - * WorldEdit version, fetched from the .jar's manifest. Used to print the - * WorldEdit version in various places. + * The event listener for WorldEdit an hMod. Configuration and such is + * also loaded here as well, although the core of the WorldEdit is + * actually in com.sk89q.worldedit.WorldEditController and is merely + * loaded by this listener. + */ + private final HMWorldEditListener listener; + + /** + * WorldEdit version, fetched from the .jar's manifest. */ private String version; - public WorldEdit() { - ServerInterface.setup(new HMServerInterface()); - listener = new HMWorldEditListener(); - } + /** + * Construct an instance of the plugin. + */ + public WorldEdit() { + listener = new HMWorldEditListener(new HMServerInterface()); + } /** * Initializes the plugin. @@ -91,25 +97,25 @@ public class WorldEdit extends Plugin { /** * Get the CraftBook version. - * + * * @return */ public String getVersion() { if (version != null) { return version; } - + Package p = WorldEdit.class.getPackage(); - + if (p == null) { p = Package.getPackage("com.sk89q.worldedit"); } - + if (p == null) { version = "(unknown)"; } else { version = p.getImplementationVersion(); - + if (version == null) { version = "(unknown)"; } @@ -117,13 +123,4 @@ public class WorldEdit extends Plugin { return version; } - - /** - * Returns the listener. - * - * @return - */ - public HMWorldEditListener getListener() { - return listener; - } } diff --git a/src/com/sk89q/worldedit/BlockWorldVector.java b/src/com/sk89q/worldedit/BlockWorldVector.java new file mode 100644 index 000000000..a7c4fe1c1 --- /dev/null +++ b/src/com/sk89q/worldedit/BlockWorldVector.java @@ -0,0 +1,101 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit; + +/** + * Extension of Vector that supports being compared as ints (for accuracy). + * + * @author sk89q + */ +public class BlockWorldVector extends WorldVector { + /** + * Construct the Vector object. + * + * @param pt + */ + public BlockWorldVector(WorldVector pt) { + super(pt.getWorld(), pt); + } + + /** + * Construct the Vector object. + * + * @param pt + */ + public BlockWorldVector(LocalWorld world, Vector pt) { + super(world, pt); + } + + /** + * Construct the Vector object. + * + * @param pt + */ + public BlockWorldVector(LocalWorld world, int x, int y, int z) { + super(world, x, y, z); + } + + /** + * Construct the Vector object. + * + * @param pt + */ + public BlockWorldVector(LocalWorld world, float x, float y, float z) { + super(world, x, y, z); + } + + /** + * Construct the Vector object. + * + * @param pt + */ + public BlockWorldVector(LocalWorld world, double x, double y, double z) { + super(world, x, y, z); + } + + /** + * Checks if another object is equivalent. + * + * @param obj + * @return whether the other object is equivalent + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof WorldVector)) { + return false; + } + WorldVector other = (WorldVector)obj; + return (int)other.x == (int)this.x && (int)other.y == (int)this.y + && (int)other.z == (int)this.z; + + } + + /** + * Gets the hash code. + * + * @return hash code + */ + @Override + public int hashCode() { + return (Integer.valueOf((int)x).hashCode() >> 13) ^ + (Integer.valueOf((int)y).hashCode() >> 7) ^ + Integer.valueOf((int)z).hashCode(); + } +} diff --git a/src/com/sk89q/worldedit/EditSession.java b/src/com/sk89q/worldedit/EditSession.java index 01fb0a42a..3c8e1d0c4 100755 --- a/src/com/sk89q/worldedit/EditSession.java +++ b/src/com/sk89q/worldedit/EditSession.java @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ package com.sk89q.worldedit; @@ -29,7 +29,6 @@ import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Random; -import com.sk89q.worldedit.*; import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.bags.*; import com.sk89q.worldedit.blocks.*; @@ -37,12 +36,12 @@ import com.sk89q.worldedit.patterns.*; /** * This class can wrap all block editing operations into one "edit session" that - * stores the state of the blocks before modification. This allows for easy - * undo or redo. In addition to that, this class can use a "queue mode" that - * will know how to handle some special types of items such as signs and - * torches. For example, torches must be placed only after there is already - * a block below it, otherwise the torch will be placed as an item. - * + * stores the state of the blocks before modification. This allows for easy undo + * or redo. In addition to that, this class can use a "queue mode" that will + * know how to handle some special types of items such as signs and torches. For + * example, torches must be placed only after there is already a block below it, + * otherwise the torch will be placed as an item. + * * @author sk89q */ public class EditSession { @@ -50,36 +49,40 @@ public class EditSession { * Random number generator. */ private static Random prng = new Random(); - + /** * Server interface. */ private ServerInterface server; - + /** + * World. + */ + private LocalWorld world; + /** * Stores the original blocks before modification. */ - private DoubleArrayList original = - new DoubleArrayList(true); + private DoubleArrayList original = new DoubleArrayList( + true); /** * Stores the current blocks. */ - private DoubleArrayList current = - new DoubleArrayList(false); + private DoubleArrayList current = new DoubleArrayList( + false); /** * Blocks that should be placed before last. */ - private DoubleArrayList queueAfter = - new DoubleArrayList(false); + private DoubleArrayList queueAfter = new DoubleArrayList( + false); /** * Blocks that should be placed last. */ - private DoubleArrayList queueLast = - new DoubleArrayList(false); + private DoubleArrayList queueLast = new DoubleArrayList( + false); /** * The maximum number of blocks to change at a time. If this number is - * exceeded, a MaxChangedBlocksException exception will be - * raised. -1 indicates no limit. + * exceeded, a MaxChangedBlocksException exception will be raised. -1 + * indicates no limit. */ private int maxBlocks = -1; /** @@ -98,25 +101,38 @@ public class EditSession { /** * Construct the object with a maximum number of blocks. + * + * @param server + * @param world + * @param maxBlocks */ - public EditSession(int maxBlocks) { + public EditSession(ServerInterface server, LocalWorld world, int maxBlocks) { if (maxBlocks < -1) { throw new IllegalArgumentException("Max blocks must be >= -1"); } + this.maxBlocks = maxBlocks; - server = ServerInterface.getInstance(); + this.server = server; + this.world = world; } /** * Construct the object with a maximum number of blocks and a block bag. + * + * @param server + * @param maxBlocks + * @blockBag */ - public EditSession(int maxBlocks, BlockBag blockBag) { + public EditSession(ServerInterface server, LocalWorld world, int maxBlocks, + BlockBag blockBag) { if (maxBlocks < -1) { throw new IllegalArgumentException("Max blocks must be >= -1"); } + this.maxBlocks = maxBlocks; this.blockBag = blockBag; - server = ServerInterface.getInstance(); + this.server = server; + this.world = world; } /** @@ -133,15 +149,15 @@ public class EditSession { } // Clear the chest so that it doesn't drop items - if (server.getBlockType(pt) == 54 && blockBag == null) { - server.clearChest(pt); + if (server.getBlockType(world, pt) == 54 && blockBag == null) { + server.clearChest(world, pt); } int id = block.getID(); - + if (blockBag != null) { - int existing = server.getBlockType(pt); - + int existing = server.getBlockType(world, pt); + if (id > 0) { try { blockBag.fetchPlacedBlock(id); @@ -160,52 +176,52 @@ public class EditSession { } } } - - boolean result = server.setBlockType(pt, id); + + boolean result = server.setBlockType(world, pt, id); if (id != 0) { if (BlockType.usesData(id)) { - server.setBlockData(pt, block.getData()); + server.setBlockData(world, pt, block.getData()); } // Signs if (block instanceof SignBlock) { - SignBlock signBlock = (SignBlock)block; + SignBlock signBlock = (SignBlock) block; String[] text = signBlock.getText(); - server.setSignText(pt, text); - // Chests + server.setSignText(world, pt, text); + // Chests } else if (block instanceof ChestBlock && blockBag == null) { - ChestBlock chestBlock = (ChestBlock)block; - server.setChestContents(pt, chestBlock.getItems()); - // Mob spawners + ChestBlock chestBlock = (ChestBlock) block; + server.setChestContents(world, pt, chestBlock.getItems()); + // Mob spawners } else if (block instanceof MobSpawnerBlock) { - MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock)block; - server.setMobSpawnerType(pt, mobSpawnerblock.getMobType()); + MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock) block; + server.setMobSpawnerType(world, pt, mobSpawnerblock.getMobType()); } } - + return result; } /** * Sets the block at position x, y, z with a block type. If queue mode is - * enabled, blocks may not be actually set in world until flushQueue() - * is called. - * + * enabled, blocks may not be actually set in world until flushQueue() is + * called. + * * @param pt * @param block * @return Whether the block changed -- not entirely dependable */ public boolean setBlock(Vector pt, BaseBlock block) - throws MaxChangedBlocksException { + throws MaxChangedBlocksException { BlockVector blockPt = pt.toBlockVector(); - - //if (!original.containsKey(blockPt)) { - original.put(blockPt, getBlock(pt)); - if (maxBlocks != -1 && original.size() > maxBlocks) { - throw new MaxChangedBlocksException(maxBlocks); - } - //} + // if (!original.containsKey(blockPt)) { + original.put(blockPt, getBlock(pt)); + + if (maxBlocks != -1 && original.size() > maxBlocks) { + throw new MaxChangedBlocksException(maxBlocks); + } + // } current.put(pt.toBlockVector(), block); @@ -242,7 +258,7 @@ public class EditSession { if (BlockType.shouldPlaceLast(block.getID())) { queueLast.put(pt.toBlockVector(), block); return getBlock(pt).getID() != block.getID(); - // Destroy torches, etc. first + // Destroy torches, etc. first } else if (BlockType.shouldPlaceLast(getBlock(pt).getID())) { rawSetBlock(pt, new BaseBlock(0)); } else { @@ -256,7 +272,7 @@ public class EditSession { /** * Gets the block type at a position x, y, z. - * + * * @param pt * @return Block type */ @@ -264,38 +280,39 @@ public class EditSession { // In the case of the queue, the block may have not actually been // changed yet if (queued) { - /*BlockVector blockPt = pt.toBlockVector(); - - if (current.containsKey(blockPt)) { - return current.get(blockPt); - }*/ + /* + * BlockVector blockPt = pt.toBlockVector(); + * + * if (current.containsKey(blockPt)) { return current.get(blockPt); + * } + */ } - + return rawGetBlock(pt); } /** * Gets the block type at a position x, y, z. - * + * * @param pt * @return BaseBlock */ public BaseBlock rawGetBlock(Vector pt) { - int type = server.getBlockType(pt); - int data = server.getBlockData(pt); + int type = server.getBlockType(world, pt); + int data = server.getBlockData(world, pt); // Sign if (type == 63 || type == 68) { - String[] text = server.getSignText(pt); + String[] text = server.getSignText(world, pt); return new SignBlock(type, data, text); - // Chest + // Chest } else if (type == 54) { - BaseItemStack[] items = - server.getChestContents(pt); + BaseItemStack[] items = server.getChestContents(world, pt); return new ChestBlock(data, items); - // Mob spawner + // Mob spawner } else if (type == 52) { - return new MobSpawnerBlock(data, server.getMobSpawnerType(pt)); + return new MobSpawnerBlock(data, + server.getMobSpawnerType(world, pt)); } else { return new BaseBlock(type, data); } @@ -305,9 +322,9 @@ public class EditSession { * Restores all blocks to their initial state. */ public void undo() { - for (Map.Entry entry : original) { - BlockVector pt = (BlockVector)entry.getKey(); - smartSetBlock(pt, (BaseBlock)entry.getValue()); + for (Map.Entry entry : original) { + BlockVector pt = (BlockVector) entry.getKey(); + smartSetBlock(pt, (BaseBlock) entry.getValue()); } flushQueue(); } @@ -316,9 +333,9 @@ public class EditSession { * Sets to new state. */ public void redo() { - for (Map.Entry entry : current) { - BlockVector pt = (BlockVector)entry.getKey(); - smartSetBlock(pt, (BaseBlock)entry.getValue()); + for (Map.Entry entry : current) { + BlockVector pt = (BlockVector) entry.getKey(); + smartSetBlock(pt, (BaseBlock) entry.getValue()); } flushQueue(); } @@ -332,9 +349,9 @@ public class EditSession { } /** - * Get the maximum number of blocks that can be changed. -1 will be - * returned if disabled. - * + * Get the maximum number of blocks that can be changed. -1 will be returned + * if disabled. + * * @return block change limit */ public int getBlockChangeLimit() { @@ -344,7 +361,8 @@ public class EditSession { /** * Set the maximum number of blocks that can be changed. * - * @param maxBlocks -1 to disable + * @param maxBlocks + * -1 to disable */ public void setBlockChangeLimit(int maxBlocks) { if (maxBlocks < -1) { @@ -383,19 +401,21 @@ public class EditSession { * Finish off the queue. */ public void flushQueue() { - if (!queued) { return; } + if (!queued) { + return; + } - for (Map.Entry entry : queueAfter) { - BlockVector pt = (BlockVector)entry.getKey(); - rawSetBlock(pt, (BaseBlock)entry.getValue()); + for (Map.Entry entry : queueAfter) { + BlockVector pt = (BlockVector) entry.getKey(); + rawSetBlock(pt, (BaseBlock) entry.getValue()); } // We don't want to place these blocks if other blocks were missing // because it might cause the items to drop if (blockBag == null || missingBlocks.size() == 0) { - for (Map.Entry entry : queueLast) { - BlockVector pt = (BlockVector)entry.getKey(); - rawSetBlock(pt, (BaseBlock)entry.getValue()); + for (Map.Entry entry : queueLast) { + BlockVector pt = (BlockVector) entry.getKey(); + rawSetBlock(pt, (BaseBlock) entry.getValue()); } } @@ -405,7 +425,7 @@ public class EditSession { /** * Fills an area recursively in the X/Z directions. - * + * * @param origin * @param block * @param radius @@ -413,10 +433,9 @@ public class EditSession { * @param recursive * @return number of blocks affected */ - public int fillXZ(Vector origin, BaseBlock block, - int radius, int depth, boolean recursive) - throws MaxChangedBlocksException { - + public int fillXZ(Vector origin, BaseBlock block, int radius, int depth, + boolean recursive) throws MaxChangedBlocksException { + int affected = 0; int originX = origin.getBlockX(); int originY = origin.getBlockY(); @@ -481,7 +500,7 @@ public class EditSession { /** * Recursively fills a block and below until it hits another block. - * + * * @param x * @param cy * @param z @@ -491,12 +510,12 @@ public class EditSession { * @return */ private int fillY(int x, int cy, int z, BaseBlock block, int minY) - throws MaxChangedBlocksException { + throws MaxChangedBlocksException { int affected = 0; for (int y = cy; y >= minY; y--) { Vector pt = new Vector(x, y, z); - + if (getBlock(pt).isAir()) { setBlock(pt, block); affected++; @@ -510,7 +529,7 @@ public class EditSession { /** * Fills an area recursively in the X/Z directions. - * + * * @param origin * @param pattern * @param radius @@ -518,9 +537,8 @@ public class EditSession { * @param recursive * @return number of blocks affected */ - public int fillXZ(Vector origin, Pattern pattern, - int radius, int depth, boolean recursive) - throws MaxChangedBlocksException { + public int fillXZ(Vector origin, Pattern pattern, int radius, int depth, + boolean recursive) throws MaxChangedBlocksException { int affected = 0; int originX = origin.getBlockX(); @@ -586,7 +604,7 @@ public class EditSession { /** * Recursively fills a block and below until it hits another block. - * + * * @param x * @param cy * @param z @@ -596,7 +614,7 @@ public class EditSession { * @return */ private int fillY(int x, int cy, int z, Pattern pattern, int minY) - throws MaxChangedBlocksException { + throws MaxChangedBlocksException { int affected = 0; for (int y = cy; y >= minY; y--) { @@ -621,8 +639,8 @@ public class EditSession { * @param height * @return number of blocks affected */ - public int removeAbove(Vector pos, int size, int height) throws - MaxChangedBlocksException { + public int removeAbove(Vector pos, int size, int height) + throws MaxChangedBlocksException { int maxY = Math.min(127, pos.getBlockY() + height - 1); size--; int affected = 0; @@ -649,14 +667,14 @@ public class EditSession { /** * Remove blocks below. - * + * * @param pos * @param size * @param height * @return number of blocks affected */ - public int removeBelow(Vector pos, int size, int height) throws - MaxChangedBlocksException { + public int removeBelow(Vector pos, int size, int height) + throws MaxChangedBlocksException { int minY = Math.max(0, pos.getBlockY() - height); size--; int affected = 0; @@ -683,14 +701,14 @@ public class EditSession { /** * Remove nearby blocks of a type. - * + * * @param pos * @param blockType * @param size * @return number of blocks affected */ - public int removeNear(Vector pos, int blockType, int size) throws - MaxChangedBlocksException { + public int removeNear(Vector pos, int blockType, int size) + throws MaxChangedBlocksException { int affected = 0; BaseBlock air = new BaseBlock(0); @@ -713,7 +731,7 @@ public class EditSession { /** * Sets all the blocks inside a region to a certain block type. - * + * * @param region * @param block * @return number of blocks affected @@ -759,7 +777,7 @@ public class EditSession { /** * Sets all the blocks inside a region to a certain block type. - * + * * @param region * @param block * @return number of blocks affected @@ -805,15 +823,16 @@ public class EditSession { /** * Replaces all the blocks of a type inside a region to another block type. - * + * * @param region - * @param fromBlockType -1 for non-air + * @param fromBlockType + * -1 for non-air * @param toBlockType * @return number of blocks affected * @throws MaxChangedBlocksException */ - public int replaceBlocks(Region region, Set fromBlockTypes, BaseBlock toBlock) - throws MaxChangedBlocksException { + public int replaceBlocks(Region region, Set fromBlockTypes, + BaseBlock toBlock) throws MaxChangedBlocksException { int affected = 0; if (region instanceof CuboidRegion) { @@ -834,9 +853,9 @@ public class EditSession { Vector pt = new Vector(x, y, z); int curBlockType = getBlock(pt).getID(); - if ((fromBlockTypes == null && curBlockType != 0) || - (fromBlockTypes != null && - fromBlockTypes.contains(curBlockType))) { + if ((fromBlockTypes == null && curBlockType != 0) + || (fromBlockTypes != null && fromBlockTypes + .contains(curBlockType))) { if (setBlock(pt, toBlock)) { affected++; } @@ -848,8 +867,8 @@ public class EditSession { for (Vector pt : region) { int curBlockType = getBlock(pt).getID(); - if (fromBlockTypes == null && curBlockType != 0 || - fromBlockTypes.contains(curBlockType)) { + if (fromBlockTypes == null && curBlockType != 0 + || fromBlockTypes.contains(curBlockType)) { if (setBlock(pt, toBlock)) { affected++; } @@ -862,16 +881,16 @@ public class EditSession { /** * Replaces all the blocks of a type inside a region to another block type. - * + * * @param region - * @param fromBlockType -1 for non-air + * @param fromBlockType + * -1 for non-air * @param pattern * @return number of blocks affected * @throws MaxChangedBlocksException */ public int replaceBlocks(Region region, Set fromBlockTypes, - Pattern pattern) - throws MaxChangedBlocksException { + Pattern pattern) throws MaxChangedBlocksException { int affected = 0; if (region instanceof CuboidRegion) { @@ -892,9 +911,9 @@ public class EditSession { Vector pt = new Vector(x, y, z); int curBlockType = getBlock(pt).getID(); - if ((fromBlockTypes == null && curBlockType != 0) || - (fromBlockTypes != null && - fromBlockTypes.contains(curBlockType))) { + if ((fromBlockTypes == null && curBlockType != 0) + || (fromBlockTypes != null && fromBlockTypes + .contains(curBlockType))) { if (setBlock(pt, pattern.next(pt))) { affected++; } @@ -906,8 +925,8 @@ public class EditSession { for (Vector pt : region) { int curBlockType = getBlock(pt).getID(); - if (fromBlockTypes == null && curBlockType != 0 || - fromBlockTypes.contains(curBlockType)) { + if (fromBlockTypes == null && curBlockType != 0 + || fromBlockTypes.contains(curBlockType)) { if (setBlock(pt, pattern.next(pt))) { affected++; } @@ -920,7 +939,7 @@ public class EditSession { /** * Make faces of the region (as if it was a cuboid if it's not). - * + * * @param region * @param block * @return number of blocks affected @@ -942,23 +961,35 @@ public class EditSession { for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { - if (setBlock(new Vector(x, y, minZ), block)) { affected++; } - if (setBlock(new Vector(x, y, maxZ), block)) { affected++; } + if (setBlock(new Vector(x, y, minZ), block)) { + affected++; + } + if (setBlock(new Vector(x, y, maxZ), block)) { + affected++; + } affected++; } } for (int y = minY; y <= maxY; y++) { for (int z = minZ; z <= maxZ; z++) { - if (setBlock(new Vector(minX, y, z), block)) { affected++; } - if (setBlock(new Vector(maxX, y, z), block)) { affected++; } + if (setBlock(new Vector(minX, y, z), block)) { + affected++; + } + if (setBlock(new Vector(maxX, y, z), block)) { + affected++; + } } } for (int z = minZ; z <= maxZ; z++) { for (int x = minX; x <= maxX; x++) { - if (setBlock(new Vector(x, minY, z), block)) { affected++; } - if (setBlock(new Vector(x, maxY, z), block)) { affected++; } + if (setBlock(new Vector(x, minY, z), block)) { + affected++; + } + if (setBlock(new Vector(x, maxY, z), block)) { + affected++; + } } } @@ -967,7 +998,7 @@ public class EditSession { /** * Make walls of the region (as if it was a cuboid if it's not). - * + * * @param region * @param block * @return number of blocks affected @@ -989,16 +1020,24 @@ public class EditSession { for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { - if (setBlock(new Vector(x, y, minZ), block)) { affected++; } - if (setBlock(new Vector(x, y, maxZ), block)) { affected++; } + if (setBlock(new Vector(x, y, minZ), block)) { + affected++; + } + if (setBlock(new Vector(x, y, maxZ), block)) { + affected++; + } affected++; } } for (int y = minY; y <= maxY; y++) { for (int z = minZ; z <= maxZ; z++) { - if (setBlock(new Vector(minX, y, z), block)) { affected++; } - if (setBlock(new Vector(maxX, y, z), block)) { affected++; } + if (setBlock(new Vector(minX, y, z), block)) { + affected++; + } + if (setBlock(new Vector(maxX, y, z), block)) { + affected++; + } } } @@ -1017,9 +1056,9 @@ public class EditSession { throws MaxChangedBlocksException { Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); - + int upperY = Math.min(127, max.getBlockY() + 1); - int lowerY = Math.max(0, min.getBlockY()- 1); + int lowerY = Math.max(0, min.getBlockY() - 1); int affected = 0; @@ -1032,7 +1071,7 @@ public class EditSession { for (int z = minZ; z <= maxZ; z++) { for (int y = upperY; y >= lowerY; y--) { Vector above = new Vector(x, y + 1, z); - + if (y + 1 <= 127 && !getBlock(new Vector(x, y, z)).isAir() && getBlock(above).isAir()) { if (setBlock(above, block)) { @@ -1057,9 +1096,8 @@ public class EditSession { * @return number of blocks affected * @throws MaxChangedBlocksException */ - public int stackCuboidRegion(Region region, Vector dir, - int count, boolean copyAir) - throws MaxChangedBlocksException { + public int stackCuboidRegion(Region region, Vector dir, int count, + boolean copyAir) throws MaxChangedBlocksException { int affected = 0; Vector min = region.getMinimumPoint(); @@ -1071,7 +1109,7 @@ public class EditSession { int maxX = max.getBlockX(); int maxY = max.getBlockY(); int maxZ = max.getBlockZ(); - + int xs = region.getWidth(); int ys = region.getHeight(); int zs = region.getLength(); @@ -1083,11 +1121,10 @@ public class EditSession { if (!block.isAir() || copyAir) { for (int i = 1; i <= count; i++) { - Vector pos = new Vector( - x + xs * dir.getBlockX() * i, - y + ys * dir.getBlockY() * i, - z + zs * dir.getBlockZ() * i); - + Vector pos = new Vector(x + xs * dir.getBlockX() + * i, y + ys * dir.getBlockY() * i, z + zs + * dir.getBlockZ() * i); + if (setBlock(pos, block)) { affected++; } @@ -1102,7 +1139,7 @@ public class EditSession { /** * Move a cuboid region. - * + * * @param region * @param dir * @param distance @@ -1111,8 +1148,8 @@ public class EditSession { * @return number of blocks moved * @throws MaxChangedBlocksException */ - public int moveCuboidRegion(Region region, Vector dir, - int distance, boolean copyAir, BaseBlock replace) + public int moveCuboidRegion(Region region, Vector dir, int distance, + boolean copyAir, BaseBlock replace) throws MaxChangedBlocksException { int affected = 0; @@ -1130,7 +1167,7 @@ public class EditSession { Vector newMin = min.add(shift); Vector newMax = min.add(shift); - Map delayed = new LinkedHashMap(); + Map delayed = new LinkedHashMap(); for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { @@ -1146,8 +1183,10 @@ public class EditSession { // Don't want to replace the old block if it's in // the new area if (x >= newMin.getBlockX() && x <= newMax.getBlockX() - && y >= newMin.getBlockY() && y <= newMax.getBlockY() - && z >= newMin.getBlockZ() && z <= newMax.getBlockZ()) { + && y >= newMin.getBlockY() + && y <= newMax.getBlockY() + && z >= newMin.getBlockZ() + && z <= newMax.getBlockZ()) { } else { setBlock(pos, replace); } @@ -1156,7 +1195,7 @@ public class EditSession { } } - for (Map.Entry entry : delayed.entrySet()) { + for (Map.Entry entry : delayed.entrySet()) { setBlock(entry.getKey(), entry.getValue()); affected++; } @@ -1166,13 +1205,14 @@ public class EditSession { /** * Drain nearby pools of water or lava. - * + * * @param pos * @param radius * @return number of blocks affected * @throws MaxChangedBlocksException */ - public int drainArea(Vector pos, int radius) throws MaxChangedBlocksException { + public int drainArea(Vector pos, int radius) + throws MaxChangedBlocksException { int affected = 0; HashSet visited = new HashSet(); @@ -1230,7 +1270,7 @@ public class EditSession { /** * Level water. - * + * * @param pos * @param radius * @return number of blocks affected @@ -1303,10 +1343,10 @@ public class EditSession { * @param block * @throws MaxChangedBlocksException */ - private int makeHCylinderPoints(Vector center, int x, int z, - int height, BaseBlock block) throws MaxChangedBlocksException { + private int makeHCylinderPoints(Vector center, int x, int z, int height, + BaseBlock block) throws MaxChangedBlocksException { int affected = 0; - + if (x == 0) { for (int y = 0; y < height; y++) { setBlock(center.add(0, y, z), block); @@ -1350,8 +1390,8 @@ public class EditSession { * @return number of blocks set * @throws MaxChangedBlocksException */ - public int makeHollowCylinder(Vector pos, BaseBlock block, - int radius, int height) throws MaxChangedBlocksException { + public int makeHollowCylinder(Vector pos, BaseBlock block, int radius, + int height) throws MaxChangedBlocksException { int x = 0; int z = radius; int d = (5 - radius * 4) / 4; @@ -1374,7 +1414,7 @@ public class EditSession { while (x < z) { x++; - + if (d >= 0) { z--; d += 2 * (x - z) + 1; @@ -1390,7 +1430,7 @@ public class EditSession { /** * Helper method to draw the cylinder. - * + * * @param center * @param x * @param z @@ -1398,8 +1438,8 @@ public class EditSession { * @param block * @throws MaxChangedBlocksException */ - private int makeCylinderPoints(Vector center, int x, int z, - int height, BaseBlock block) throws MaxChangedBlocksException { + private int makeCylinderPoints(Vector center, int x, int z, int height, + BaseBlock block) throws MaxChangedBlocksException { int affected = 0; if (x == z) { @@ -1437,8 +1477,8 @@ public class EditSession { * @return number of blocks set * @throws MaxChangedBlocksException */ - public int makeCylinder(Vector pos, BaseBlock block, - int radius, int height) throws MaxChangedBlocksException { + public int makeCylinder(Vector pos, BaseBlock block, int radius, int height) + throws MaxChangedBlocksException { int x = 0; int z = radius; int d = (5 - radius * 4) / 4; @@ -1477,7 +1517,7 @@ public class EditSession { /** * Makes a sphere. - * + * * @param pos * @param block * @param radius @@ -1485,10 +1525,10 @@ public class EditSession { * @return number of blocks changed * @throws MaxChangedBlocksException */ - public int makeSphere(Vector pos, BaseBlock block, int radius, boolean filled) - throws MaxChangedBlocksException { + public int makeSphere(Vector pos, BaseBlock block, int radius, + boolean filled) throws MaxChangedBlocksException { int affected = 0; - + for (int x = 0; x <= radius; x++) { for (int y = 0; y <= radius; y++) { for (int z = 0; z <= radius; z++) { @@ -1496,14 +1536,30 @@ public class EditSession { double d = vec.distance(pos); if (d <= radius + 0.5 && (filled || d >= radius - 0.5)) { - if (setBlock(vec, block)) { affected++; } - if (setBlock(pos.add(-x, y, z), block)) { affected++; } - if (setBlock(pos.add(x, -y, z), block)) { affected++; } - if (setBlock(pos.add(x, y, -z), block)) { affected++; } - if (setBlock(pos.add(-x, -y, z), block)) { affected++; } - if (setBlock(pos.add(x, -y, -z), block)) { affected++; } - if (setBlock(pos.add(-x, y, -z), block)) { affected++; } - if (setBlock(pos.add(-x, -y, -z), block)) { affected++; } + if (setBlock(vec, block)) { + affected++; + } + if (setBlock(pos.add(-x, y, z), block)) { + affected++; + } + if (setBlock(pos.add(x, -y, z), block)) { + affected++; + } + if (setBlock(pos.add(x, y, -z), block)) { + affected++; + } + if (setBlock(pos.add(-x, -y, z), block)) { + affected++; + } + if (setBlock(pos.add(x, -y, -z), block)) { + affected++; + } + if (setBlock(pos.add(-x, y, -z), block)) { + affected++; + } + if (setBlock(pos.add(-x, -y, -z), block)) { + affected++; + } } } } @@ -1514,7 +1570,7 @@ public class EditSession { /** * Make snow. - * + * * @param pos * @param radius * @return number of blocks affected @@ -1536,7 +1592,7 @@ public class EditSession { if ((new Vector(x, oy, z)).distance(pos) > radius) { continue; } - + for (int y = 127; y >= 1; y--) { Vector pt = new Vector(x, y, z); int id = getBlock(pt).getID(); @@ -1555,8 +1611,8 @@ public class EditSession { || id == 53 // Wood steps || id == 55 // Redstone wire || id == 59 // Crops - || (id >= 63 && id <= 72) - || id == 75 // Redstone torch + || (id >= 63 && id <= 72) || id == 75 // Redstone + // torch || id == 76 // Redstone torch || id == 77 // Stone button || id == 78 // Snow @@ -1567,7 +1623,7 @@ public class EditSession { || id == 90) { // Portal break; } - + // Ice! if (id == 8 || id == 9) { if (setBlock(pt, ice)) { @@ -1581,7 +1637,7 @@ public class EditSession { if (y == 127) { // Too high! break; } - + if (setBlock(pt.add(0, 1, 0), snow)) { affected++; } @@ -1593,13 +1649,14 @@ public class EditSession { return affected; } - + /** * Set a block by chance. * * @param pos * @param block - * @param c 0-1 chance + * @param c + * 0-1 chance * @return whether a block was changed */ private boolean setChanceBlockIfAir(Vector pos, BaseBlock block, double c) @@ -1612,15 +1669,15 @@ public class EditSession { /** * Makes a pumpkin patch. - * + * * @param basePos */ private void makePumpkinPatch(Vector basePos) throws MaxChangedBlocksException { - //BaseBlock logBlock = new BaseBlock(17); + // BaseBlock logBlock = new BaseBlock(17); BaseBlock leavesBlock = new BaseBlock(18); - //setBlock(basePos.subtract(0, 1, 0), logBlock); + // setBlock(basePos.subtract(0, 1, 0), logBlock); setBlockIfAir(basePos, leavesBlock); makePumpkinPatchVine(basePos, basePos.add(0, 0, 1)); @@ -1637,8 +1694,10 @@ public class EditSession { */ private void makePumpkinPatchVine(Vector basePos, Vector pos) throws MaxChangedBlocksException { - if (pos.distance(basePos) > 4) return; - if (getBlock(pos).getID() != 0) return; + if (pos.distance(basePos) > 4) + return; + if (getBlock(pos).getID() != 0) + return; for (int i = -1; i > -3; i--) { Vector testPos = pos.add(0, i, 0); @@ -1655,27 +1714,35 @@ public class EditSession { int h = prng.nextInt(3) - 1; if (t == 0) { - if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(1, 0, 0)); - if (prng.nextBoolean()) setBlockIfAir(pos.add(1, h, -1), new BaseBlock(18)); + if (prng.nextBoolean()) + makePumpkinPatchVine(basePos, pos.add(1, 0, 0)); + if (prng.nextBoolean()) + setBlockIfAir(pos.add(1, h, -1), new BaseBlock(18)); setBlockIfAir(pos.add(0, 0, -1), new BaseBlock(86)); } else if (t == 1) { - if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(0, 0, 1)); - if (prng.nextBoolean()) setBlockIfAir(pos.add(1, h, 0), new BaseBlock(18)); + if (prng.nextBoolean()) + makePumpkinPatchVine(basePos, pos.add(0, 0, 1)); + if (prng.nextBoolean()) + setBlockIfAir(pos.add(1, h, 0), new BaseBlock(18)); setBlockIfAir(pos.add(1, 0, 1), new BaseBlock(86)); } else if (t == 2) { - if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(0, 0, -1)); - if (prng.nextBoolean()) setBlockIfAir(pos.add(-1, h, 0), new BaseBlock(18)); + if (prng.nextBoolean()) + makePumpkinPatchVine(basePos, pos.add(0, 0, -1)); + if (prng.nextBoolean()) + setBlockIfAir(pos.add(-1, h, 0), new BaseBlock(18)); setBlockIfAir(pos.add(-1, 0, 1), new BaseBlock(86)); } else if (t == 3) { - if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(-1, 0, 0)); - if (prng.nextBoolean()) setBlockIfAir(pos.add(-1, h, -1), new BaseBlock(18)); + if (prng.nextBoolean()) + makePumpkinPatchVine(basePos, pos.add(-1, 0, 0)); + if (prng.nextBoolean()) + setBlockIfAir(pos.add(-1, h, -1), new BaseBlock(18)); setBlockIfAir(pos.add(-1, 0, -1), new BaseBlock(86)); } } /** * Makes pumpkin patches. - * + * * @param basePos * @param size * @return number of trees created @@ -1684,13 +1751,17 @@ public class EditSession { throws MaxChangedBlocksException { int affected = 0; - for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + size; x++) { - for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + size; z++) { + for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + + size; x++) { + for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + + size; z++) { // Don't want to be in the ground if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir()) continue; // The gods don't want a pumpkin patch here - if (Math.random() < 0.98) { continue; } + if (Math.random() < 0.98) { + continue; + } for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; y--) { // Check if we hit the ground @@ -1721,14 +1792,18 @@ public class EditSession { public int makeForest(Vector basePos, int size, double density, boolean pineTree) throws MaxChangedBlocksException { int affected = 0; - - for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + size; x++) { - for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + size; z++) { + + for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + + size; x++) { + for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + + size; z++) { // Don't want to be in the ground if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir()) continue; // The gods don't want a tree here - if (Math.random() >= density) { continue; } // def 0.05 + if (Math.random() >= density) { + continue; + } // def 0.05 for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; y--) { // Check if we hit the ground @@ -1737,7 +1812,8 @@ public class EditSession { if (pineTree) { makePineTree(new Vector(x, y + 1, z)); } else { - server.generateTree(this, new Vector(x, y + 1, z)); + server.generateTree(this, world, + new Vector(x, y + 1, z)); } affected++; break; @@ -1753,13 +1829,12 @@ public class EditSession { /** * Makes a terrible looking pine tree. - * + * * @param basePos */ - private void makePineTree(Vector basePos) - throws MaxChangedBlocksException { - int trunkHeight = (int)Math.floor(Math.random() * 2) + 3; - int height = (int)Math.floor(Math.random() * 5) + 8; + private void makePineTree(Vector basePos) throws MaxChangedBlocksException { + int trunkHeight = (int) Math.floor(Math.random() * 2) + 3; + int height = (int) Math.floor(Math.random() * 5) + 8; BaseBlock logBlock = new BaseBlock(17); BaseBlock leavesBlock = new BaseBlock(18); @@ -1812,7 +1887,7 @@ public class EditSession { /** * Count the number of blocks of a list of types in a region. - * + * * @param region * @param searchIDs * @return @@ -1861,10 +1936,8 @@ public class EditSession { * @return */ public List> getBlockDistribution(Region region) { - List> distribution - = new ArrayList>(); - Map> map = - new HashMap>(); + List> distribution = new ArrayList>(); + Map> map = new HashMap>(); if (region instanceof CuboidRegion) { // Doing this for speed @@ -1909,23 +1982,25 @@ public class EditSession { } Collections.sort(distribution); - //Collections.reverse(distribution); + // Collections.reverse(distribution); return distribution; } - + /** * Returns the highest solid 'terrain' block which can occur naturally. * Looks at: 1, 2, 3, 7, 12, 13, 14, 15, 16, 56, 73, 74, 87, 88, 89 * * @param x * @param z - * @param minY minimal height - * @param maxY maximal height + * @param minY + * minimal height + * @param maxY + * maximal height * @return height of highest block found or 'minY' */ - public int getHighestTerrainBlock( int x , int z, int minY, int maxY) { + public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { for (int y = maxY; y >= minY; y--) { Vector pt = new Vector(x, y, z); int id = getBlock(pt).getID(); @@ -1953,7 +2028,7 @@ public class EditSession { } return minY; } - + /** * Gets the list of missing blocks and clears the list for the next * operation. @@ -1974,7 +2049,8 @@ public class EditSession { } /** - * @param blockBag the blockBag to set + * @param blockBag + * the blockBag to set */ public void setBlockBag(BlockBag blockBag) { this.blockBag = blockBag; diff --git a/src/com/sk89q/worldedit/LocalWorld.java b/src/com/sk89q/worldedit/LocalWorld.java new file mode 100644 index 000000000..74bda7fef --- /dev/null +++ b/src/com/sk89q/worldedit/LocalWorld.java @@ -0,0 +1,41 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit; + +/** + * Represents a world. + * + * @author sk89q + */ +public abstract class LocalWorld { + /** + * Compare if the other world is equal. + * + * @param other + * @return + */ + public abstract boolean equals(Object other); + /** + * Hash code. + * + * @return + */ + public abstract int hashCode(); +} diff --git a/src/com/sk89q/worldedit/ServerInterface.java b/src/com/sk89q/worldedit/ServerInterface.java index 851213f3c..9934e69bc 100644 --- a/src/com/sk89q/worldedit/ServerInterface.java +++ b/src/com/sk89q/worldedit/ServerInterface.java @@ -15,113 +15,92 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . -*/ + */ package com.sk89q.worldedit; import com.sk89q.worldedit.blocks.BaseItemStack; /** - * + * * @author sk89q */ public abstract class ServerInterface { - /** - * Instance. - */ - private static ServerInterface instance; - - /** - * Get the current instance. - * - * @return - */ - public static ServerInterface getInstance() { - return instance; - } - - /** - * Set up an instance. - * @param instance - */ - public static void setup(ServerInterface instance) { - ServerInterface.instance = instance; - } - /** * Set block type. - * + * * @param pt * @param type * @return */ - public abstract boolean setBlockType(Vector pt, int type); - + public abstract boolean setBlockType(LocalWorld world, Vector pt, int type); + /** * Get block type. - * + * * @param pt * @return */ - public abstract int getBlockType(Vector pt); + public abstract int getBlockType(LocalWorld world, Vector pt); /** * Set block data. - * + * * @param pt * @param data * @return */ - public abstract void setBlockData(Vector pt, int data); + public abstract void setBlockData(LocalWorld world, Vector pt, int data); /** * Get block data. - * + * * @param pt * @return */ - public abstract int getBlockData(Vector pt); - + public abstract int getBlockData(LocalWorld world, Vector pt); + /** * Set sign text. - * + * * @param pt * @param text */ - public abstract void setSignText(Vector pt, String[] text); - + public abstract void setSignText(LocalWorld world, Vector pt, String[] text); + /** * Get sign text. - * + * * @param pt * @return */ - public abstract String[] getSignText(Vector pt); + public abstract String[] getSignText(LocalWorld world, Vector pt); /** * Gets the contents of chests. Will return null if the chest does not * really exist or it is the second block for a double chest. - * + * * @param pt * @return */ - public abstract BaseItemStack[] getChestContents(Vector pt); + public abstract BaseItemStack[] getChestContents(LocalWorld world, Vector pt); /** * Sets a chest slot. - * + * * @param pt * @param contents * @return */ - public abstract boolean setChestContents(Vector pt, BaseItemStack[] contents); + public abstract boolean setChestContents(LocalWorld world, Vector pt, + BaseItemStack[] contents); /** * Clear a chest's contents. * * @param pt */ - public abstract boolean clearChest(Vector pt); + public abstract boolean clearChest(LocalWorld world, Vector pt); /** * Checks if a mob type is valid. @@ -133,19 +112,20 @@ public abstract class ServerInterface { /** * Set mob spawner mob type. - * + * * @param pt * @param mobType */ - public abstract void setMobSpawnerType(Vector pt, String mobType); + public abstract void setMobSpawnerType(LocalWorld world, Vector pt, + String mobType); /** * Get mob spawner mob type. May return an empty string. - * + * * @param pt * @param mobType */ - public abstract String getMobSpawnerType(Vector pt); + public abstract String getMobSpawnerType(LocalWorld world, Vector pt); /** * Generate a tree at a location. @@ -153,45 +133,48 @@ public abstract class ServerInterface { * @param pt * @return */ - public abstract boolean generateTree(EditSession editSession, Vector pt); + public abstract boolean generateTree(EditSession editSession, + LocalWorld world, Vector pt); /** * Drop an item. - * + * * @param pt * @param type * @param count * @param times */ - public abstract void dropItem(Vector pt, int type, int count, int times); + public abstract void dropItem(LocalWorld world, Vector pt, int type, + int count, int times); /** * Drop an item. - * + * * @param pt * @param type * @param count * @param times */ - public abstract void dropItem(Vector pt, int type, int count); + public abstract void dropItem(LocalWorld world, Vector pt, int type, + int count); /** * Drop an item. - * + * * @param pt * @param type * @param count * @param times */ - public abstract void dropItem(Vector pt, int type); + public abstract void dropItem(LocalWorld world, Vector pt, int type); /** * Simulate a block being mined. * * @param pt */ - public abstract void simulateBlockMine(Vector pt); - + public abstract void simulateBlockMine(LocalWorld world, Vector pt); + /** * Resolves an item name to its ID. * @@ -207,5 +190,5 @@ public abstract class ServerInterface { * @param radius * @return */ - public abstract int killMobs(Vector origin, int radius); + public abstract int killMobs(LocalWorld world, Vector origin, int radius); } diff --git a/src/com/sk89q/worldedit/Vector.java b/src/com/sk89q/worldedit/Vector.java index f7126be4d..a499e4d07 100644 --- a/src/com/sk89q/worldedit/Vector.java +++ b/src/com/sk89q/worldedit/Vector.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit; /** * - * @author Albert + * @author sk89q */ public class Vector { protected final double x, y, z; diff --git a/src/com/sk89q/worldedit/WorldEditController.java b/src/com/sk89q/worldedit/WorldEditController.java index b63037a80..cf3b11de5 100644 --- a/src/com/sk89q/worldedit/WorldEditController.java +++ b/src/com/sk89q/worldedit/WorldEditController.java @@ -95,10 +95,12 @@ public class WorldEditController { public boolean useInventoryOverride = false; /** - * Construct an instance of the plugin. + * Construct an instance of the plugin + * + * @param server */ - public WorldEditController() { - server = ServerInterface.getInstance(); + public WorldEditController(ServerInterface server) { + this.server = server; // Note: Commands should only have the phrase 'air' at the end // for now (see SMWorldEditListener.canUseCommand) @@ -442,9 +444,9 @@ public class WorldEditController { // Jump to the block in sight } else if (split[0].equalsIgnoreCase("/jumpto")) { checkArgs(split, 0, 0, split[0]); - Vector pos = player.getSolidBlockTrace(300); + WorldVector pos = player.getSolidBlockTrace(300); if (pos != null) { - player.findFreePosition(pos); + player.findFreePosition(pos.getWorld(), pos); player.print("Poof!"); } else { player.printError("No block in sight!"); @@ -1323,7 +1325,7 @@ public class WorldEditController { Math.max(1, Integer.parseInt(split[1])) : -1; Vector origin = session.getPlacementPosition(player); - int killed = server.killMobs(origin, radius); + int killed = server.killMobs(player.getWorld(), origin, radius); player.print("Killed " + killed + " mobs."); return true; @@ -1732,10 +1734,10 @@ public class WorldEditController { } else if (player.isHoldingPickAxe() && session.getTool() == WorldEditSession.Tool.TREE) { EditSession editSession = - new EditSession(session.getBlockChangeLimit()); + new EditSession(server, player.getWorld(), session.getBlockChangeLimit()); try { - if (!server.generateTree(editSession, clicked)) { + if (!server.generateTree(editSession, player.getWorld(), clicked)) { player.printError("Notch won't let you put a tree there."); } } finally { @@ -1745,7 +1747,7 @@ public class WorldEditController { return true; } else if (player.isHoldingPickAxe() && session.getTool() == WorldEditSession.Tool.INFO) { - BaseBlock block = (new EditSession(0)).rawGetBlock(clicked); + BaseBlock block = (new EditSession(server, player.getWorld(), 0)).rawGetBlock(clicked); player.print("\u00A79@" + clicked + ": " + "\u00A7e" + "Type: " + block.getID() + "\u00A77" + " (" @@ -1805,20 +1807,22 @@ public class WorldEditController { } else if (player.isHoldingPickAxe()) { if (session.hasSuperPickAxe()) { boolean canBedrock = canUseCommand(player, "/worldeditbedrock"); + + LocalWorld world = player.getWorld(); // Single block super pickaxe if (session.getSuperPickaxeMode() == WorldEditSession.SuperPickaxeMode.SINGLE) { - if (server.getBlockType(clicked) == 7 && !canBedrock) { + if (server.getBlockType(world, clicked) == 7 && !canBedrock) { return true; - } else if (server.getBlockType(clicked) == 46) { + } else if (server.getBlockType(world, clicked) == 46) { return false; } if (superPickaxeDrop) { - server.simulateBlockMine(clicked); + server.simulateBlockMine(world, clicked); } else { - server.setBlockType(clicked, 0); + server.setBlockType(world, clicked, 0); } // Area super pickaxe @@ -1828,7 +1832,7 @@ public class WorldEditController { int oy = clicked.getBlockY(); int oz = clicked.getBlockZ(); int size = session.getSuperPickaxeRange(); - int initialType = server.getBlockType(clicked); + int initialType = server.getBlockType(world, clicked); if (initialType == 7 && !canBedrock) { return true; @@ -1838,11 +1842,11 @@ public class WorldEditController { for (int y = oy - size; y <= oy + size; y++) { for (int z = oz - size; z <= oz + size; z++) { Vector pos = new Vector(x, y, z); - if (server.getBlockType(pos) == initialType) { + if (server.getBlockType(world, pos) == initialType) { if (superPickaxeManyDrop) { - server.simulateBlockMine(pos); + server.simulateBlockMine(world, pos); } else { - server.setBlockType(pos, 0); + server.setBlockType(world, pos, 0); } } } @@ -1855,13 +1859,13 @@ public class WorldEditController { } else if (session.getSuperPickaxeMode() == WorldEditSession.SuperPickaxeMode.SAME_TYPE_RECURSIVE) { int size = session.getSuperPickaxeRange(); - int initialType = server.getBlockType(clicked); + int initialType = server.getBlockType(world, clicked); if (initialType == 7 && !canBedrock) { return true; } - recursiveSuperPickaxe(clicked.toBlockVector(), clicked, size, + recursiveSuperPickaxe(world, clicked.toBlockVector(), clicked, size, initialType, new HashSet()); return true; @@ -1881,7 +1885,7 @@ public class WorldEditController { * @param canBedrock * @return */ - private void recursiveSuperPickaxe(BlockVector pos, Vector origin, + private void recursiveSuperPickaxe(LocalWorld world, BlockVector pos, Vector origin, int size, int initialType, Set visited) { if (origin.distance(pos) > size || visited.contains(pos)) { return; @@ -1889,27 +1893,27 @@ public class WorldEditController { visited.add(pos); - if (server.getBlockType(pos) == initialType) { + if (server.getBlockType(world, pos) == initialType) { if (superPickaxeManyDrop) { - server.simulateBlockMine(pos); + server.simulateBlockMine(world, pos); } else { - server.setBlockType(pos, 0); + server.setBlockType(world, pos, 0); } } else { return; } - recursiveSuperPickaxe(pos.add(1, 0, 0).toBlockVector(), origin, size, + recursiveSuperPickaxe(world, pos.add(1, 0, 0).toBlockVector(), origin, size, initialType, visited); - recursiveSuperPickaxe(pos.add(-1, 0, 0).toBlockVector(), origin, size, + recursiveSuperPickaxe(world, pos.add(-1, 0, 0).toBlockVector(), origin, size, initialType, visited); - recursiveSuperPickaxe(pos.add(0, 0, 1).toBlockVector(), origin, size, + recursiveSuperPickaxe(world, pos.add(0, 0, 1).toBlockVector(), origin, size, initialType, visited); - recursiveSuperPickaxe(pos.add(0, 0, -1).toBlockVector(), origin, size, + recursiveSuperPickaxe(world, pos.add(0, 0, -1).toBlockVector(), origin, size, initialType, visited); - recursiveSuperPickaxe(pos.add(0, 1, 0).toBlockVector(), origin, size, + recursiveSuperPickaxe(world, pos.add(0, 1, 0).toBlockVector(), origin, size, initialType, visited); - recursiveSuperPickaxe(pos.add(0, -1, 0).toBlockVector(), origin, size, + recursiveSuperPickaxe(world, pos.add(0, -1, 0).toBlockVector(), origin, size, initialType, visited); } @@ -1943,7 +1947,8 @@ public class WorldEditController { BlockBag blockBag = session.getBlockBag(player); EditSession editSession = - new EditSession(session.getBlockChangeLimit(), blockBag); + new EditSession(server, player.getWorld(), + session.getBlockChangeLimit(), blockBag); editSession.enableQueue(); long start = System.currentTimeMillis(); diff --git a/src/com/sk89q/worldedit/WorldEditPlayer.java b/src/com/sk89q/worldedit/WorldEditPlayer.java index bca863620..706d7e649 100644 --- a/src/com/sk89q/worldedit/WorldEditPlayer.java +++ b/src/com/sk89q/worldedit/WorldEditPlayer.java @@ -48,9 +48,11 @@ public abstract class WorldEditPlayer { /** * Construct the object. + * + * @param server */ - protected WorldEditPlayer() { - server = ServerInterface.getInstance(); + protected WorldEditPlayer(ServerInterface server) { + this.server = server; } /** @@ -72,7 +74,7 @@ public abstract class WorldEditPlayer { * * @param searchPos search position */ - public void findFreePosition(Vector searchPos) { + public void findFreePosition(LocalWorld world, Vector searchPos) { int x = searchPos.getBlockX(); int y = Math.max(0, searchPos.getBlockY()); int origY = y; @@ -81,7 +83,8 @@ public abstract class WorldEditPlayer { byte free = 0; while (y <= 129) { - if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) { + if (BlockType.canPassThrough(server.getBlockType(world, + new Vector(x, y, z)))) { free++; } else { free = 0; @@ -106,7 +109,7 @@ public abstract class WorldEditPlayer { * that free position. */ public void findFreePosition() { - findFreePosition(getBlockIn()); + findFreePosition(getPosition().getWorld(), getBlockIn()); } /** @@ -119,12 +122,13 @@ public abstract class WorldEditPlayer { int x = pos.getBlockX(); int y = Math.max(0, pos.getBlockY()); int z = pos.getBlockZ(); + LocalWorld world = getPosition().getWorld(); byte free = 0; byte spots = 0; while (y <= 129) { - if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) { + if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) { free++; } else { free = 0; @@ -133,7 +137,7 @@ public abstract class WorldEditPlayer { if (free == 2) { spots++; if (spots == 2) { - int type = server.getBlockType(new Vector(x, y - 2, z)); + int type = server.getBlockType(world, new Vector(x, y - 2, z)); // Don't get put in lava! if (type == 10 || type == 11) { @@ -161,11 +165,12 @@ public abstract class WorldEditPlayer { int x = pos.getBlockX(); int y = Math.max(0, pos.getBlockY() - 1); int z = pos.getBlockZ(); + LocalWorld world = getPosition().getWorld(); byte free = 0; while (y >= 1) { - if (BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) { + if (BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) { free++; } else { free = 0; @@ -176,7 +181,7 @@ public abstract class WorldEditPlayer { // lightly and also check to see if there's something to // stand upon while (y >= 0) { - int type = server.getBlockType(new Vector(x, y, z)); + int type = server.getBlockType(world, new Vector(x, y, z)); // Don't want to end up in lava if (type != 0 && type != 10 && type != 11) { @@ -209,17 +214,18 @@ public abstract class WorldEditPlayer { int initialY = Math.max(0, pos.getBlockY()); int y = Math.max(0, pos.getBlockY() + 2); int z = pos.getBlockZ(); + LocalWorld world = getPosition().getWorld(); // No free space above - if (server.getBlockType(new Vector(x, y, z)) != 0) { + if (server.getBlockType(world, new Vector(x, y, z)) != 0) { return false; } while (y <= 127) { // Found a ceiling! - if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) { + if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) { int platformY = Math.max(initialY, y - 3 - clearance); - server.setBlockType(new Vector(x, platformY, z), + server.setBlockType(world, new Vector(x, platformY, z), BlockType.GLASS.getID()); setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5)); return true; @@ -244,14 +250,15 @@ public abstract class WorldEditPlayer { int y = Math.max(0, pos.getBlockY() + 1); int z = pos.getBlockZ(); int maxY = Math.min(128, initialY + distance); + LocalWorld world = getPosition().getWorld(); while (y <= 129) { - if (!BlockType.canPassThrough(server.getBlockType(new Vector(x, y, z)))) { + if (!BlockType.canPassThrough(server.getBlockType(world, new Vector(x, y, z)))) { break; // Hit something } else if (y > maxY + 1) { break; } else if (y == maxY + 1) { - server.setBlockType(new Vector(x, y - 2, z), + server.setBlockType(world, new Vector(x, y - 2, z), BlockType.GLASS.getID()); setPosition(new Vector(x + 0.5, y - 1, z + 0.5)); return true; @@ -268,8 +275,8 @@ public abstract class WorldEditPlayer { * * @return point */ - public Vector getBlockIn() { - return getPosition().toBlockVector(); + public WorldVector getBlockIn() { + return getPosition(); } /** @@ -277,8 +284,9 @@ public abstract class WorldEditPlayer { * * @return point */ - public Vector getBlockOn() { - return getPosition().subtract(0, 1, 0).toBlockVector(); + public WorldVector getBlockOn() { + WorldVector pos = getPosition(); + return new WorldVector(pos.getWorld(), pos.subtract(0, 1, 0)); } /** @@ -287,7 +295,7 @@ public abstract class WorldEditPlayer { * @param range * @return point */ - public abstract Vector getBlockTrace(int range); + public abstract WorldVector getBlockTrace(int range); /** * Get the point of the block being looked at. May return null. @@ -295,7 +303,7 @@ public abstract class WorldEditPlayer { * @param range * @return point */ - public abstract Vector getSolidBlockTrace(int range); + public abstract WorldVector getSolidBlockTrace(int range); /** * Get the player's cardinal direction (N, W, NW, etc.). May return null. @@ -360,7 +368,14 @@ public abstract class WorldEditPlayer { * * @return point */ - public abstract Vector getPosition(); + public abstract WorldVector getPosition(); + + /** + * Get the player's world. + * + * @return point + */ + public abstract LocalWorld getWorld(); /** * Get the player's view pitch. diff --git a/src/com/sk89q/worldedit/WorldVector.java b/src/com/sk89q/worldedit/WorldVector.java new file mode 100644 index 000000000..469cba030 --- /dev/null +++ b/src/com/sk89q/worldedit/WorldVector.java @@ -0,0 +1,104 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit; + +/** + * A vector with a world component. + * + * @author sk89q + */ +public class WorldVector extends Vector { + /** + * Represents the world. + */ + private LocalWorld world; + + /** + * Construct the Vector object. + * + * @param x + * @param y + * @param z + */ + public WorldVector(LocalWorld world, double x, double y, double z) { + super(x, y, z); + this.world = world; + } + + /** + * Construct the Vector object. + * + * @param x + * @param y + * @param z + */ + public WorldVector(LocalWorld world, int x, int y, int z) { + super(x, y, z); + this.world = world; + } + + /** + * Construct the Vector object. + * + * @param x + * @param y + * @param z + */ + public WorldVector(LocalWorld world, float x, float y, float z) { + super(x, y, z); + this.world = world; + } + + /** + * Construct the Vector object. + * + * @param pt + */ + public WorldVector(LocalWorld world, Vector pt) { + super(pt); + this.world = world; + } + + /** + * Construct the Vector object. + */ + public WorldVector(LocalWorld world) { + super(); + this.world = world; + } + + /** + * Get the world. + * + * @return + */ + public LocalWorld getWorld() { + return world; + } + + /** + * Gets a BlockVector version. + * + * @return BlockWorldVector + */ + public BlockWorldVector toWorldBlockVector() { + return new BlockWorldVector(this); + } +}