From 478d6f6e54d1968f1446f78975c550de12da7ef8 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 1 Nov 2011 14:23:46 +0100 Subject: [PATCH] Added support for type/data to //generate. --- .../commands/GenerationCommands.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java b/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java index ccff176ba..238d4e0fe 100644 --- a/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/GenerationCommands.java @@ -28,6 +28,7 @@ import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.expression.Expression; import com.sk89q.worldedit.expression.ExpressionException; +import com.sk89q.worldedit.expression.runtime.LValue; import com.sk89q.worldedit.patterns.Pattern; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; @@ -304,7 +305,7 @@ public class GenerationCommands { @Command( aliases = { "/generate", "/gen", "/g" }, - usage = " ", + usage = " ", desc = "Generates a shape according to a formula. -h for hollow, -r for raw coordinates, -o for unscaled, but offset from placement", flags = "hro", min = 1, @@ -321,13 +322,16 @@ public class GenerationCommands { final Expression expression; try { - expression = Expression.compile(args.getJoinedStrings(1), "x", "y", "z"); + expression = Expression.compile(args.getJoinedStrings(1), "x", "y", "z", "type", "data"); expression.optimize(); } catch (ExpressionException e) { player.printError(e.getMessage()); return; } + final LValue typeVariable = (LValue) expression.getVariable("type"); + final LValue dataVariable = (LValue) expression.getVariable("data"); + final ArbitraryShape shape; if (args.hasFlag('r')) { @@ -335,7 +339,14 @@ public class GenerationCommands { @Override protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) { try { - return expression.evaluate(x, y, z) > 0 ? defaultMaterial : null; + typeVariable.assign(defaultMaterial.getType()); + dataVariable.assign(defaultMaterial.getData()); + + if (expression.evaluate(x, y, z) <= 0) { + return null; + } + + return new BaseBlock((int)typeVariable.getValue(), (int)dataVariable.getValue()); } catch (Exception e) { e.printStackTrace(); return null; @@ -353,7 +364,14 @@ public class GenerationCommands { @Override protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) { try { - return expression.evaluate(x - placementX, y - placementY, z - placementZ) > 0 ? defaultMaterial : null; + typeVariable.assign(defaultMaterial.getType()); + dataVariable.assign(defaultMaterial.getData()); + + if (expression.evaluate(x - placementX, y - placementY, z - placementZ) <= 0) { + return null; + } + + return new BaseBlock((int)typeVariable.getValue(), (int)dataVariable.getValue()); } catch (Exception e) { e.printStackTrace(); return null; @@ -371,7 +389,14 @@ public class GenerationCommands { final Vector scaled = new Vector(x, y, z).subtract(center).divide(stretch); try { - return expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ()) > 0 ? defaultMaterial : null; + typeVariable.assign(defaultMaterial.getType()); + dataVariable.assign(defaultMaterial.getData()); + + if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ()) <= 0) { + return null; + } + + return new BaseBlock((int)typeVariable.getValue(), (int)dataVariable.getValue()); } catch (Exception e) { e.printStackTrace(); return null;