mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 11:26:42 +00:00
Moved shape generation to EditSession.
Also refactored it to get rid of the 3 different anonymous classes.
This commit is contained in:
@ -34,6 +34,9 @@ import com.sk89q.worldedit.regions.*;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.bags.*;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
import com.sk89q.worldedit.expression.Expression;
|
||||
import com.sk89q.worldedit.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.masks.Mask;
|
||||
import com.sk89q.worldedit.patterns.*;
|
||||
|
||||
@ -2611,4 +2614,32 @@ public class EditSession {
|
||||
|
||||
return distribution;
|
||||
}
|
||||
|
||||
public int makeShape(final Region region, final Vector zero, final Vector unit, final Pattern pattern, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException {
|
||||
final Expression expression = Expression.compile(expressionString, "x", "y", "z", "type", "data");
|
||||
expression.optimize();
|
||||
|
||||
final RValue typeVariable = expression.getVariable("type");
|
||||
final RValue dataVariable = expression.getVariable("data");
|
||||
|
||||
final ArbitraryShape shape = new ArbitraryShape(region) {
|
||||
@Override
|
||||
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
|
||||
final Vector scaled = new Vector(x, y, z).subtract(zero).divide(unit);
|
||||
|
||||
try {
|
||||
if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ(), defaultMaterial.getType(), defaultMaterial.getData()) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BaseBlock((int)typeVariable.getValue(), (int)dataVariable.getValue());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return shape.generate(this, pattern, hollow);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user