Add some experimental brush commands.

/br set <shape> <radius> <pattern>
/br deform <shape> <expression>
/br scatter <shape> <density> <generator>
/br apply <shape> <generator>

<shape> can be: cuboid, cyl[inder], sphere

<density> is 0-100

<generator> can be:
forest|tree <type>
item <item>[:<data>] (ONLY WORKS ON FORGE)

Examples:

/br deform cuboid 5 y-=0.2
/br scatter sphere 5 100 minecraft:dye:15
This commit is contained in:
sk89q
2015-10-26 23:14:30 -07:00
parent b19cd9bec4
commit 935de4c93d
59 changed files with 2239 additions and 99 deletions

View File

@ -0,0 +1,62 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.NullExtent;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
public class EditContext {
private Extent destination = new NullExtent();
private Region region = new CuboidRegion(Vector.ZERO, Vector.ZERO);
private Pattern fill = new BlockPattern(new BaseBlock(BlockID.AIR));
public Extent getDestination() {
return destination;
}
public void setDestination(Extent destination) {
this.destination = destination;
}
public Region getRegion() {
return region;
}
public void setRegion(Region region) {
this.region = region;
}
public Pattern getFill() {
return fill;
}
public void setFill(Pattern fill) {
this.fill = fill;
}
}

View File

@ -0,0 +1,144 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.factory;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.regions.Region;
import static com.google.common.base.Preconditions.checkNotNull;
public class Deform implements OperationFactory {
private String expression;
private Mode mode = Mode.UNIT_CUBE;
private Vector offset = new Vector();
public Deform(String expression) {
checkNotNull(expression, "expression");
this.expression = expression;
}
public String getExpression() {
return expression;
}
public void setExpression(String expression) {
checkNotNull(expression, "expression");
this.expression = expression;
}
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
checkNotNull(mode, "mode");
this.mode = mode;
}
public Vector getOffset() {
return offset;
}
public void setOffset(Vector offset) {
checkNotNull(offset, "offset");
this.offset = offset;
}
@Override
public String toString() {
return "deformation of " + expression;
}
@Override
public Operation createOperation(final EditContext context) {
final Vector zero;
Vector unit;
switch (mode) {
case UNIT_CUBE:
final Vector min = context.getRegion().getMinimumPoint();
final Vector max = context.getRegion().getMaximumPoint();
zero = max.add(min).multiply(0.5);
unit = max.subtract(zero);
if (unit.getX() == 0) unit = unit.setX(1.0);
if (unit.getY() == 0) unit = unit.setY(1.0);
if (unit.getZ() == 0) unit = unit.setZ(1.0);
break;
case RAW_COORD:
zero = Vector.ZERO;
unit = Vector.ONE;
break;
case OFFSET:
default:
zero = offset;
unit = Vector.ONE;
}
return new DeformOperation(context.getDestination(), context.getRegion(), zero, unit, expression);
}
private static final class DeformOperation implements Operation {
private final Extent destination;
private final Region region;
private final Vector zero;
private final Vector unit;
private final String expression;
private DeformOperation(Extent destination, Region region, Vector zero, Vector unit, String expression) {
this.destination = destination;
this.region = region;
this.zero = zero;
this.unit = unit;
this.expression = expression;
}
@Override
public Operation resume(RunContext run) throws WorldEditException {
try {
// TODO: Move deformation code
((EditSession) destination).deformRegion(region, zero, unit, expression);
return null;
} catch (ExpressionException e) {
throw new RuntimeException("Failed to execute expression", e); // TODO: Better exception to throw here?
}
}
@Override
public void cancel() {
}
}
public enum Mode {
RAW_COORD,
OFFSET,
UNIT_CUBE
}
}

View File

@ -0,0 +1,29 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.factory;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.operation.Operation;
public interface OperationFactory {
Operation createOperation(EditContext context);
}

View File

@ -0,0 +1,49 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.factory;
import com.google.common.base.Function;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import static com.google.common.base.Preconditions.checkNotNull;
public class RegionApply implements OperationFactory {
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
public RegionApply(Function<EditContext, ? extends RegionFunction> regionFunctionFactory) {
checkNotNull(regionFunctionFactory, "regionFunctionFactory");
this.regionFunctionFactory = regionFunctionFactory;
}
@Override
public Operation createOperation(EditContext context) {
return new RegionVisitor(context.getRegion(), regionFunctionFactory.apply(context));
}
@Override
public String toString() {
return "set " + regionFunctionFactory;
}
}

View File

@ -0,0 +1,40 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.factory;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.block.BlockReplace;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
public class RegionReplace implements OperationFactory {
@Override
public Operation createOperation(EditContext context) {
BlockReplace replace = new BlockReplace(context.getDestination(), context.getFill());
return new RegionVisitor(context.getRegion(), replace);
}
@Override
public String toString() {
return "set blocks";
}
}

View File

@ -0,0 +1,60 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.function.factory;
import com.google.common.base.Function;
import com.sk89q.worldedit.function.EditContext;
import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.NoiseFilter2D;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.visitor.LayerVisitor;
import com.sk89q.worldedit.math.noise.RandomNoise;
import com.sk89q.worldedit.regions.Region;
import static com.sk89q.worldedit.regions.Regions.*;
public class Scatter implements OperationFactory {
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
private final double density;
public Scatter(Function<EditContext, ? extends RegionFunction> regionFunctionFactory, double density) {
this.regionFunctionFactory = regionFunctionFactory;
this.density = density;
new NoiseFilter2D(new RandomNoise(), density); // Check validity density argument
}
@Override
public Operation createOperation(EditContext context) {
Region region = context.getRegion();
GroundFunction ground = new GroundFunction(new ExistingBlockMask(context.getDestination()), regionFunctionFactory.apply(context));
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
return visitor;
}
@Override
public String toString() {
return "scatter " + regionFunctionFactory;
}
}

View File

@ -55,6 +55,10 @@ public class ForestGenerator implements RegionFunction {
if (t == BlockID.GRASS || t == BlockID.DIRT) {
treeGenerator.generate(editSession, position.add(0, 1, 0));
return true;
} else if (t == BlockID.LONG_GRASS || t == BlockID.DEAD_BUSH || t == BlockID.RED_FLOWER || t == BlockID.YELLOW_FLOWER) { // TODO: This list needs to be moved
editSession.setBlock(position, new BaseBlock(0));
treeGenerator.generate(editSession, position);
return true;
} else if (t == BlockID.SNOW) {
editSession.setBlock(position, new BaseBlock(BlockID.AIR));
return false;