Cleaned up some code, changed WorldEdit to be world-aware (finally).

Dieser Commit ist enthalten in:
sk89q 2011-01-01 10:33:18 -08:00
Ursprung 6d172891e2
Commit ac4e6e8ddf
12 geänderte Dateien mit 783 neuen und 442 gelöschten Zeilen

Datei anzeigen

@ -17,9 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface; import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditPlayer; import com.sk89q.worldedit.WorldEditPlayer;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.BlockType;
@ -38,8 +40,8 @@ public class HMPlayer extends WorldEditPlayer {
* *
* @param player * @param player
*/ */
public HMPlayer(Player player) { public HMPlayer(ServerInterface server, Player player) {
super(); super(server);
this.player = player; this.player = player;
} }
@ -58,13 +60,13 @@ public class HMPlayer extends WorldEditPlayer {
* @param range * @param range
* @return point * @return point
*/ */
public Vector getBlockTrace(int range) { public WorldVector getBlockTrace(int range) {
HitBlox hitBlox = new HitBlox(player,range, 0.2); HitBlox hitBlox = new HitBlox(player,range, 0.2);
Block block = hitBlox.getTargetBlock(); Block block = hitBlox.getTargetBlock();
if (block == null) { if (block == null) {
return 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 * @param range
* @return point * @return point
*/ */
public Vector getSolidBlockTrace(int range) { public WorldVector getSolidBlockTrace(int range) {
HitBlox hitBlox = new HitBlox(player,range, 0.2); HitBlox hitBlox = new HitBlox(player,range, 0.2);
Block block = null; Block block = null;
@ -85,7 +87,7 @@ public class HMPlayer extends WorldEditPlayer {
if (block == null) { if (block == null) {
return 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 * @return point
*/ */
public Vector getPosition() { public WorldVector getPosition() {
return new Vector(player.getX(), player.getY(), player.getZ()); 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; boolean foundNext = false;
int searchDist = 0; int searchDist = 0;
HitBlox hitBlox = new HitBlox(player,range, 0.2); HitBlox hitBlox = new HitBlox(player,range, 0.2);
LocalWorld world = getPosition().getWorld();
Block block; Block block;
while ((block = hitBlox.getNextBlock()) != null) { while ((block = hitBlox.getNextBlock()) != null) {
searchDist++; searchDist++;
@ -183,7 +195,7 @@ public class HMPlayer extends WorldEditPlayer {
if (block.getType() == 0) { if (block.getType() == 0) {
if (foundNext) { if (foundNext) {
Vector v = new Vector(block.getX(), block.getY() - 1, block.getZ()); 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)); setPosition(v.add(0.5, 0, 0.5));
return true; return true;
} }

Datei anzeigen

@ -43,7 +43,7 @@ public class HMServerInterface extends ServerInterface {
* @param type * @param type
* @return * @return
*/ */
public boolean setBlockType(Vector pt, int type) { public boolean setBlockType(LocalWorld world, Vector pt, int type) {
// Can't set colored cloth or crash // Can't set colored cloth or crash
if ((type >= 21 && type <= 34) || type == 36) { if ((type >= 21 && type <= 34) || type == 36) {
return false; return false;
@ -58,7 +58,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public int getBlockType(Vector pt) { public int getBlockType(LocalWorld world, Vector pt) {
return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(), return etc.getServer().getBlockIdAt(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ()); pt.getBlockZ());
} }
@ -70,7 +70,7 @@ public class HMServerInterface extends ServerInterface {
* @param data * @param data
* @return * @return
*/ */
public void setBlockData(Vector pt, int data) { public void setBlockData(LocalWorld world, Vector pt, int data) {
etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(), etc.getServer().setBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ(), data); pt.getBlockZ(), data);
} }
@ -81,7 +81,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public int getBlockData(Vector pt) { public int getBlockData(LocalWorld world, Vector pt) {
return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(), return etc.getServer().getBlockData(pt.getBlockX(), pt.getBlockY(),
pt.getBlockZ()); pt.getBlockZ());
} }
@ -92,7 +92,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @param text * @param text
*/ */
public void setSignText(Vector pt, String[] text) { public void setSignText(LocalWorld world, Vector pt, String[] text) {
Sign signData = (Sign)etc.getServer().getComplexBlock( Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) { if (signData == null) {
@ -110,7 +110,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public String[] getSignText(Vector pt) { public String[] getSignText(LocalWorld world, Vector pt) {
Sign signData = (Sign)etc.getServer().getComplexBlock( Sign signData = (Sign)etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (signData == null) { if (signData == null) {
@ -130,7 +130,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public BaseItemStack[] getChestContents(Vector pt) { public BaseItemStack[] getChestContents(LocalWorld world, Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock( ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
@ -165,7 +165,7 @@ public class HMServerInterface extends ServerInterface {
* @param contents * @param contents
* @return * @return
*/ */
public boolean setChestContents(Vector pt, public boolean setChestContents(LocalWorld world, Vector pt,
BaseItemStack[] contents) { BaseItemStack[] contents) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock( ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
@ -197,7 +197,7 @@ public class HMServerInterface extends ServerInterface {
* *
* @param pt * @param pt
*/ */
public boolean clearChest(Vector pt) { public boolean clearChest(LocalWorld world, Vector pt) {
ComplexBlock cblock = etc.getServer().getOnlyComplexBlock( ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
@ -247,7 +247,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @param mobType * @param mobType
*/ */
public void setMobSpawnerType(Vector pt, String mobType) { public void setMobSpawnerType(LocalWorld world, Vector pt, String mobType) {
ComplexBlock cblock = etc.getServer().getComplexBlock( ComplexBlock cblock = etc.getServer().getComplexBlock(
pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
@ -266,7 +266,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @param mobType * @param mobType
*/ */
public String getMobSpawnerType(Vector pt) { public String getMobSpawnerType(LocalWorld world, Vector pt) {
try { try {
return MinecraftServerInterface.getMobSpawnerType(pt); return MinecraftServerInterface.getMobSpawnerType(pt);
} catch (Throwable t) { } catch (Throwable t) {
@ -282,7 +282,7 @@ public class HMServerInterface extends ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public boolean generateTree(EditSession editSession, Vector pt) { public boolean generateTree(EditSession editSession, LocalWorld world, Vector pt) {
try { try {
return MinecraftServerInterface.generateTree(editSession, pt); return MinecraftServerInterface.generateTree(editSession, pt);
} catch (Throwable t) { } catch (Throwable t) {
@ -300,7 +300,7 @@ public class HMServerInterface extends ServerInterface {
* @param count * @param count
* @param times * @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++) { for (int i = 0; i < times; i++) {
etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count); type, count);
@ -315,7 +315,7 @@ public class HMServerInterface extends ServerInterface {
* @param count * @param count
* @param times * @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(), etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, count); type, count);
} }
@ -328,7 +328,7 @@ public class HMServerInterface extends ServerInterface {
* @param count * @param count
* @param times * @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(), etc.getServer().dropItem(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(),
type, 1); type, 1);
} }
@ -338,57 +338,57 @@ public class HMServerInterface extends ServerInterface {
* *
* @param pt * @param pt
*/ */
public void simulateBlockMine(Vector pt) { public void simulateBlockMine(LocalWorld world, Vector pt) {
int type = getBlockType(pt); int type = getBlockType(world, pt);
setBlockType(pt, 0); setBlockType(world, pt, 0);
if (type == 1) { dropItem(pt, 4); } // Stone if (type == 1) { dropItem(world, pt, 4); } // Stone
else if (type == 2) { dropItem(pt, 3); } // Grass else if (type == 2) { dropItem(world, pt, 3); } // Grass
else if (type == 7) { } // Bedrock else if (type == 7) { } // Bedrock
else if (type == 8) { } // Water else if (type == 8) { } // Water
else if (type == 9) { } // Water else if (type == 9) { } // Water
else if (type == 10) { } // Lava else if (type == 10) { } // Lava
else if (type == 11) { } // Lava else if (type == 11) { } // Lava
else if (type == 13) { // Gravel else if (type == 13) { // Gravel
dropItem(pt, type); dropItem(world, pt, type);
if (random.nextDouble() >= 0.9) { 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 else if (type == 18) { // Leaves
if (random.nextDouble() > 0.95) { if (random.nextDouble() > 0.95) {
dropItem(pt, 6); dropItem(world, pt, 6);
} }
} }
else if (type == 20) { } // Glass 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 == 47) { } // Bookshelves
else if (type == 51) { } // Fire else if (type == 51) { } // Fire
else if (type == 52) { } // Mob spawner else if (type == 52) { } // Mob spawner
else if (type == 53) { dropItem(pt, 5); } // Wooden stairs else if (type == 53) { dropItem(world, pt, 5); } // Wooden stairs
else if (type == 55) { dropItem(pt, 331); } // Redstone wire else if (type == 55) { dropItem(world, pt, 331); } // Redstone wire
else if (type == 56) { dropItem(pt, 264); } // Diamond ore else if (type == 56) { dropItem(world, pt, 264); } // Diamond ore
else if (type == 59) { dropItem(pt, 295); } // Crops else if (type == 59) { dropItem(world, pt, 295); } // Crops
else if (type == 60) { dropItem(pt, 3); } // Soil else if (type == 60) { dropItem(world, pt, 3); } // Soil
else if (type == 62) { dropItem(pt, 61); } // Furnace else if (type == 62) { dropItem(world, pt, 61); } // Furnace
else if (type == 63) { dropItem(pt, 323); } // Sign post else if (type == 63) { dropItem(world, pt, 323); } // Sign post
else if (type == 64) { dropItem(pt, 324); } // Wood door else if (type == 64) { dropItem(world, pt, 324); } // Wood door
else if (type == 67) { dropItem(pt, 4); } // Cobblestone stairs else if (type == 67) { dropItem(world, pt, 4); } // Cobblestone stairs
else if (type == 68) { dropItem(pt, 323); } // Wall sign else if (type == 68) { dropItem(world, pt, 323); } // Wall sign
else if (type == 71) { dropItem(pt, 330); } // Iron door else if (type == 71) { dropItem(world, pt, 330); } // Iron door
else if (type == 73) { dropItem(pt, 331, 1, 4); } // Redstone ore else if (type == 73) { dropItem(world, pt, 331, 1, 4); } // Redstone ore
else if (type == 74) { dropItem(pt, 331, 1, 4); } // Glowing redstone ore else if (type == 74) { dropItem(world, pt, 331, 1, 4); } // Glowing redstone ore
else if (type == 75) { dropItem(pt, 76); } // Redstone torch else if (type == 75) { dropItem(world, pt, 76); } // Redstone torch
else if (type == 78) { } // Snow else if (type == 78) { } // Snow
else if (type == 79) { } // Ice else if (type == 79) { } // Ice
else if (type == 82) { dropItem(pt, 337, 1, 4); } // Clay else if (type == 82) { dropItem(world, pt, 337, 1, 4); } // Clay
else if (type == 83) { dropItem(pt, 338); } // Reed else if (type == 83) { dropItem(world, pt, 338); } // Reed
else if (type == 89) { dropItem(pt, 348); } // Lightstone else if (type == 89) { dropItem(world, pt, 348); } // Lightstone
else if (type == 90) { } // Portal else if (type == 90) { } // Portal
else if (type != 0) { else if (type != 0) {
dropItem(pt, type); dropItem(world, pt, type);
} }
} }
@ -409,7 +409,7 @@ public class HMServerInterface extends ServerInterface {
* @param radius * @param radius
* @return * @return
*/ */
public int killMobs(Vector origin, int radius) { public int killMobs(LocalWorld world, Vector origin, int radius) {
int killed = 0; int killed = 0;
for (Mob mob : etc.getServer().getMobList()) { for (Mob mob : etc.getServer().getMobList()) {

Datei anzeigen

@ -17,11 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import java.util.List;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -29,16 +25,10 @@ import java.util.logging.Handler;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import java.io.*; import java.io.*;
import com.sk89q.worldedit.*; 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.snapshots.*;
import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.patterns.*;
/** /**
* Plugin base. * The event listener for WorldEdit in hMod.
* *
* @author sk89q * @author sk89q
*/ */
@ -47,23 +37,36 @@ public class HMWorldEditListener extends PluginListener {
* Logger. * Logger.
*/ */
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/** /**
* WorldEditLibrary's properties file. * Properties file.
*/ */
private PropertiesFile properties; private PropertiesFile properties;
/** /**
* Main WorldEdit controller. * 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 * @param player
*/ */
@Override @Override
public void onDisconnect(Player player) { 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 * @param player
*/ */
public void onArmSwing(Player 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(), Vector pos = new Vector(blockClicked.getX(),
blockClicked.getY(), blockClicked.getY(),
blockClicked.getZ()); 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(), Vector pos = new Vector(blockClicked.getX(),
blockClicked.getY(), blockClicked.getY(),
blockClicked.getZ()); 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 @Override
public boolean onCommand(Player player, String[] split) { 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 * @return
*/ */
public WorldEditSession _bridgeSession(Player player) { 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);
} }
} }

Datei anzeigen

@ -15,7 +15,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,21 +31,27 @@ public class WorldEdit extends Plugin {
/** /**
* Logger. * Logger.
*/ */
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); private static final Logger logger = Logger
/** .getLogger("Minecraft.WorldEdit");
* WorldEditLibrary instance.
*/
private static HMWorldEditListener listener;
/** /**
* WorldEdit version, fetched from the .jar's manifest. Used to print the * The event listener for WorldEdit an hMod. Configuration and such is
* WorldEdit version in various places. * 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; private String version;
/**
* Construct an instance of the plugin.
*/
public WorldEdit() { public WorldEdit() {
ServerInterface.setup(new HMServerInterface()); listener = new HMWorldEditListener(new HMServerInterface());
listener = new HMWorldEditListener();
} }
/** /**
@ -117,13 +123,4 @@ public class WorldEdit extends Plugin {
return version; return version;
} }
/**
* Returns the listener.
*
* @return
*/
public HMWorldEditListener getListener() {
return listener;
}
} }

Datei anzeigen

@ -0,0 +1,101 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

Datei anzeigen

@ -15,7 +15,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit; package com.sk89q.worldedit;
@ -29,7 +29,6 @@ import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Random; import java.util.Random;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.regions.*;
import com.sk89q.worldedit.bags.*; import com.sk89q.worldedit.bags.*;
import com.sk89q.worldedit.blocks.*; import com.sk89q.worldedit.blocks.*;
@ -37,11 +36,11 @@ import com.sk89q.worldedit.patterns.*;
/** /**
* This class can wrap all block editing operations into one "edit session" that * 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 * stores the state of the blocks before modification. This allows for easy undo
* undo or redo. In addition to that, this class can use a "queue mode" that * or redo. In addition to that, this class can use a "queue mode" that will
* will know how to handle some special types of items such as signs and * know how to handle some special types of items such as signs and torches. For
* torches. For example, torches must be placed only after there is already * example, torches must be placed only after there is already a block below it,
* a block below it, otherwise the torch will be placed as an item. * otherwise the torch will be placed as an item.
* *
* @author sk89q * @author sk89q
*/ */
@ -55,31 +54,35 @@ public class EditSession {
* Server interface. * Server interface.
*/ */
private ServerInterface server; private ServerInterface server;
/**
* World.
*/
private LocalWorld world;
/** /**
* Stores the original blocks before modification. * Stores the original blocks before modification.
*/ */
private DoubleArrayList<BlockVector,BaseBlock> original = private DoubleArrayList<BlockVector, BaseBlock> original = new DoubleArrayList<BlockVector, BaseBlock>(
new DoubleArrayList<BlockVector,BaseBlock>(true); true);
/** /**
* Stores the current blocks. * Stores the current blocks.
*/ */
private DoubleArrayList<BlockVector,BaseBlock> current = private DoubleArrayList<BlockVector, BaseBlock> current = new DoubleArrayList<BlockVector, BaseBlock>(
new DoubleArrayList<BlockVector,BaseBlock>(false); false);
/** /**
* Blocks that should be placed before last. * Blocks that should be placed before last.
*/ */
private DoubleArrayList<BlockVector,BaseBlock> queueAfter = private DoubleArrayList<BlockVector, BaseBlock> queueAfter = new DoubleArrayList<BlockVector, BaseBlock>(
new DoubleArrayList<BlockVector,BaseBlock>(false); false);
/** /**
* Blocks that should be placed last. * Blocks that should be placed last.
*/ */
private DoubleArrayList<BlockVector,BaseBlock> queueLast = private DoubleArrayList<BlockVector, BaseBlock> queueLast = new DoubleArrayList<BlockVector, BaseBlock>(
new DoubleArrayList<BlockVector,BaseBlock>(false); false);
/** /**
* The maximum number of blocks to change at a time. If this number is * The maximum number of blocks to change at a time. If this number is
* exceeded, a MaxChangedBlocksException exception will be * exceeded, a MaxChangedBlocksException exception will be raised. -1
* raised. -1 indicates no limit. * indicates no limit.
*/ */
private int maxBlocks = -1; private int maxBlocks = -1;
/** /**
@ -98,25 +101,38 @@ public class EditSession {
/** /**
* Construct the object with a maximum number of blocks. * 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) { if (maxBlocks < -1) {
throw new IllegalArgumentException("Max blocks must be >= -1"); throw new IllegalArgumentException("Max blocks must be >= -1");
} }
this.maxBlocks = maxBlocks; 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. * 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) { if (maxBlocks < -1) {
throw new IllegalArgumentException("Max blocks must be >= -1"); throw new IllegalArgumentException("Max blocks must be >= -1");
} }
this.maxBlocks = maxBlocks; this.maxBlocks = maxBlocks;
this.blockBag = blockBag; this.blockBag = blockBag;
server = ServerInterface.getInstance(); this.server = server;
this.world = world;
} }
/** /**
@ -133,14 +149,14 @@ public class EditSession {
} }
// Clear the chest so that it doesn't drop items // Clear the chest so that it doesn't drop items
if (server.getBlockType(pt) == 54 && blockBag == null) { if (server.getBlockType(world, pt) == 54 && blockBag == null) {
server.clearChest(pt); server.clearChest(world, pt);
} }
int id = block.getID(); int id = block.getID();
if (blockBag != null) { if (blockBag != null) {
int existing = server.getBlockType(pt); int existing = server.getBlockType(world, pt);
if (id > 0) { if (id > 0) {
try { try {
@ -161,25 +177,25 @@ public class EditSession {
} }
} }
boolean result = server.setBlockType(pt, id); boolean result = server.setBlockType(world, pt, id);
if (id != 0) { if (id != 0) {
if (BlockType.usesData(id)) { if (BlockType.usesData(id)) {
server.setBlockData(pt, block.getData()); server.setBlockData(world, pt, block.getData());
} }
// Signs // Signs
if (block instanceof SignBlock) { if (block instanceof SignBlock) {
SignBlock signBlock = (SignBlock)block; SignBlock signBlock = (SignBlock) block;
String[] text = signBlock.getText(); String[] text = signBlock.getText();
server.setSignText(pt, text); server.setSignText(world, pt, text);
// Chests // Chests
} else if (block instanceof ChestBlock && blockBag == null) { } else if (block instanceof ChestBlock && blockBag == null) {
ChestBlock chestBlock = (ChestBlock)block; ChestBlock chestBlock = (ChestBlock) block;
server.setChestContents(pt, chestBlock.getItems()); server.setChestContents(world, pt, chestBlock.getItems());
// Mob spawners // Mob spawners
} else if (block instanceof MobSpawnerBlock) { } else if (block instanceof MobSpawnerBlock) {
MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock)block; MobSpawnerBlock mobSpawnerblock = (MobSpawnerBlock) block;
server.setMobSpawnerType(pt, mobSpawnerblock.getMobType()); server.setMobSpawnerType(world, pt, mobSpawnerblock.getMobType());
} }
} }
@ -188,8 +204,8 @@ public class EditSession {
/** /**
* Sets the block at position x, y, z with a block type. If queue mode is * 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() * enabled, blocks may not be actually set in world until flushQueue() is
* is called. * called.
* *
* @param pt * @param pt
* @param block * @param block
@ -199,13 +215,13 @@ public class EditSession {
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
BlockVector blockPt = pt.toBlockVector(); BlockVector blockPt = pt.toBlockVector();
//if (!original.containsKey(blockPt)) { // if (!original.containsKey(blockPt)) {
original.put(blockPt, getBlock(pt)); original.put(blockPt, getBlock(pt));
if (maxBlocks != -1 && original.size() > maxBlocks) { if (maxBlocks != -1 && original.size() > maxBlocks) {
throw new MaxChangedBlocksException(maxBlocks); throw new MaxChangedBlocksException(maxBlocks);
} }
//} // }
current.put(pt.toBlockVector(), block); current.put(pt.toBlockVector(), block);
@ -264,11 +280,12 @@ public class EditSession {
// In the case of the queue, the block may have not actually been // In the case of the queue, the block may have not actually been
// changed yet // changed yet
if (queued) { if (queued) {
/*BlockVector blockPt = pt.toBlockVector(); /*
* BlockVector blockPt = pt.toBlockVector();
if (current.containsKey(blockPt)) { *
return current.get(blockPt); * if (current.containsKey(blockPt)) { return current.get(blockPt);
}*/ * }
*/
} }
return rawGetBlock(pt); return rawGetBlock(pt);
@ -281,21 +298,21 @@ public class EditSession {
* @return BaseBlock * @return BaseBlock
*/ */
public BaseBlock rawGetBlock(Vector pt) { public BaseBlock rawGetBlock(Vector pt) {
int type = server.getBlockType(pt); int type = server.getBlockType(world, pt);
int data = server.getBlockData(pt); int data = server.getBlockData(world, pt);
// Sign // Sign
if (type == 63 || type == 68) { if (type == 63 || type == 68) {
String[] text = server.getSignText(pt); String[] text = server.getSignText(world, pt);
return new SignBlock(type, data, text); return new SignBlock(type, data, text);
// Chest // Chest
} else if (type == 54) { } else if (type == 54) {
BaseItemStack[] items = BaseItemStack[] items = server.getChestContents(world, pt);
server.getChestContents(pt);
return new ChestBlock(data, items); return new ChestBlock(data, items);
// Mob spawner // Mob spawner
} else if (type == 52) { } else if (type == 52) {
return new MobSpawnerBlock(data, server.getMobSpawnerType(pt)); return new MobSpawnerBlock(data,
server.getMobSpawnerType(world, pt));
} else { } else {
return new BaseBlock(type, data); return new BaseBlock(type, data);
} }
@ -305,9 +322,9 @@ public class EditSession {
* Restores all blocks to their initial state. * Restores all blocks to their initial state.
*/ */
public void undo() { public void undo() {
for (Map.Entry<BlockVector,BaseBlock> entry : original) { for (Map.Entry<BlockVector, BaseBlock> entry : original) {
BlockVector pt = (BlockVector)entry.getKey(); BlockVector pt = (BlockVector) entry.getKey();
smartSetBlock(pt, (BaseBlock)entry.getValue()); smartSetBlock(pt, (BaseBlock) entry.getValue());
} }
flushQueue(); flushQueue();
} }
@ -316,9 +333,9 @@ public class EditSession {
* Sets to new state. * Sets to new state.
*/ */
public void redo() { public void redo() {
for (Map.Entry<BlockVector,BaseBlock> entry : current) { for (Map.Entry<BlockVector, BaseBlock> entry : current) {
BlockVector pt = (BlockVector)entry.getKey(); BlockVector pt = (BlockVector) entry.getKey();
smartSetBlock(pt, (BaseBlock)entry.getValue()); smartSetBlock(pt, (BaseBlock) entry.getValue());
} }
flushQueue(); flushQueue();
} }
@ -332,8 +349,8 @@ public class EditSession {
} }
/** /**
* Get the maximum number of blocks that can be changed. -1 will be * Get the maximum number of blocks that can be changed. -1 will be returned
* returned if disabled. * if disabled.
* *
* @return block change limit * @return block change limit
*/ */
@ -344,7 +361,8 @@ public class EditSession {
/** /**
* Set the maximum number of blocks that can be changed. * 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) { public void setBlockChangeLimit(int maxBlocks) {
if (maxBlocks < -1) { if (maxBlocks < -1) {
@ -383,19 +401,21 @@ public class EditSession {
* Finish off the queue. * Finish off the queue.
*/ */
public void flushQueue() { public void flushQueue() {
if (!queued) { return; } if (!queued) {
return;
}
for (Map.Entry<BlockVector,BaseBlock> entry : queueAfter) { for (Map.Entry<BlockVector, BaseBlock> entry : queueAfter) {
BlockVector pt = (BlockVector)entry.getKey(); BlockVector pt = (BlockVector) entry.getKey();
rawSetBlock(pt, (BaseBlock)entry.getValue()); rawSetBlock(pt, (BaseBlock) entry.getValue());
} }
// We don't want to place these blocks if other blocks were missing // We don't want to place these blocks if other blocks were missing
// because it might cause the items to drop // because it might cause the items to drop
if (blockBag == null || missingBlocks.size() == 0) { if (blockBag == null || missingBlocks.size() == 0) {
for (Map.Entry<BlockVector,BaseBlock> entry : queueLast) { for (Map.Entry<BlockVector, BaseBlock> entry : queueLast) {
BlockVector pt = (BlockVector)entry.getKey(); BlockVector pt = (BlockVector) entry.getKey();
rawSetBlock(pt, (BaseBlock)entry.getValue()); rawSetBlock(pt, (BaseBlock) entry.getValue());
} }
} }
@ -413,9 +433,8 @@ public class EditSession {
* @param recursive * @param recursive
* @return number of blocks affected * @return number of blocks affected
*/ */
public int fillXZ(Vector origin, BaseBlock block, public int fillXZ(Vector origin, BaseBlock block, int radius, int depth,
int radius, int depth, boolean recursive) boolean recursive) throws MaxChangedBlocksException {
throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
int originX = origin.getBlockX(); int originX = origin.getBlockX();
@ -518,9 +537,8 @@ public class EditSession {
* @param recursive * @param recursive
* @return number of blocks affected * @return number of blocks affected
*/ */
public int fillXZ(Vector origin, Pattern pattern, public int fillXZ(Vector origin, Pattern pattern, int radius, int depth,
int radius, int depth, boolean recursive) boolean recursive) throws MaxChangedBlocksException {
throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
int originX = origin.getBlockX(); int originX = origin.getBlockX();
@ -621,8 +639,8 @@ public class EditSession {
* @param height * @param height
* @return number of blocks affected * @return number of blocks affected
*/ */
public int removeAbove(Vector pos, int size, int height) throws public int removeAbove(Vector pos, int size, int height)
MaxChangedBlocksException { throws MaxChangedBlocksException {
int maxY = Math.min(127, pos.getBlockY() + height - 1); int maxY = Math.min(127, pos.getBlockY() + height - 1);
size--; size--;
int affected = 0; int affected = 0;
@ -655,8 +673,8 @@ public class EditSession {
* @param height * @param height
* @return number of blocks affected * @return number of blocks affected
*/ */
public int removeBelow(Vector pos, int size, int height) throws public int removeBelow(Vector pos, int size, int height)
MaxChangedBlocksException { throws MaxChangedBlocksException {
int minY = Math.max(0, pos.getBlockY() - height); int minY = Math.max(0, pos.getBlockY() - height);
size--; size--;
int affected = 0; int affected = 0;
@ -689,8 +707,8 @@ public class EditSession {
* @param size * @param size
* @return number of blocks affected * @return number of blocks affected
*/ */
public int removeNear(Vector pos, int blockType, int size) throws public int removeNear(Vector pos, int blockType, int size)
MaxChangedBlocksException { throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
BaseBlock air = new BaseBlock(0); BaseBlock air = new BaseBlock(0);
@ -807,13 +825,14 @@ public class EditSession {
* Replaces all the blocks of a type inside a region to another block type. * Replaces all the blocks of a type inside a region to another block type.
* *
* @param region * @param region
* @param fromBlockType -1 for non-air * @param fromBlockType
* -1 for non-air
* @param toBlockType * @param toBlockType
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int replaceBlocks(Region region, Set<Integer> fromBlockTypes, BaseBlock toBlock) public int replaceBlocks(Region region, Set<Integer> fromBlockTypes,
throws MaxChangedBlocksException { BaseBlock toBlock) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
if (region instanceof CuboidRegion) { if (region instanceof CuboidRegion) {
@ -834,9 +853,9 @@ public class EditSession {
Vector pt = new Vector(x, y, z); Vector pt = new Vector(x, y, z);
int curBlockType = getBlock(pt).getID(); int curBlockType = getBlock(pt).getID();
if ((fromBlockTypes == null && curBlockType != 0) || if ((fromBlockTypes == null && curBlockType != 0)
(fromBlockTypes != null && || (fromBlockTypes != null && fromBlockTypes
fromBlockTypes.contains(curBlockType))) { .contains(curBlockType))) {
if (setBlock(pt, toBlock)) { if (setBlock(pt, toBlock)) {
affected++; affected++;
} }
@ -848,8 +867,8 @@ public class EditSession {
for (Vector pt : region) { for (Vector pt : region) {
int curBlockType = getBlock(pt).getID(); int curBlockType = getBlock(pt).getID();
if (fromBlockTypes == null && curBlockType != 0 || if (fromBlockTypes == null && curBlockType != 0
fromBlockTypes.contains(curBlockType)) { || fromBlockTypes.contains(curBlockType)) {
if (setBlock(pt, toBlock)) { if (setBlock(pt, toBlock)) {
affected++; affected++;
} }
@ -864,14 +883,14 @@ public class EditSession {
* Replaces all the blocks of a type inside a region to another block type. * Replaces all the blocks of a type inside a region to another block type.
* *
* @param region * @param region
* @param fromBlockType -1 for non-air * @param fromBlockType
* -1 for non-air
* @param pattern * @param pattern
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int replaceBlocks(Region region, Set<Integer> fromBlockTypes, public int replaceBlocks(Region region, Set<Integer> fromBlockTypes,
Pattern pattern) Pattern pattern) throws MaxChangedBlocksException {
throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
if (region instanceof CuboidRegion) { if (region instanceof CuboidRegion) {
@ -892,9 +911,9 @@ public class EditSession {
Vector pt = new Vector(x, y, z); Vector pt = new Vector(x, y, z);
int curBlockType = getBlock(pt).getID(); int curBlockType = getBlock(pt).getID();
if ((fromBlockTypes == null && curBlockType != 0) || if ((fromBlockTypes == null && curBlockType != 0)
(fromBlockTypes != null && || (fromBlockTypes != null && fromBlockTypes
fromBlockTypes.contains(curBlockType))) { .contains(curBlockType))) {
if (setBlock(pt, pattern.next(pt))) { if (setBlock(pt, pattern.next(pt))) {
affected++; affected++;
} }
@ -906,8 +925,8 @@ public class EditSession {
for (Vector pt : region) { for (Vector pt : region) {
int curBlockType = getBlock(pt).getID(); int curBlockType = getBlock(pt).getID();
if (fromBlockTypes == null && curBlockType != 0 || if (fromBlockTypes == null && curBlockType != 0
fromBlockTypes.contains(curBlockType)) { || fromBlockTypes.contains(curBlockType)) {
if (setBlock(pt, pattern.next(pt))) { if (setBlock(pt, pattern.next(pt))) {
affected++; affected++;
} }
@ -942,23 +961,35 @@ public class EditSession {
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) { for (int y = minY; y <= maxY; y++) {
if (setBlock(new Vector(x, y, minZ), block)) { affected++; } if (setBlock(new Vector(x, y, minZ), block)) {
if (setBlock(new Vector(x, y, maxZ), block)) { affected++; } affected++;
}
if (setBlock(new Vector(x, y, maxZ), block)) {
affected++;
}
affected++; affected++;
} }
} }
for (int y = minY; y <= maxY; y++) { for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) { for (int z = minZ; z <= maxZ; z++) {
if (setBlock(new Vector(minX, y, z), block)) { affected++; } if (setBlock(new Vector(minX, y, z), block)) {
if (setBlock(new Vector(maxX, y, z), block)) { affected++; } affected++;
}
if (setBlock(new Vector(maxX, y, z), block)) {
affected++;
}
} }
} }
for (int z = minZ; z <= maxZ; z++) { for (int z = minZ; z <= maxZ; z++) {
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
if (setBlock(new Vector(x, minY, z), block)) { affected++; } if (setBlock(new Vector(x, minY, z), block)) {
if (setBlock(new Vector(x, maxY, z), block)) { affected++; } affected++;
}
if (setBlock(new Vector(x, maxY, z), block)) {
affected++;
}
} }
} }
@ -989,16 +1020,24 @@ public class EditSession {
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) { for (int y = minY; y <= maxY; y++) {
if (setBlock(new Vector(x, y, minZ), block)) { affected++; } if (setBlock(new Vector(x, y, minZ), block)) {
if (setBlock(new Vector(x, y, maxZ), block)) { affected++; } affected++;
}
if (setBlock(new Vector(x, y, maxZ), block)) {
affected++;
}
affected++; affected++;
} }
} }
for (int y = minY; y <= maxY; y++) { for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) { for (int z = minZ; z <= maxZ; z++) {
if (setBlock(new Vector(minX, y, z), block)) { affected++; } if (setBlock(new Vector(minX, y, z), block)) {
if (setBlock(new Vector(maxX, y, z), block)) { affected++; } affected++;
}
if (setBlock(new Vector(maxX, y, z), block)) {
affected++;
}
} }
} }
@ -1019,7 +1058,7 @@ public class EditSession {
Vector max = region.getMaximumPoint(); Vector max = region.getMaximumPoint();
int upperY = Math.min(127, max.getBlockY() + 1); 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; int affected = 0;
@ -1057,9 +1096,8 @@ public class EditSession {
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int stackCuboidRegion(Region region, Vector dir, public int stackCuboidRegion(Region region, Vector dir, int count,
int count, boolean copyAir) boolean copyAir) throws MaxChangedBlocksException {
throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
Vector min = region.getMinimumPoint(); Vector min = region.getMinimumPoint();
@ -1083,10 +1121,9 @@ public class EditSession {
if (!block.isAir() || copyAir) { if (!block.isAir() || copyAir) {
for (int i = 1; i <= count; i++) { for (int i = 1; i <= count; i++) {
Vector pos = new Vector( Vector pos = new Vector(x + xs * dir.getBlockX()
x + xs * dir.getBlockX() * i, * i, y + ys * dir.getBlockY() * i, z + zs
y + ys * dir.getBlockY() * i, * dir.getBlockZ() * i);
z + zs * dir.getBlockZ() * i);
if (setBlock(pos, block)) { if (setBlock(pos, block)) {
affected++; affected++;
@ -1111,8 +1148,8 @@ public class EditSession {
* @return number of blocks moved * @return number of blocks moved
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int moveCuboidRegion(Region region, Vector dir, public int moveCuboidRegion(Region region, Vector dir, int distance,
int distance, boolean copyAir, BaseBlock replace) boolean copyAir, BaseBlock replace)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
@ -1130,7 +1167,7 @@ public class EditSession {
Vector newMin = min.add(shift); Vector newMin = min.add(shift);
Vector newMax = min.add(shift); Vector newMax = min.add(shift);
Map<Vector,BaseBlock> delayed = new LinkedHashMap<Vector,BaseBlock>(); Map<Vector, BaseBlock> delayed = new LinkedHashMap<Vector, BaseBlock>();
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) { 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 // Don't want to replace the old block if it's in
// the new area // the new area
if (x >= newMin.getBlockX() && x <= newMax.getBlockX() if (x >= newMin.getBlockX() && x <= newMax.getBlockX()
&& y >= newMin.getBlockY() && y <= newMax.getBlockY() && y >= newMin.getBlockY()
&& z >= newMin.getBlockZ() && z <= newMax.getBlockZ()) { && y <= newMax.getBlockY()
&& z >= newMin.getBlockZ()
&& z <= newMax.getBlockZ()) {
} else { } else {
setBlock(pos, replace); setBlock(pos, replace);
} }
@ -1156,7 +1195,7 @@ public class EditSession {
} }
} }
for (Map.Entry<Vector,BaseBlock> entry : delayed.entrySet()) { for (Map.Entry<Vector, BaseBlock> entry : delayed.entrySet()) {
setBlock(entry.getKey(), entry.getValue()); setBlock(entry.getKey(), entry.getValue());
affected++; affected++;
} }
@ -1172,7 +1211,8 @@ public class EditSession {
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int drainArea(Vector pos, int radius) throws MaxChangedBlocksException { public int drainArea(Vector pos, int radius)
throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
HashSet<BlockVector> visited = new HashSet<BlockVector>(); HashSet<BlockVector> visited = new HashSet<BlockVector>();
@ -1303,8 +1343,8 @@ public class EditSession {
* @param block * @param block
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
private int makeHCylinderPoints(Vector center, int x, int z, private int makeHCylinderPoints(Vector center, int x, int z, int height,
int height, BaseBlock block) throws MaxChangedBlocksException { BaseBlock block) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
if (x == 0) { if (x == 0) {
@ -1350,8 +1390,8 @@ public class EditSession {
* @return number of blocks set * @return number of blocks set
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int makeHollowCylinder(Vector pos, BaseBlock block, public int makeHollowCylinder(Vector pos, BaseBlock block, int radius,
int radius, int height) throws MaxChangedBlocksException { int height) throws MaxChangedBlocksException {
int x = 0; int x = 0;
int z = radius; int z = radius;
int d = (5 - radius * 4) / 4; int d = (5 - radius * 4) / 4;
@ -1398,8 +1438,8 @@ public class EditSession {
* @param block * @param block
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
private int makeCylinderPoints(Vector center, int x, int z, private int makeCylinderPoints(Vector center, int x, int z, int height,
int height, BaseBlock block) throws MaxChangedBlocksException { BaseBlock block) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
if (x == z) { if (x == z) {
@ -1437,8 +1477,8 @@ public class EditSession {
* @return number of blocks set * @return number of blocks set
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int makeCylinder(Vector pos, BaseBlock block, public int makeCylinder(Vector pos, BaseBlock block, int radius, int height)
int radius, int height) throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int x = 0; int x = 0;
int z = radius; int z = radius;
int d = (5 - radius * 4) / 4; int d = (5 - radius * 4) / 4;
@ -1485,8 +1525,8 @@ public class EditSession {
* @return number of blocks changed * @return number of blocks changed
* @throws MaxChangedBlocksException * @throws MaxChangedBlocksException
*/ */
public int makeSphere(Vector pos, BaseBlock block, int radius, boolean filled) public int makeSphere(Vector pos, BaseBlock block, int radius,
throws MaxChangedBlocksException { boolean filled) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
for (int x = 0; x <= radius; x++) { for (int x = 0; x <= radius; x++) {
@ -1496,14 +1536,30 @@ public class EditSession {
double d = vec.distance(pos); double d = vec.distance(pos);
if (d <= radius + 0.5 && (filled || d >= radius - 0.5)) { if (d <= radius + 0.5 && (filled || d >= radius - 0.5)) {
if (setBlock(vec, block)) { affected++; } if (setBlock(vec, block)) {
if (setBlock(pos.add(-x, y, z), block)) { affected++; } 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)) {
if (setBlock(pos.add(-x, -y, z), block)) { affected++; } 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)) {
if (setBlock(pos.add(-x, -y, -z), block)) { affected++; } 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++;
}
} }
} }
} }
@ -1555,8 +1611,8 @@ public class EditSession {
|| id == 53 // Wood steps || id == 53 // Wood steps
|| id == 55 // Redstone wire || id == 55 // Redstone wire
|| id == 59 // Crops || id == 59 // Crops
|| (id >= 63 && id <= 72) || (id >= 63 && id <= 72) || id == 75 // Redstone
|| id == 75 // Redstone torch // torch
|| id == 76 // Redstone torch || id == 76 // Redstone torch
|| id == 77 // Stone button || id == 77 // Stone button
|| id == 78 // Snow || id == 78 // Snow
@ -1599,7 +1655,8 @@ public class EditSession {
* *
* @param pos * @param pos
* @param block * @param block
* @param c 0-1 chance * @param c
* 0-1 chance
* @return whether a block was changed * @return whether a block was changed
*/ */
private boolean setChanceBlockIfAir(Vector pos, BaseBlock block, double c) private boolean setChanceBlockIfAir(Vector pos, BaseBlock block, double c)
@ -1617,10 +1674,10 @@ public class EditSession {
*/ */
private void makePumpkinPatch(Vector basePos) private void makePumpkinPatch(Vector basePos)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
//BaseBlock logBlock = new BaseBlock(17); // BaseBlock logBlock = new BaseBlock(17);
BaseBlock leavesBlock = new BaseBlock(18); BaseBlock leavesBlock = new BaseBlock(18);
//setBlock(basePos.subtract(0, 1, 0), logBlock); // setBlock(basePos.subtract(0, 1, 0), logBlock);
setBlockIfAir(basePos, leavesBlock); setBlockIfAir(basePos, leavesBlock);
makePumpkinPatchVine(basePos, basePos.add(0, 0, 1)); makePumpkinPatchVine(basePos, basePos.add(0, 0, 1));
@ -1637,8 +1694,10 @@ public class EditSession {
*/ */
private void makePumpkinPatchVine(Vector basePos, Vector pos) private void makePumpkinPatchVine(Vector basePos, Vector pos)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
if (pos.distance(basePos) > 4) return; if (pos.distance(basePos) > 4)
if (getBlock(pos).getID() != 0) return; return;
if (getBlock(pos).getID() != 0)
return;
for (int i = -1; i > -3; i--) { for (int i = -1; i > -3; i--) {
Vector testPos = pos.add(0, i, 0); Vector testPos = pos.add(0, i, 0);
@ -1655,20 +1714,28 @@ public class EditSession {
int h = prng.nextInt(3) - 1; int h = prng.nextInt(3) - 1;
if (t == 0) { if (t == 0) {
if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(1, 0, 0)); if (prng.nextBoolean())
if (prng.nextBoolean()) setBlockIfAir(pos.add(1, h, -1), new BaseBlock(18)); 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)); setBlockIfAir(pos.add(0, 0, -1), new BaseBlock(86));
} else if (t == 1) { } else if (t == 1) {
if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(0, 0, 1)); if (prng.nextBoolean())
if (prng.nextBoolean()) setBlockIfAir(pos.add(1, h, 0), new BaseBlock(18)); 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)); setBlockIfAir(pos.add(1, 0, 1), new BaseBlock(86));
} else if (t == 2) { } else if (t == 2) {
if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(0, 0, -1)); if (prng.nextBoolean())
if (prng.nextBoolean()) setBlockIfAir(pos.add(-1, h, 0), new BaseBlock(18)); 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)); setBlockIfAir(pos.add(-1, 0, 1), new BaseBlock(86));
} else if (t == 3) { } else if (t == 3) {
if (prng.nextBoolean()) makePumpkinPatchVine(basePos, pos.add(-1, 0, 0)); if (prng.nextBoolean())
if (prng.nextBoolean()) setBlockIfAir(pos.add(-1, h, -1), new BaseBlock(18)); 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)); setBlockIfAir(pos.add(-1, 0, -1), new BaseBlock(86));
} }
} }
@ -1684,13 +1751,17 @@ public class EditSession {
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + size; x++) { for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX()
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + size; z++) { + size; x++) {
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ()
+ size; z++) {
// Don't want to be in the ground // Don't want to be in the ground
if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir()) if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir())
continue; continue;
// The gods don't want a pumpkin patch here // 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--) { for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; y--) {
// Check if we hit the ground // Check if we hit the ground
@ -1722,13 +1793,17 @@ public class EditSession {
boolean pineTree) throws MaxChangedBlocksException { boolean pineTree) throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX() + size; x++) { for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX()
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ() + size; z++) { + size; x++) {
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ()
+ size; z++) {
// Don't want to be in the ground // Don't want to be in the ground
if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir()) if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir())
continue; continue;
// The gods don't want a tree here // 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--) { for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; y--) {
// Check if we hit the ground // Check if we hit the ground
@ -1737,7 +1812,8 @@ public class EditSession {
if (pineTree) { if (pineTree) {
makePineTree(new Vector(x, y + 1, z)); makePineTree(new Vector(x, y + 1, z));
} else { } else {
server.generateTree(this, new Vector(x, y + 1, z)); server.generateTree(this, world,
new Vector(x, y + 1, z));
} }
affected++; affected++;
break; break;
@ -1756,10 +1832,9 @@ public class EditSession {
* *
* @param basePos * @param basePos
*/ */
private void makePineTree(Vector basePos) private void makePineTree(Vector basePos) throws MaxChangedBlocksException {
throws MaxChangedBlocksException { int trunkHeight = (int) Math.floor(Math.random() * 2) + 3;
int trunkHeight = (int)Math.floor(Math.random() * 2) + 3; int height = (int) Math.floor(Math.random() * 5) + 8;
int height = (int)Math.floor(Math.random() * 5) + 8;
BaseBlock logBlock = new BaseBlock(17); BaseBlock logBlock = new BaseBlock(17);
BaseBlock leavesBlock = new BaseBlock(18); BaseBlock leavesBlock = new BaseBlock(18);
@ -1861,10 +1936,8 @@ public class EditSession {
* @return * @return
*/ */
public List<Countable<Integer>> getBlockDistribution(Region region) { public List<Countable<Integer>> getBlockDistribution(Region region) {
List<Countable<Integer>> distribution List<Countable<Integer>> distribution = new ArrayList<Countable<Integer>>();
= new ArrayList<Countable<Integer>>(); Map<Integer, Countable<Integer>> map = new HashMap<Integer, Countable<Integer>>();
Map<Integer,Countable<Integer>> map =
new HashMap<Integer,Countable<Integer>>();
if (region instanceof CuboidRegion) { if (region instanceof CuboidRegion) {
// Doing this for speed // Doing this for speed
@ -1909,7 +1982,7 @@ public class EditSession {
} }
Collections.sort(distribution); Collections.sort(distribution);
//Collections.reverse(distribution); // Collections.reverse(distribution);
return distribution; return distribution;
} }
@ -1920,12 +1993,14 @@ public class EditSession {
* *
* @param x * @param x
* @param z * @param z
* @param minY minimal height * @param minY
* @param maxY maximal height * minimal height
* @param maxY
* maximal height
* @return height of highest block found or 'minY' * @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--) { for (int y = maxY; y >= minY; y--) {
Vector pt = new Vector(x, y, z); Vector pt = new Vector(x, y, z);
int id = getBlock(pt).getID(); int id = getBlock(pt).getID();
@ -1974,7 +2049,8 @@ public class EditSession {
} }
/** /**
* @param blockBag the blockBag to set * @param blockBag
* the blockBag to set
*/ */
public void setBlockBag(BlockBag blockBag) { public void setBlockBag(BlockBag blockBag) {
this.blockBag = blockBag; this.blockBag = blockBag;

Datei anzeigen

@ -0,0 +1,41 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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();
}

Datei anzeigen

@ -15,7 +15,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit; package com.sk89q.worldedit;
@ -26,28 +26,6 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
* @author sk89q * @author sk89q
*/ */
public abstract class ServerInterface { 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. * Set block type.
* *
@ -55,7 +33,7 @@ public abstract class ServerInterface {
* @param type * @param type
* @return * @return
*/ */
public abstract boolean setBlockType(Vector pt, int type); public abstract boolean setBlockType(LocalWorld world, Vector pt, int type);
/** /**
* Get block type. * Get block type.
@ -63,7 +41,7 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public abstract int getBlockType(Vector pt); public abstract int getBlockType(LocalWorld world, Vector pt);
/** /**
* Set block data. * Set block data.
@ -72,7 +50,7 @@ public abstract class ServerInterface {
* @param data * @param data
* @return * @return
*/ */
public abstract void setBlockData(Vector pt, int data); public abstract void setBlockData(LocalWorld world, Vector pt, int data);
/** /**
* Get block data. * Get block data.
@ -80,7 +58,7 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public abstract int getBlockData(Vector pt); public abstract int getBlockData(LocalWorld world, Vector pt);
/** /**
* Set sign text. * Set sign text.
@ -88,7 +66,7 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @param text * @param text
*/ */
public abstract void setSignText(Vector pt, String[] text); public abstract void setSignText(LocalWorld world, Vector pt, String[] text);
/** /**
* Get sign text. * Get sign text.
@ -96,7 +74,7 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @return * @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 * Gets the contents of chests. Will return null if the chest does not
@ -105,7 +83,7 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public abstract BaseItemStack[] getChestContents(Vector pt); public abstract BaseItemStack[] getChestContents(LocalWorld world, Vector pt);
/** /**
* Sets a chest slot. * Sets a chest slot.
@ -114,14 +92,15 @@ public abstract class ServerInterface {
* @param contents * @param contents
* @return * @return
*/ */
public abstract boolean setChestContents(Vector pt, BaseItemStack[] contents); public abstract boolean setChestContents(LocalWorld world, Vector pt,
BaseItemStack[] contents);
/** /**
* Clear a chest's contents. * Clear a chest's contents.
* *
* @param pt * @param pt
*/ */
public abstract boolean clearChest(Vector pt); public abstract boolean clearChest(LocalWorld world, Vector pt);
/** /**
* Checks if a mob type is valid. * Checks if a mob type is valid.
@ -137,7 +116,8 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @param mobType * @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. * Get mob spawner mob type. May return an empty string.
@ -145,7 +125,7 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @param mobType * @param mobType
*/ */
public abstract String getMobSpawnerType(Vector pt); public abstract String getMobSpawnerType(LocalWorld world, Vector pt);
/** /**
* Generate a tree at a location. * Generate a tree at a location.
@ -153,7 +133,8 @@ public abstract class ServerInterface {
* @param pt * @param pt
* @return * @return
*/ */
public abstract boolean generateTree(EditSession editSession, Vector pt); public abstract boolean generateTree(EditSession editSession,
LocalWorld world, Vector pt);
/** /**
* Drop an item. * Drop an item.
@ -163,7 +144,8 @@ public abstract class ServerInterface {
* @param count * @param count
* @param times * @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. * Drop an item.
@ -173,7 +155,8 @@ public abstract class ServerInterface {
* @param count * @param count
* @param times * @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. * Drop an item.
@ -183,14 +166,14 @@ public abstract class ServerInterface {
* @param count * @param count
* @param times * @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. * Simulate a block being mined.
* *
* @param pt * @param pt
*/ */
public abstract void simulateBlockMine(Vector pt); public abstract void simulateBlockMine(LocalWorld world, Vector pt);
/** /**
* Resolves an item name to its ID. * Resolves an item name to its ID.
@ -207,5 +190,5 @@ public abstract class ServerInterface {
* @param radius * @param radius
* @return * @return
*/ */
public abstract int killMobs(Vector origin, int radius); public abstract int killMobs(LocalWorld world, Vector origin, int radius);
} }

Datei anzeigen

@ -21,7 +21,7 @@ package com.sk89q.worldedit;
/** /**
* *
* @author Albert * @author sk89q
*/ */
public class Vector { public class Vector {
protected final double x, y, z; protected final double x, y, z;

Datei anzeigen

@ -95,10 +95,12 @@ public class WorldEditController {
public boolean useInventoryOverride = false; public boolean useInventoryOverride = false;
/** /**
* Construct an instance of the plugin. * Construct an instance of the plugin
*
* @param server
*/ */
public WorldEditController() { public WorldEditController(ServerInterface server) {
server = ServerInterface.getInstance(); this.server = server;
// Note: Commands should only have the phrase 'air' at the end // Note: Commands should only have the phrase 'air' at the end
// for now (see SMWorldEditListener.canUseCommand) // for now (see SMWorldEditListener.canUseCommand)
@ -442,9 +444,9 @@ public class WorldEditController {
// Jump to the block in sight // Jump to the block in sight
} else if (split[0].equalsIgnoreCase("/jumpto")) { } else if (split[0].equalsIgnoreCase("/jumpto")) {
checkArgs(split, 0, 0, split[0]); checkArgs(split, 0, 0, split[0]);
Vector pos = player.getSolidBlockTrace(300); WorldVector pos = player.getSolidBlockTrace(300);
if (pos != null) { if (pos != null) {
player.findFreePosition(pos); player.findFreePosition(pos.getWorld(), pos);
player.print("Poof!"); player.print("Poof!");
} else { } else {
player.printError("No block in sight!"); player.printError("No block in sight!");
@ -1323,7 +1325,7 @@ public class WorldEditController {
Math.max(1, Integer.parseInt(split[1])) : -1; Math.max(1, Integer.parseInt(split[1])) : -1;
Vector origin = session.getPlacementPosition(player); Vector origin = session.getPlacementPosition(player);
int killed = server.killMobs(origin, radius); int killed = server.killMobs(player.getWorld(), origin, radius);
player.print("Killed " + killed + " mobs."); player.print("Killed " + killed + " mobs.");
return true; return true;
@ -1732,10 +1734,10 @@ public class WorldEditController {
} else if (player.isHoldingPickAxe() } else if (player.isHoldingPickAxe()
&& session.getTool() == WorldEditSession.Tool.TREE) { && session.getTool() == WorldEditSession.Tool.TREE) {
EditSession editSession = EditSession editSession =
new EditSession(session.getBlockChangeLimit()); new EditSession(server, player.getWorld(), session.getBlockChangeLimit());
try { try {
if (!server.generateTree(editSession, clicked)) { if (!server.generateTree(editSession, player.getWorld(), clicked)) {
player.printError("Notch won't let you put a tree there."); player.printError("Notch won't let you put a tree there.");
} }
} finally { } finally {
@ -1745,7 +1747,7 @@ public class WorldEditController {
return true; return true;
} else if (player.isHoldingPickAxe() } else if (player.isHoldingPickAxe()
&& session.getTool() == WorldEditSession.Tool.INFO) { && 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" player.print("\u00A79@" + clicked + ": " + "\u00A7e"
+ "Type: " + block.getID() + "\u00A77" + " (" + "Type: " + block.getID() + "\u00A77" + " ("
@ -1806,19 +1808,21 @@ public class WorldEditController {
if (session.hasSuperPickAxe()) { if (session.hasSuperPickAxe()) {
boolean canBedrock = canUseCommand(player, "/worldeditbedrock"); boolean canBedrock = canUseCommand(player, "/worldeditbedrock");
LocalWorld world = player.getWorld();
// Single block super pickaxe // Single block super pickaxe
if (session.getSuperPickaxeMode() == if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SINGLE) { WorldEditSession.SuperPickaxeMode.SINGLE) {
if (server.getBlockType(clicked) == 7 && !canBedrock) { if (server.getBlockType(world, clicked) == 7 && !canBedrock) {
return true; return true;
} else if (server.getBlockType(clicked) == 46) { } else if (server.getBlockType(world, clicked) == 46) {
return false; return false;
} }
if (superPickaxeDrop) { if (superPickaxeDrop) {
server.simulateBlockMine(clicked); server.simulateBlockMine(world, clicked);
} else { } else {
server.setBlockType(clicked, 0); server.setBlockType(world, clicked, 0);
} }
// Area super pickaxe // Area super pickaxe
@ -1828,7 +1832,7 @@ public class WorldEditController {
int oy = clicked.getBlockY(); int oy = clicked.getBlockY();
int oz = clicked.getBlockZ(); int oz = clicked.getBlockZ();
int size = session.getSuperPickaxeRange(); int size = session.getSuperPickaxeRange();
int initialType = server.getBlockType(clicked); int initialType = server.getBlockType(world, clicked);
if (initialType == 7 && !canBedrock) { if (initialType == 7 && !canBedrock) {
return true; return true;
@ -1838,11 +1842,11 @@ public class WorldEditController {
for (int y = oy - size; y <= oy + size; y++) { for (int y = oy - size; y <= oy + size; y++) {
for (int z = oz - size; z <= oz + size; z++) { for (int z = oz - size; z <= oz + size; z++) {
Vector pos = new Vector(x, y, z); Vector pos = new Vector(x, y, z);
if (server.getBlockType(pos) == initialType) { if (server.getBlockType(world, pos) == initialType) {
if (superPickaxeManyDrop) { if (superPickaxeManyDrop) {
server.simulateBlockMine(pos); server.simulateBlockMine(world, pos);
} else { } else {
server.setBlockType(pos, 0); server.setBlockType(world, pos, 0);
} }
} }
} }
@ -1855,13 +1859,13 @@ public class WorldEditController {
} else if (session.getSuperPickaxeMode() == } else if (session.getSuperPickaxeMode() ==
WorldEditSession.SuperPickaxeMode.SAME_TYPE_RECURSIVE) { WorldEditSession.SuperPickaxeMode.SAME_TYPE_RECURSIVE) {
int size = session.getSuperPickaxeRange(); int size = session.getSuperPickaxeRange();
int initialType = server.getBlockType(clicked); int initialType = server.getBlockType(world, clicked);
if (initialType == 7 && !canBedrock) { if (initialType == 7 && !canBedrock) {
return true; return true;
} }
recursiveSuperPickaxe(clicked.toBlockVector(), clicked, size, recursiveSuperPickaxe(world, clicked.toBlockVector(), clicked, size,
initialType, new HashSet<BlockVector>()); initialType, new HashSet<BlockVector>());
return true; return true;
@ -1881,7 +1885,7 @@ public class WorldEditController {
* @param canBedrock * @param canBedrock
* @return * @return
*/ */
private void recursiveSuperPickaxe(BlockVector pos, Vector origin, private void recursiveSuperPickaxe(LocalWorld world, BlockVector pos, Vector origin,
int size, int initialType, Set<BlockVector> visited) { int size, int initialType, Set<BlockVector> visited) {
if (origin.distance(pos) > size || visited.contains(pos)) { if (origin.distance(pos) > size || visited.contains(pos)) {
return; return;
@ -1889,27 +1893,27 @@ public class WorldEditController {
visited.add(pos); visited.add(pos);
if (server.getBlockType(pos) == initialType) { if (server.getBlockType(world, pos) == initialType) {
if (superPickaxeManyDrop) { if (superPickaxeManyDrop) {
server.simulateBlockMine(pos); server.simulateBlockMine(world, pos);
} else { } else {
server.setBlockType(pos, 0); server.setBlockType(world, pos, 0);
} }
} else { } else {
return; return;
} }
recursiveSuperPickaxe(pos.add(1, 0, 0).toBlockVector(), origin, size, recursiveSuperPickaxe(world, pos.add(1, 0, 0).toBlockVector(), origin, size,
initialType, visited); initialType, visited);
recursiveSuperPickaxe(pos.add(-1, 0, 0).toBlockVector(), origin, size, recursiveSuperPickaxe(world, pos.add(-1, 0, 0).toBlockVector(), origin, size,
initialType, visited); initialType, visited);
recursiveSuperPickaxe(pos.add(0, 0, 1).toBlockVector(), origin, size, recursiveSuperPickaxe(world, pos.add(0, 0, 1).toBlockVector(), origin, size,
initialType, visited); initialType, visited);
recursiveSuperPickaxe(pos.add(0, 0, -1).toBlockVector(), origin, size, recursiveSuperPickaxe(world, pos.add(0, 0, -1).toBlockVector(), origin, size,
initialType, visited); initialType, visited);
recursiveSuperPickaxe(pos.add(0, 1, 0).toBlockVector(), origin, size, recursiveSuperPickaxe(world, pos.add(0, 1, 0).toBlockVector(), origin, size,
initialType, visited); initialType, visited);
recursiveSuperPickaxe(pos.add(0, -1, 0).toBlockVector(), origin, size, recursiveSuperPickaxe(world, pos.add(0, -1, 0).toBlockVector(), origin, size,
initialType, visited); initialType, visited);
} }
@ -1943,7 +1947,8 @@ public class WorldEditController {
BlockBag blockBag = session.getBlockBag(player); BlockBag blockBag = session.getBlockBag(player);
EditSession editSession = EditSession editSession =
new EditSession(session.getBlockChangeLimit(), blockBag); new EditSession(server, player.getWorld(),
session.getBlockChangeLimit(), blockBag);
editSession.enableQueue(); editSession.enableQueue();
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();

Datei anzeigen

@ -48,9 +48,11 @@ public abstract class WorldEditPlayer {
/** /**
* Construct the object. * Construct the object.
*
* @param server
*/ */
protected WorldEditPlayer() { protected WorldEditPlayer(ServerInterface server) {
server = ServerInterface.getInstance(); this.server = server;
} }
/** /**
@ -72,7 +74,7 @@ public abstract class WorldEditPlayer {
* *
* @param searchPos search position * @param searchPos search position
*/ */
public void findFreePosition(Vector searchPos) { public void findFreePosition(LocalWorld world, Vector searchPos) {
int x = searchPos.getBlockX(); int x = searchPos.getBlockX();
int y = Math.max(0, searchPos.getBlockY()); int y = Math.max(0, searchPos.getBlockY());
int origY = y; int origY = y;
@ -81,7 +83,8 @@ public abstract class WorldEditPlayer {
byte free = 0; byte free = 0;
while (y <= 129) { 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++; free++;
} else { } else {
free = 0; free = 0;
@ -106,7 +109,7 @@ public abstract class WorldEditPlayer {
* that free position. * that free position.
*/ */
public void findFreePosition() { public void findFreePosition() {
findFreePosition(getBlockIn()); findFreePosition(getPosition().getWorld(), getBlockIn());
} }
/** /**
@ -119,12 +122,13 @@ public abstract class WorldEditPlayer {
int x = pos.getBlockX(); int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY()); int y = Math.max(0, pos.getBlockY());
int z = pos.getBlockZ(); int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
byte free = 0; byte free = 0;
byte spots = 0; byte spots = 0;
while (y <= 129) { 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++; free++;
} else { } else {
free = 0; free = 0;
@ -133,7 +137,7 @@ public abstract class WorldEditPlayer {
if (free == 2) { if (free == 2) {
spots++; spots++;
if (spots == 2) { 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! // Don't get put in lava!
if (type == 10 || type == 11) { if (type == 10 || type == 11) {
@ -161,11 +165,12 @@ public abstract class WorldEditPlayer {
int x = pos.getBlockX(); int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY() - 1); int y = Math.max(0, pos.getBlockY() - 1);
int z = pos.getBlockZ(); int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
byte free = 0; byte free = 0;
while (y >= 1) { 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++; free++;
} else { } else {
free = 0; free = 0;
@ -176,7 +181,7 @@ public abstract class WorldEditPlayer {
// lightly and also check to see if there's something to // lightly and also check to see if there's something to
// stand upon // stand upon
while (y >= 0) { 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 // Don't want to end up in lava
if (type != 0 && type != 10 && type != 11) { if (type != 0 && type != 10 && type != 11) {
@ -209,17 +214,18 @@ public abstract class WorldEditPlayer {
int initialY = Math.max(0, pos.getBlockY()); int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 2); int y = Math.max(0, pos.getBlockY() + 2);
int z = pos.getBlockZ(); int z = pos.getBlockZ();
LocalWorld world = getPosition().getWorld();
// No free space above // 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; return false;
} }
while (y <= 127) { while (y <= 127) {
// Found a ceiling! // 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); 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()); BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5)); setPosition(new Vector(x + 0.5, platformY + 1, z + 0.5));
return true; return true;
@ -244,14 +250,15 @@ public abstract class WorldEditPlayer {
int y = Math.max(0, pos.getBlockY() + 1); int y = Math.max(0, pos.getBlockY() + 1);
int z = pos.getBlockZ(); int z = pos.getBlockZ();
int maxY = Math.min(128, initialY + distance); int maxY = Math.min(128, initialY + distance);
LocalWorld world = getPosition().getWorld();
while (y <= 129) { 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 break; // Hit something
} else if (y > maxY + 1) { } else if (y > maxY + 1) {
break; break;
} else if (y == maxY + 1) { } 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()); BlockType.GLASS.getID());
setPosition(new Vector(x + 0.5, y - 1, z + 0.5)); setPosition(new Vector(x + 0.5, y - 1, z + 0.5));
return true; return true;
@ -268,8 +275,8 @@ public abstract class WorldEditPlayer {
* *
* @return point * @return point
*/ */
public Vector getBlockIn() { public WorldVector getBlockIn() {
return getPosition().toBlockVector(); return getPosition();
} }
/** /**
@ -277,8 +284,9 @@ public abstract class WorldEditPlayer {
* *
* @return point * @return point
*/ */
public Vector getBlockOn() { public WorldVector getBlockOn() {
return getPosition().subtract(0, 1, 0).toBlockVector(); WorldVector pos = getPosition();
return new WorldVector(pos.getWorld(), pos.subtract(0, 1, 0));
} }
/** /**
@ -287,7 +295,7 @@ public abstract class WorldEditPlayer {
* @param range * @param range
* @return point * @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. * Get the point of the block being looked at. May return null.
@ -295,7 +303,7 @@ public abstract class WorldEditPlayer {
* @param range * @param range
* @return point * @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. * Get the player's cardinal direction (N, W, NW, etc.). May return null.
@ -360,7 +368,14 @@ public abstract class WorldEditPlayer {
* *
* @return point * @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. * Get the player's view pitch.

Datei anzeigen

@ -0,0 +1,104 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}