Fix some pattern stuff

This commit is contained in:
Jesse Boyd 2017-03-12 05:51:56 +11:00
parent b53b9af4bd
commit b56f6664d5
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
21 changed files with 76 additions and 74 deletions

View File

@ -73,7 +73,7 @@ public class SplineBrush implements Brush {
for (int x = -1; x <= 1; x++) { for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) { for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) { for (int z = -1; z <= 1; z++) {
if (x != 0 || y != 0 && z != 0) { if (x != 0 || y != 0 || z != 0) {
Vector pos = new Vector(x, y, z); Vector pos = new Vector(x, y, z);
if (!directions.contains(pos)) { if (!directions.contains(pos)) {
directions.add(pos); directions.add(pos);

View File

@ -16,6 +16,6 @@ public class PatternTransform extends ResettableExtent {
@Override @Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
return pattern.apply(getExtent(), location); return pattern.apply(getExtent(), location, location);
} }
} }

View File

@ -23,8 +23,8 @@ public class BiomePattern extends ExistingPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
return extent.setBiome(new Vector2D(position.getBlockX(), position.getBlockZ()), biome); return extent.setBiome(new Vector2D(setPosition.getBlockX(), setPosition.getBlockZ()), biome);
} }
public class BiomePatternException extends RuntimeException { public class BiomePatternException extends RuntimeException {

View File

@ -29,11 +29,11 @@ public class Linear3DBlockPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
int index = (position.getBlockX() + position.getBlockY() + position.getBlockZ()) % patternsArray.length; int index = (get.getBlockX() + get.getBlockY() + get.getBlockZ()) % patternsArray.length;
if (index < 0) { if (index < 0) {
index += patternsArray.length; index += patternsArray.length;
} }
return patternsArray[index].apply(extent, position); return patternsArray[index].apply(extent, set, get);
} }
} }

View File

@ -29,11 +29,11 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
if (index == patternsArray.length) { if (index == patternsArray.length) {
index = 0; index = 0;
} }
return patternsArray[index++].apply(extent, position); return patternsArray[index++].apply(extent, set, get);
} }
@Override @Override

View File

@ -35,11 +35,11 @@ public class MaskedPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
patternExtent.setTarget(position); patternExtent.setTarget(get);
if (mask.test(position)) { if (mask.test(get)) {
return patternExtent.getAndResetTarget(extent, position); return patternExtent.getAndResetTarget(extent, set, get);
} }
return secondaryPattern.apply(extent, position); return secondaryPattern.apply(extent, set, get);
} }
} }

View File

@ -26,9 +26,9 @@ public class NoXPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector pos) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutY((pos.getY())); mutable.mutY((get.getY()));
mutable.mutZ((pos.getZ())); mutable.mutZ((get.getZ()));
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} }
} }

View File

@ -26,9 +26,9 @@ public class NoYPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector pos) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutX((pos.getX())); mutable.mutX((get.getX()));
mutable.mutZ((pos.getZ())); mutable.mutZ((get.getZ()));
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} }
} }

View File

@ -26,9 +26,9 @@ public class NoZPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector pos) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutX((pos.getX())); mutable.mutX((get.getX()));
mutable.mutY((pos.getY())); mutable.mutY((get.getY()));
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} }
} }

View File

@ -30,10 +30,10 @@ public class OffsetPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutX((position.getX() + dx)); mutable.mutX((get.getX() + dx));
mutable.mutY((position.getY() + dy)); mutable.mutY((get.getY() + dy));
mutable.mutZ((position.getZ() + dz)); mutable.mutZ((get.getZ() + dz));
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} }
} }

View File

@ -67,13 +67,13 @@ public class PatternExtent extends AbstractPattern implements Extent {
this.target = vector; this.target = vector;
} }
public boolean getAndResetTarget(Extent extent, Vector position) throws WorldEditException { public boolean getAndResetTarget(Extent extent, Vector set, Vector get) throws WorldEditException {
BaseBlock result = block; BaseBlock result = block;
if (result != null) { if (result != null) {
block = null; block = null;
return extent.setBlock(position, result); return extent.setBlock(set, result);
} else { } else {
return pattern.apply(extent, target); return pattern.apply(extent, set, target);
} }
} }
@ -119,7 +119,7 @@ public class PatternExtent extends AbstractPattern implements Extent {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
return pattern.apply(extent, position); return pattern.apply(extent, set, get);
} }
} }

View File

@ -35,10 +35,10 @@ public class RandomOffsetPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); mutable.mutX((get.getX() + r.nextInt(dx2) - dx));
mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); mutable.mutY((get.getY() + r.nextInt(dy2) - dy));
mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz));
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} }
} }

View File

@ -31,14 +31,14 @@ public class RelativePattern extends AbstractPattern implements ResettablePatter
} }
@Override @Override
public boolean apply(Extent extent, Vector pos) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
if (origin == null) { if (origin == null) {
origin = new Vector(pos); origin = new Vector(get);
} }
mutable.mutX((pos.getX() - origin.getX())); mutable.mutX((get.getX() - origin.getX()));
mutable.mutY((pos.getY() - origin.getY())); mutable.mutY((get.getY() - origin.getY()));
mutable.mutZ((pos.getZ() - origin.getZ())); mutable.mutZ((get.getZ() - origin.getZ()));
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} }
@Override @Override

View File

@ -50,15 +50,15 @@ public class SolidRandomOffsetPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); mutable.mutX((get.getX() + r.nextInt(dx2) - dx));
mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); mutable.mutY((get.getY() + r.nextInt(dy2) - dy));
mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz));
BaseBlock block = pattern.apply(mutable); BaseBlock block = pattern.apply(mutable);
if (solid[FaweCache.getCombined(block)]) { if (solid[FaweCache.getCombined(block)]) {
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} else { } else {
return pattern.apply(extent, position); return pattern.apply(extent, set, get);
} }
} }
} }

View File

@ -52,17 +52,17 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); mutable.mutX((get.getX() + r.nextInt(dx2) - dx));
mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); mutable.mutY((get.getY() + r.nextInt(dy2) - dy));
mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz));
BaseBlock block = pattern.apply(mutable); BaseBlock block = pattern.apply(mutable);
if (solid[FaweCache.getCombined(block)]) { if (solid[FaweCache.getCombined(block)]) {
mutable.mutY(mutable.getY() + 1); mutable.mutY(mutable.getY() + 1);
if (!solid[FaweCache.getCombined(pattern.apply(mutable))]) { if (!solid[FaweCache.getCombined(pattern.apply(mutable))]) {
return pattern.apply(extent, mutable); return pattern.apply(extent, set, mutable);
} }
} }
return pattern.apply(extent, position); return pattern.apply(extent, set, get);
} }
} }

View File

@ -180,6 +180,8 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
private FawePlayer player; private FawePlayer player;
private FaweChangeSet changeTask; private FaweChangeSet changeTask;
private MutableBlockVector mutable = new MutableBlockVector();
private int changes = 0; private int changes = 0;
private BlockBag blockBag; private BlockBag blockBag;
@ -1108,7 +1110,8 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
public boolean setBlock(int x, int y, int z, Pattern pattern) { public boolean setBlock(int x, int y, int z, Pattern pattern) {
this.changes++; this.changes++;
try { try {
return pattern.apply(extent, MutableBlockVector.get(x, y, z)); mutable.setComponents(x, y, z);
return pattern.apply(extent, mutable, mutable);
} catch (WorldEditException e) { } catch (WorldEditException e) {
throw new RuntimeException("Unexpected exception", e); throw new RuntimeException("Unexpected exception", e);
} }
@ -1132,7 +1135,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
public boolean setBlock(final Vector position, final Pattern pattern) throws MaxChangedBlocksException { public boolean setBlock(final Vector position, final Pattern pattern) throws MaxChangedBlocksException {
this.changes++; this.changes++;
try { try {
return pattern.apply(this.extent, position); return pattern.apply(this.extent, position, position);
} catch (WorldEditException e) { } catch (WorldEditException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -2943,7 +2946,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
} }
} }
this.changes++; this.changes++;
pattern.apply(this.extent, position); pattern.apply(this.extent, position, position);
} }
} catch (WorldEditException e) { } catch (WorldEditException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -55,7 +55,7 @@ public class BlockReplace implements RegionFunction {
@Override @Override
public boolean apply(Vector position) throws WorldEditException { public boolean apply(Vector position) throws WorldEditException {
return pattern.apply(extent, position); return pattern.apply(extent, position, position);
} }
public static Class<?> inject() { public static Class<?> inject() {

View File

@ -16,6 +16,7 @@ public class ClipboardPattern extends AbstractPattern {
private final Clipboard clipboard; private final Clipboard clipboard;
private final int sx, sy, sz; private final int sx, sy, sz;
private final Vector min; private final Vector min;
private MutableBlockVector mutable = new MutableBlockVector();
/** /**
* Create a new clipboard pattern. * Create a new clipboard pattern.
@ -32,8 +33,6 @@ public class ClipboardPattern extends AbstractPattern {
this.min = clipboard.getMinimumPoint(); this.min = clipboard.getMinimumPoint();
} }
private MutableBlockVector mutable = new MutableBlockVector();
@Override @Override
public BaseBlock apply(Vector position) { public BaseBlock apply(Vector position) {
int xp = position.getBlockX() % sx; int xp = position.getBlockX() % sx;

View File

@ -43,8 +43,8 @@ public class RandomPattern extends AbstractPattern {
} }
@Override @Override
public boolean apply(Extent extent, Vector position) throws WorldEditException { public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
return collection.next().apply(extent, position); return collection.next().apply(extent, set, get);
} }
private static class Chance { private static class Chance {

View File

@ -39,8 +39,8 @@ public interface Pattern{
*/ */
public BaseBlock next(Vector position); public BaseBlock next(Vector position);
default boolean apply(Extent extent, Vector position) throws WorldEditException { default boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
return extent.setBlock(position, next(position)); return extent.setBlock(setPosition, next(getPosition));
} }
/** /**