mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-28 21:56:33 +01:00
Add scatter overlay
This commit is contained in:
parent
cff2cc846a
commit
ec455189dc
@ -24,6 +24,7 @@ public class ScatterBrush implements Brush {
|
|||||||
private final int count;
|
private final int count;
|
||||||
private final int distance;
|
private final int distance;
|
||||||
private Mask mask;
|
private Mask mask;
|
||||||
|
private AdjacentAnyMask adjacent;
|
||||||
|
|
||||||
public ScatterBrush(int count, int distance) {
|
public ScatterBrush(int count, int distance) {
|
||||||
this.count = count;
|
this.count = count;
|
||||||
@ -44,7 +45,7 @@ public class ScatterBrush implements Brush {
|
|||||||
if (this.mask == null) {
|
if (this.mask == null) {
|
||||||
this.mask = Masks.alwaysTrue();
|
this.mask = Masks.alwaysTrue();
|
||||||
}
|
}
|
||||||
final AdjacentAnyMask adjacent = new AdjacentAnyMask(editSession, Arrays.asList(new BaseBlock(0)));
|
this.adjacent = new AdjacentAnyMask(editSession, Arrays.asList(new BaseBlock(0)));
|
||||||
final SolidBlockMask solid = new SolidBlockMask(editSession);
|
final SolidBlockMask solid = new SolidBlockMask(editSession);
|
||||||
final RadiusMask radius = new RadiusMask(0, (int) size);
|
final RadiusMask radius = new RadiusMask(0, (int) size);
|
||||||
|
|
||||||
@ -83,6 +84,10 @@ public class ScatterBrush implements Brush {
|
|||||||
return mask.test(pos);
|
return mask.test(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector getDirection(Vector pt) {
|
||||||
|
return adjacent.direction(pt);
|
||||||
|
}
|
||||||
|
|
||||||
public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException {
|
public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException {
|
||||||
editSession.setBlock(pt, p);
|
editSession.setBlock(pt, p);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.boydti.fawe.object.brush;
|
||||||
|
|
||||||
|
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
|
|
||||||
|
public class ScatterOverlayBrush extends ScatterBrush {
|
||||||
|
public ScatterOverlayBrush(int count, int distance) {
|
||||||
|
super(count, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException {
|
||||||
|
int x = pt.getBlockX();
|
||||||
|
int y = pt.getBlockY();
|
||||||
|
int z = pt.getBlockZ();
|
||||||
|
Vector dir = getDirection(pt);
|
||||||
|
dir.setComponents(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ());
|
||||||
|
editSession.setBlock(dir, p);
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,9 @@ import java.util.Collection;
|
|||||||
* Just an optimized version of the Adjacent Mask for single adjacency
|
* Just an optimized version of the Adjacent Mask for single adjacency
|
||||||
*/
|
*/
|
||||||
public class AdjacentAnyMask extends BlockMask {
|
public class AdjacentAnyMask extends BlockMask {
|
||||||
|
|
||||||
|
private MutableBlockVector mutable = new MutableBlockVector();
|
||||||
|
|
||||||
public AdjacentAnyMask(Extent extent, Collection<BaseBlock> blocks) {
|
public AdjacentAnyMask(Extent extent, Collection<BaseBlock> blocks) {
|
||||||
super(extent, blocks);
|
super(extent, blocks);
|
||||||
}
|
}
|
||||||
@ -43,19 +46,19 @@ public class AdjacentAnyMask extends BlockMask {
|
|||||||
int y = v.getBlockY();
|
int y = v.getBlockY();
|
||||||
int z = v.getBlockZ();
|
int z = v.getBlockZ();
|
||||||
v.mutY(y + 1);
|
v.mutY(y + 1);
|
||||||
if (super.test(v)) { v.mutY(y); return MutableBlockVector.get(0, 1, 0); }
|
if (super.test(v)) { v.mutY(y); return mutable.setComponents(0, 1, 0); }
|
||||||
v.mutY(y - 1);
|
v.mutY(y - 1);
|
||||||
if (super.test(v)) { v.mutY(y); return MutableBlockVector.get(0, -1, 0); }
|
if (super.test(v)) { v.mutY(y); return mutable.setComponents(0, -1, 0); }
|
||||||
v.mutY(y);
|
v.mutY(y);
|
||||||
v.mutX(x + 1);
|
v.mutX(x + 1);
|
||||||
if (super.test(v)) { v.mutX(x); return MutableBlockVector.get(1, 0, 0); }
|
if (super.test(v)) { v.mutX(x); return mutable.setComponents(1, 0, 0); }
|
||||||
v.mutX(x - 1);
|
v.mutX(x - 1);
|
||||||
if (super.test(v)) { v.mutX(x); return MutableBlockVector.get(-1, 0, 0); }
|
if (super.test(v)) { v.mutX(x); return mutable.setComponents(-1, 0, 0); }
|
||||||
v.mutX(x);
|
v.mutX(x);
|
||||||
v.mutZ(z + 1);
|
v.mutZ(z + 1);
|
||||||
if (super.test(v)) { v.mutZ(z); return MutableBlockVector.get(0, 0, 1); }
|
if (super.test(v)) { v.mutZ(z); return mutable.setComponents(0, 0, 1); }
|
||||||
v.mutZ(z - 1);
|
v.mutZ(z - 1);
|
||||||
if (super.test(v)) { v.mutZ(z); return MutableBlockVector.get(0, 0, - 1); }
|
if (super.test(v)) { v.mutZ(z); return mutable.setComponents(0, 0, - 1); }
|
||||||
v.mutZ(z);
|
v.mutZ(z);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import com.boydti.fawe.object.brush.RaiseBrush;
|
|||||||
import com.boydti.fawe.object.brush.RecurseBrush;
|
import com.boydti.fawe.object.brush.RecurseBrush;
|
||||||
import com.boydti.fawe.object.brush.ScatterBrush;
|
import com.boydti.fawe.object.brush.ScatterBrush;
|
||||||
import com.boydti.fawe.object.brush.ScatterCommand;
|
import com.boydti.fawe.object.brush.ScatterCommand;
|
||||||
|
import com.boydti.fawe.object.brush.ScatterOverlayBrush;
|
||||||
import com.boydti.fawe.object.brush.ShatterBrush;
|
import com.boydti.fawe.object.brush.ShatterBrush;
|
||||||
import com.boydti.fawe.object.brush.SplatterBrush;
|
import com.boydti.fawe.object.brush.SplatterBrush;
|
||||||
import com.boydti.fawe.object.brush.SplineBrush;
|
import com.boydti.fawe.object.brush.SplineBrush;
|
||||||
@ -68,6 +69,7 @@ import com.sk89q.worldedit.WorldEditException;
|
|||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.blocks.BlockID;
|
import com.sk89q.worldedit.blocks.BlockID;
|
||||||
import com.sk89q.worldedit.command.tool.BrushTool;
|
import com.sk89q.worldedit.command.tool.BrushTool;
|
||||||
|
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||||
import com.sk89q.worldedit.command.tool.brush.ButcherBrush;
|
import com.sk89q.worldedit.command.tool.brush.ButcherBrush;
|
||||||
import com.sk89q.worldedit.command.tool.brush.ClipboardBrush;
|
import com.sk89q.worldedit.command.tool.brush.ClipboardBrush;
|
||||||
import com.sk89q.worldedit.command.tool.brush.CylinderBrush;
|
import com.sk89q.worldedit.command.tool.brush.CylinderBrush;
|
||||||
@ -570,17 +572,24 @@ public class BrushCommands {
|
|||||||
usage = "<pattern> [radius=5] [points=5] [distance=1]",
|
usage = "<pattern> [radius=5] [points=5] [distance=1]",
|
||||||
desc = "Scatter blocks on a surface",
|
desc = "Scatter blocks on a surface",
|
||||||
help =
|
help =
|
||||||
"Chooses the scatter brush.",
|
"Chooses the scatter brush.\n" +
|
||||||
|
" The -o flag will overlay the block",
|
||||||
min = 1,
|
min = 1,
|
||||||
max = 4
|
max = 4
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.brush.scatter")
|
@CommandPermissions("worldedit.brush.scatter")
|
||||||
public void scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, @Optional("5") double points, @Optional("1") double distance) throws WorldEditException {
|
public void scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, @Optional("5") double points, @Optional("1") double distance, @Switch('o') boolean overlay) throws WorldEditException {
|
||||||
worldEdit.checkMaxBrushRadius(radius);
|
worldEdit.checkMaxBrushRadius(radius);
|
||||||
BrushTool tool = session.getBrushTool(player);
|
BrushTool tool = session.getBrushTool(player);
|
||||||
tool.setFill(fill);
|
tool.setFill(fill);
|
||||||
tool.setSize(radius);
|
tool.setSize(radius);
|
||||||
tool.setBrush(new ScatterBrush((int) points, (int) distance), "worldedit.brush.scatter", player);
|
Brush brush;
|
||||||
|
if (overlay) {
|
||||||
|
brush = new ScatterOverlayBrush((int) points, (int) distance);
|
||||||
|
} else {
|
||||||
|
brush = new ScatterBrush((int) points, (int) distance);
|
||||||
|
}
|
||||||
|
tool.setBrush(brush, "worldedit.brush.scatter", player);
|
||||||
player.print(BBC.getPrefix() + BBC.BRUSH_SCATTER.f(radius, points));
|
player.print(BBC.getPrefix() + BBC.BRUSH_SCATTER.f(radius, points));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user