3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

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/>.
*/
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;
}

Datei anzeigen

@ -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()) {

Datei anzeigen

@ -17,11 +17,7 @@
* 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.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);
}
}

Datei anzeigen

@ -31,21 +31,27 @@ 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;
/**
* Construct an instance of the plugin.
*/
public WorldEdit() {
ServerInterface.setup(new HMServerInterface());
listener = new HMWorldEditListener();
listener = new HMWorldEditListener(new HMServerInterface());
}
/**
@ -117,13 +123,4 @@ public class WorldEdit extends Plugin {
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

@ -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,11 +36,11 @@ 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
*/
@ -55,31 +54,35 @@ public class EditSession {
* Server interface.
*/
private ServerInterface server;
/**
* World.
*/
private LocalWorld world;
/**
* Stores the original blocks before modification.
*/
private DoubleArrayList<BlockVector,BaseBlock> original =
new DoubleArrayList<BlockVector,BaseBlock>(true);
private DoubleArrayList<BlockVector, BaseBlock> original = new DoubleArrayList<BlockVector, BaseBlock>(
true);
/**
* Stores the current blocks.
*/
private DoubleArrayList<BlockVector,BaseBlock> current =
new DoubleArrayList<BlockVector,BaseBlock>(false);
private DoubleArrayList<BlockVector, BaseBlock> current = new DoubleArrayList<BlockVector, BaseBlock>(
false);
/**
* Blocks that should be placed before last.
*/
private DoubleArrayList<BlockVector,BaseBlock> queueAfter =
new DoubleArrayList<BlockVector,BaseBlock>(false);
private DoubleArrayList<BlockVector, BaseBlock> queueAfter = new DoubleArrayList<BlockVector, BaseBlock>(
false);
/**
* Blocks that should be placed last.
*/
private DoubleArrayList<BlockVector,BaseBlock> queueLast =
new DoubleArrayList<BlockVector,BaseBlock>(false);
private DoubleArrayList<BlockVector, BaseBlock> queueLast = new DoubleArrayList<BlockVector, BaseBlock>(
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,14 +149,14 @@ 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 {
@ -161,25 +177,25 @@ 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;
String[] text = signBlock.getText();
server.setSignText(pt, text);
server.setSignText(world, pt, text);
// Chests
} else if (block instanceof ChestBlock && blockBag == null) {
ChestBlock chestBlock = (ChestBlock) block;
server.setChestContents(pt, chestBlock.getItems());
server.setChestContents(world, pt, chestBlock.getItems());
// Mob spawners
} else if (block instanceof MobSpawnerBlock) {
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
* 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
@ -264,11 +280,12 @@ 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);
@ -281,21 +298,21 @@ public class EditSession {
* @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
} else if (type == 54) {
BaseItemStack[] items =
server.getChestContents(pt);
BaseItemStack[] items = server.getChestContents(world, pt);
return new ChestBlock(data, items);
// 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);
}
@ -332,8 +349,8 @@ 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
*/
@ -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,7 +401,9 @@ public class EditSession {
* Finish off the queue.
*/
public void flushQueue() {
if (!queued) { return; }
if (!queued) {
return;
}
for (Map.Entry<BlockVector, BaseBlock> entry : queueAfter) {
BlockVector pt = (BlockVector) entry.getKey();
@ -413,9 +433,8 @@ 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();
@ -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();
@ -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;
@ -655,8 +673,8 @@ public class EditSession {
* @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;
@ -689,8 +707,8 @@ public class EditSession {
* @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);
@ -807,13 +825,14 @@ 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<Integer> fromBlockTypes, BaseBlock toBlock)
throws MaxChangedBlocksException {
public int replaceBlocks(Region region, Set<Integer> 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++;
}
@ -864,14 +883,14 @@ 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<Integer> 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++;
}
@ -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++;
}
}
}
@ -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++;
}
}
}
@ -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();
@ -1083,10 +1121,9 @@ 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++;
@ -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;
@ -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);
}
@ -1172,7 +1211,8 @@ public class EditSession {
* @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<BlockVector> visited = new HashSet<BlockVector>();
@ -1303,8 +1343,8 @@ 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) {
@ -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;
@ -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;
@ -1485,8 +1525,8 @@ 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++) {
@ -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++;
}
}
}
}
@ -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
@ -1599,7 +1655,8 @@ public class EditSession {
*
* @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)
@ -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,20 +1714,28 @@ 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));
}
}
@ -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
@ -1722,13 +1793,17 @@ public class EditSession {
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;
@ -1756,8 +1832,7 @@ public class EditSession {
*
* @param basePos
*/
private void makePineTree(Vector basePos)
throws MaxChangedBlocksException {
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;
@ -1861,10 +1936,8 @@ public class EditSession {
* @return
*/
public List<Countable<Integer>> getBlockDistribution(Region region) {
List<Countable<Integer>> distribution
= new ArrayList<Countable<Integer>>();
Map<Integer,Countable<Integer>> map =
new HashMap<Integer,Countable<Integer>>();
List<Countable<Integer>> distribution = new ArrayList<Countable<Integer>>();
Map<Integer, Countable<Integer>> map = new HashMap<Integer, Countable<Integer>>();
if (region instanceof CuboidRegion) {
// Doing this for speed
@ -1920,8 +1993,10 @@ public class EditSession {
*
* @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'
*/
@ -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;

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

@ -26,28 +26,6 @@ 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.
*
@ -55,7 +33,7 @@ public abstract class ServerInterface {
* @param type
* @return
*/
public abstract boolean setBlockType(Vector pt, int type);
public abstract boolean setBlockType(LocalWorld world, Vector pt, int type);
/**
* Get block type.
@ -63,7 +41,7 @@ public abstract class ServerInterface {
* @param pt
* @return
*/
public abstract int getBlockType(Vector pt);
public abstract int getBlockType(LocalWorld world, Vector pt);
/**
* Set block data.
@ -72,7 +50,7 @@ public abstract class ServerInterface {
* @param data
* @return
*/
public abstract void setBlockData(Vector pt, int data);
public abstract void setBlockData(LocalWorld world, Vector pt, int data);
/**
* Get block data.
@ -80,7 +58,7 @@ public abstract class ServerInterface {
* @param pt
* @return
*/
public abstract int getBlockData(Vector pt);
public abstract int getBlockData(LocalWorld world, Vector pt);
/**
* Set sign text.
@ -88,7 +66,7 @@ public abstract class ServerInterface {
* @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.
@ -96,7 +74,7 @@ public abstract class ServerInterface {
* @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
@ -105,7 +83,7 @@ public abstract class ServerInterface {
* @param pt
* @return
*/
public abstract BaseItemStack[] getChestContents(Vector pt);
public abstract BaseItemStack[] getChestContents(LocalWorld world, Vector pt);
/**
* Sets a chest slot.
@ -114,14 +92,15 @@ public abstract class ServerInterface {
* @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.
@ -137,7 +116,8 @@ public abstract class ServerInterface {
* @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.
@ -145,7 +125,7 @@ public abstract class ServerInterface {
* @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,7 +133,8 @@ 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.
@ -163,7 +144,8 @@ public abstract class ServerInterface {
* @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.
@ -173,7 +155,8 @@ public abstract class ServerInterface {
* @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.
@ -183,14 +166,14 @@ public abstract class ServerInterface {
* @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);
}

Datei anzeigen

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

Datei anzeigen

@ -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" + " ("
@ -1806,19 +1808,21 @@ public class WorldEditController {
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<BlockVector>());
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<BlockVector> 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();

Datei anzeigen

@ -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.

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);
}
}