mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 11:26:42 +00:00
Reorganize and further unify the new commands.
This commit is contained in:
@ -19,31 +19,41 @@
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
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 com.sk89q.worldedit.regions.NullRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class RegionApply implements OperationFactory {
|
||||
public class Apply implements Contextual<Operation> {
|
||||
|
||||
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
|
||||
private final Region region;
|
||||
private final Contextual<? extends RegionFunction> function;
|
||||
|
||||
public RegionApply(Function<EditContext, ? extends RegionFunction> regionFunctionFactory) {
|
||||
checkNotNull(regionFunctionFactory, "regionFunctionFactory");
|
||||
this.regionFunctionFactory = regionFunctionFactory;
|
||||
public Apply(Contextual<? extends RegionFunction> function) {
|
||||
this(new NullRegion(), function);
|
||||
}
|
||||
|
||||
public Apply(Region region, Contextual<? extends RegionFunction> function) {
|
||||
checkNotNull(region, "region");
|
||||
checkNotNull(function, "function");
|
||||
this.region = region;
|
||||
this.function = function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation createOperation(EditContext context) {
|
||||
return new RegionVisitor(context.getRegion(), regionFunctionFactory.apply(context));
|
||||
public Operation createFromContext(EditContext context) {
|
||||
return new RegionVisitor(MoreObjects.firstNonNull(context.getRegion(), region), function.createFromContext(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "set " + regionFunctionFactory;
|
||||
return "set " + function;
|
||||
}
|
||||
|
||||
}
|
@ -19,37 +19,73 @@
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.MoreObjects;
|
||||
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.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
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.NullRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class Deform implements OperationFactory {
|
||||
public class Deform implements Contextual<Operation> {
|
||||
|
||||
private Extent destination;
|
||||
private Region region;
|
||||
private String expression;
|
||||
private Mode mode = Mode.UNIT_CUBE;
|
||||
private Vector offset = new Vector();
|
||||
|
||||
public Deform(String expression) {
|
||||
checkNotNull(expression, "expression");
|
||||
this.expression = expression;
|
||||
this(new NullExtent(), new NullRegion(), expression);
|
||||
}
|
||||
|
||||
public Deform(String expression, Mode mode) {
|
||||
this(new NullExtent(), new NullRegion(), expression, mode);
|
||||
}
|
||||
|
||||
public Deform(Extent destination, Region region, String expression) {
|
||||
this(destination, region, expression, Mode.UNIT_CUBE);
|
||||
}
|
||||
|
||||
public Deform(Extent destination, Region region, String expression, Mode mode) {
|
||||
checkNotNull(destination, "destination");
|
||||
checkNotNull(region, "region");
|
||||
checkNotNull(expression, "expression");
|
||||
checkNotNull(mode, "mode");
|
||||
this.destination = destination;
|
||||
this.region = region;
|
||||
this.expression = expression;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public Extent getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(Extent destination) {
|
||||
checkNotNull(destination, "destination");
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public Region getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(Region region) {
|
||||
checkNotNull(region, "region");
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
@ -83,14 +119,16 @@ public class Deform implements OperationFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation createOperation(final EditContext context) {
|
||||
public Operation createFromContext(final EditContext context) {
|
||||
final Vector zero;
|
||||
Vector unit;
|
||||
|
||||
Region region = MoreObjects.firstNonNull(context.getRegion(), this.region);
|
||||
|
||||
switch (mode) {
|
||||
case UNIT_CUBE:
|
||||
final Vector min = context.getRegion().getMinimumPoint();
|
||||
final Vector max = context.getRegion().getMaximumPoint();
|
||||
final Vector min = region.getMinimumPoint();
|
||||
final Vector max = region.getMaximumPoint();
|
||||
|
||||
zero = max.add(min).multiply(0.5);
|
||||
unit = max.subtract(zero);
|
||||
@ -109,7 +147,7 @@ public class Deform implements OperationFactory {
|
||||
unit = Vector.ONE;
|
||||
}
|
||||
|
||||
return new DeformOperation(context.getDestination(), context.getRegion(), zero, unit, expression);
|
||||
return new DeformOperation(context.getDestination(), region, zero, unit, expression);
|
||||
}
|
||||
|
||||
private static final class DeformOperation implements Operation {
|
||||
@ -141,6 +179,12 @@ public class Deform implements OperationFactory {
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStatusMessages(List<String> messages) {
|
||||
messages.add("deformed using " + expression);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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);
|
||||
|
||||
}
|
@ -19,7 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.function.factory;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.GroundFunction;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
@ -28,25 +31,41 @@ 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.NullRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.regions.Regions.*;
|
||||
|
||||
public class Scatter implements OperationFactory {
|
||||
public class Paint implements Contextual<Operation> {
|
||||
|
||||
private final Function<EditContext, ? extends RegionFunction> regionFunctionFactory;
|
||||
private final Extent destination;
|
||||
private final Region region;
|
||||
private final Contextual<? extends RegionFunction> function;
|
||||
private final double density;
|
||||
|
||||
public Scatter(Function<EditContext, ? extends RegionFunction> regionFunctionFactory, double density) {
|
||||
this.regionFunctionFactory = regionFunctionFactory;
|
||||
public Paint(Contextual<? extends RegionFunction> function, double density) {
|
||||
this(new NullExtent(), new NullRegion(), function, density);
|
||||
}
|
||||
|
||||
public Paint(Extent destination, Region region, Contextual<? extends RegionFunction> function,
|
||||
double density) {
|
||||
checkNotNull(destination, "destination");
|
||||
checkNotNull(region, "region");
|
||||
checkNotNull(function, "function");
|
||||
checkNotNull(density, "density");
|
||||
this.destination = destination;
|
||||
this.region = region;
|
||||
this.function = function;
|
||||
this.density = density;
|
||||
new NoiseFilter2D(new RandomNoise(), density); // Check validity density argument
|
||||
new NoiseFilter2D(new RandomNoise(), density); // Check validity of the density argument
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation createOperation(EditContext context) {
|
||||
Region region = context.getRegion();
|
||||
GroundFunction ground = new GroundFunction(new ExistingBlockMask(context.getDestination()), regionFunctionFactory.apply(context));
|
||||
public Operation createFromContext(EditContext context) {
|
||||
Extent destination = MoreObjects.firstNonNull(context.getDestination(), this.destination);
|
||||
Region region = MoreObjects.firstNonNull(context.getRegion(), this.region);
|
||||
GroundFunction ground = new GroundFunction(new ExistingBlockMask(destination), function.createFromContext(context));
|
||||
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
|
||||
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
|
||||
return visitor;
|
||||
@ -54,7 +73,7 @@ public class Scatter implements OperationFactory {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "scatter " + regionFunctionFactory;
|
||||
return "scatter " + function;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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";
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user