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 y = -1; y <= 1; y++) {
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);
if (!directions.contains(pos)) {
directions.add(pos);

View File

@ -1,8 +1,8 @@
package com.boydti.fawe.object.brush;
public enum TargetMode {
TARGET_BLOCK_RANGE,
FOWARD_POINT_PITCH,
TARGET_POINT_HEIGHT,
TARGET_FACE_RANGE,
TARGET_BLOCK_RANGE,
FOWARD_POINT_PITCH,
TARGET_POINT_HEIGHT,
TARGET_FACE_RANGE,
}

View File

@ -16,6 +16,6 @@ public class PatternTransform extends ResettableExtent {
@Override
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
public boolean apply(Extent extent, Vector position) throws WorldEditException {
return extent.setBiome(new Vector2D(position.getBlockX(), position.getBlockZ()), biome);
public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException {
return extent.setBiome(new Vector2D(setPosition.getBlockX(), setPosition.getBlockZ()), biome);
}
public class BiomePatternException extends RuntimeException {

View File

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

View File

@ -35,11 +35,11 @@ public class MaskedPattern extends AbstractPattern {
}
@Override
public boolean apply(Extent extent, Vector position) throws WorldEditException {
patternExtent.setTarget(position);
if (mask.test(position)) {
return patternExtent.getAndResetTarget(extent, position);
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
patternExtent.setTarget(get);
if (mask.test(get)) {
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
public boolean apply(Extent extent, Vector pos) throws WorldEditException {
mutable.mutY((pos.getY()));
mutable.mutZ((pos.getZ()));
return pattern.apply(extent, mutable);
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutY((get.getY()));
mutable.mutZ((get.getZ()));
return pattern.apply(extent, set, mutable);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -52,17 +52,17 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern {
}
@Override
public boolean apply(Extent extent, Vector position) throws WorldEditException {
mutable.mutX((position.getX() + r.nextInt(dx2) - dx));
mutable.mutY((position.getY() + r.nextInt(dy2) - dy));
mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz));
public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException {
mutable.mutX((get.getX() + r.nextInt(dx2) - dx));
mutable.mutY((get.getY() + r.nextInt(dy2) - dy));
mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz));
BaseBlock block = pattern.apply(mutable);
if (solid[FaweCache.getCombined(block)]) {
mutable.mutY(mutable.getY() + 1);
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 FaweChangeSet changeTask;
private MutableBlockVector mutable = new MutableBlockVector();
private int changes = 0;
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) {
this.changes++;
try {
return pattern.apply(extent, MutableBlockVector.get(x, y, z));
mutable.setComponents(x, y, z);
return pattern.apply(extent, mutable, mutable);
} catch (WorldEditException 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 {
this.changes++;
try {
return pattern.apply(this.extent, position);
return pattern.apply(this.extent, position, position);
} catch (WorldEditException e) {
throw new RuntimeException(e);
}
@ -2943,7 +2946,7 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
}
}
this.changes++;
pattern.apply(this.extent, position);
pattern.apply(this.extent, position, position);
}
} catch (WorldEditException e) {
throw new RuntimeException(e);

View File

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

View File

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

View File

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

View File

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