Skip to content

Commit

Permalink
/tree now makes regular tree and /bigtree makes big trees.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Jan 9, 2011
1 parent d997dba commit cdea296
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 8 deletions.
23 changes: 21 additions & 2 deletions src/HMWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalWorld;
Expand Down Expand Up @@ -279,8 +280,26 @@ public boolean generateTree(EditSession editSession, Vector pt) {
try {
return MinecraftServerInterface.generateTree(editSession, pt);
} catch (Throwable t) {
logger.severe("Failed to create tree (do you need to update WorldEdit due to a Minecraft update?): "
+ t.getMessage());
logger.log(Level.SEVERE,
"Failed to create tree (do you need to update WorldEdit " +
"due to a Minecraft update?)", t);
return false;
}
}

/**
* Generate a big tree at a location.
*
* @param pt
* @return
*/
public boolean generateBigTree(EditSession editSession, Vector pt) {
try {
return MinecraftServerInterface.generateBigTree(editSession, pt);
} catch (Throwable t) {
logger.log(Level.SEVERE,
"Failed to create big tree (do you need to update WorldEdit " +
"due to a Minecraft update?)", t);
return false;
}
}
Expand Down
29 changes: 25 additions & 4 deletions src/MinecraftServerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ public class MinecraftServerInterface {
private static MinecraftSetBlockProxy proxy;

/**
* Generate a tree at a location.
* Perform world generation at a location.
*
* @param pt
* @return
*/
public static boolean generateTree(EditSession editSession, Vector pt) {
private static boolean performWorldGen(EditSession editSession, Vector pt,
bt worldGen) {
if (proxy == null) {
try {
proxy = createNoConstructor(MinecraftSetBlockProxy.class);
Expand All @@ -60,11 +61,31 @@ public static boolean generateTree(EditSession editSession, Vector pt) {
}
proxy.setEditSession(editSession);

bt treeGen = new ib();
return treeGen.a(proxy, random,
bt gen = worldGen;
return gen.a(proxy, random,
pt.getBlockX(), pt.getBlockY() + 1, pt.getBlockZ());
}

/**
* Generate a tree at a location.
*
* @param pt
* @return
*/
public static boolean generateTree(EditSession editSession, Vector pt) {
return performWorldGen(editSession, pt, new kl());
}

/**
* Generate a big tree at a location.
*
* @param pt
* @return
*/
public static boolean generateBigTree(EditSession editSession, Vector pt) {
return performWorldGen(editSession, pt, new ib());
}

/**
* Get mob spawner mob type. May return an empty string.
*
Expand Down
2 changes: 1 addition & 1 deletion src/com/sk89q/worldedit/EditSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ public int makeForest(Vector basePos, int size, double density,
if (pineTree) {
makePineTree(new Vector(x, y + 1, z));
} else {
world.generateTree(this, new Vector(x, y + 1, z));
world.generateBigTree(this, new Vector(x, y + 1, z));
}
affected++;
break;
Expand Down
8 changes: 8 additions & 0 deletions src/com/sk89q/worldedit/LocalWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public abstract void setMobSpawnerType(Vector pt,
*/
public abstract boolean generateTree(EditSession editSession, Vector pt);

/**
* Generate a big tree at a location.
*
* @param pt
* @return
*/
public abstract boolean generateBigTree(EditSession editSession, Vector pt);

/**
* Drop an item.
*
Expand Down
8 changes: 8 additions & 0 deletions src/com/sk89q/worldedit/WorldEditController.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public WorldEditController(ServerInterface server, LocalConfiguration config) {
commands.put("/none", "Switch to no tool");
commands.put("/info", "Switch to the info tool");
commands.put("/tree", "Switch to the tree tool");
commands.put("/bigtree", "Switch to the big tree tool");
commands.put("/repl", "[ID] - Switch to the block replacer tool");
commands.put("//expand", "[Num] <Dir> - Expands the selection");
commands.put("//contract", "[Num] <Dir> - Contracts the selection");
Expand Down Expand Up @@ -684,6 +685,13 @@ public boolean performCommand(LocalPlayer player,
player.print("Tree tool equipped. Right click with a pickaxe.");
return true;

// Big tree tool
} else if (split[0].equalsIgnoreCase("/bigtree")) {
checkArgs(split, 0, 0, split[0]);
session.setTool(new BigTreePlanter());
player.print("Big tree tool equipped. Right click with a pickaxe.");
return true;

// Info tool
} else if (split[0].equalsIgnoreCase("/info")) {
checkArgs(split, 0, 0, split[0]);
Expand Down
6 changes: 6 additions & 0 deletions src/com/sk89q/worldedit/bukkit/BukkitWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public boolean generateTree(EditSession editSession, Vector pt) {
return false;
}

@Override
public boolean generateBigTree(EditSession editSession, Vector pt) {
// TODO Auto-generated method stub
return false;
}

@Override
public void dropItem(Vector pt, int type, int count, int times) {
// TODO Auto-generated method stub
Expand Down
49 changes: 49 additions & 0 deletions src/com/sk89q/worldedit/superpickaxe/BigTreePlanter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// $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.superpickaxe;

import com.sk89q.worldedit.*;

/**
* Plants a big tree.
*
* @author sk89q
*/
public class BigTreePlanter implements SuperPickaxeMode {
@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {

LocalWorld world = clicked.getWorld();
EditSession editSession =
new EditSession(server, world, session.getBlockChangeLimit());

try {
if (!world.generateBigTree(editSession, clicked)) {
player.printError("Notch won't let you put a tree there.");
}
} finally {
session.remember(editSession);
}

return true;
}

}
1 change: 0 additions & 1 deletion src/com/sk89q/worldedit/superpickaxe/TreePlanter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author sk89q
*/
public class TreePlanter implements SuperPickaxeMode {

@Override
public boolean act(ServerInterface server, LocalConfiguration config,
LocalPlayer player, LocalSession session, WorldVector clicked) {
Expand Down

0 comments on commit cdea296

Please sign in to comment.