Skip to content

Commit

Permalink
Cleaned up some code, changed WorldEdit to be world-aware (finally).
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Jan 1, 2011
1 parent 6d17289 commit ac4e6e8
Show file tree
Hide file tree
Showing 12 changed files with 782 additions and 441 deletions.
30 changes: 21 additions & 9 deletions src/HMPlayer.java
Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -58,13 +60,13 @@ public void setPosition(Vector pos) {
* @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());
}

/**
Expand All @@ -73,7 +75,7 @@ public Vector getBlockTrace(int range) {
* @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;

Expand All @@ -85,7 +87,7 @@ public Vector getSolidBlockTrace(int range) {
if (block == null) {
return null;
}
return new Vector(block.getX(), block.getY(), block.getZ());
return new WorldVector(null, block.getX(), block.getY(), block.getZ());
}

/**
Expand Down Expand Up @@ -130,8 +132,17 @@ public double getPitch() {
*
* @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;
}

/**
Expand Down Expand Up @@ -174,6 +185,7 @@ public boolean passThroughForwardWall(int range) {
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++;
Expand All @@ -183,7 +195,7 @@ public boolean passThroughForwardWall(int range) {
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;
}
Expand Down
88 changes: 44 additions & 44 deletions src/HMServerInterface.java
Expand Up @@ -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;
Expand All @@ -58,7 +58,7 @@ public boolean setBlockType(Vector pt, int type) {
* @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());
}
Expand All @@ -70,7 +70,7 @@ public int getBlockType(Vector pt) {
* @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);
}
Expand All @@ -81,7 +81,7 @@ public void setBlockData(Vector pt, int data) {
* @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());
}
Expand All @@ -92,7 +92,7 @@ public int getBlockData(Vector pt) {
* @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) {
Expand All @@ -110,7 +110,7 @@ public void setSignText(Vector pt, String[] text) {
* @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) {
Expand All @@ -130,7 +130,7 @@ public String[] getSignText(Vector pt) {
* @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());

Expand Down Expand Up @@ -165,7 +165,7 @@ public BaseItemStack[] getChestContents(Vector pt) {
* @param contents
* @return
*/
public boolean setChestContents(Vector pt,
public boolean setChestContents(LocalWorld world, Vector pt,
BaseItemStack[] contents) {

ComplexBlock cblock = etc.getServer().getOnlyComplexBlock(
Expand Down Expand Up @@ -197,7 +197,7 @@ public boolean setChestContents(Vector pt,
*
* @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());

Expand Down Expand Up @@ -247,7 +247,7 @@ public boolean isValidMobType(String type) {
* @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());

Expand All @@ -266,7 +266,7 @@ public void setMobSpawnerType(Vector pt, String mobType) {
* @param pt
* @param mobType
*/
public String getMobSpawnerType(Vector pt) {
public String getMobSpawnerType(LocalWorld world, Vector pt) {
try {
return MinecraftServerInterface.getMobSpawnerType(pt);
} catch (Throwable t) {
Expand All @@ -282,7 +282,7 @@ public String getMobSpawnerType(Vector pt) {
* @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) {
Expand All @@ -300,7 +300,7 @@ public boolean generateTree(EditSession editSession, Vector pt) {
* @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);
Expand All @@ -315,7 +315,7 @@ public void dropItem(Vector pt, int type, int count, int times) {
* @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);
}
Expand All @@ -328,7 +328,7 @@ public void dropItem(Vector pt, int type, int count) {
* @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);
}
Expand All @@ -338,57 +338,57 @@ public void dropItem(Vector pt, int type) {
*
* @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);
}
}

Expand All @@ -409,7 +409,7 @@ public int resolveItem(String name) {
* @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()) {
Expand Down

0 comments on commit ac4e6e8

Please sign in to comment.