Add offset pattern

This commit is contained in:
Jesse Boyd 2016-09-28 23:19:00 +10:00
parent 7da883b9d7
commit b414229c91
2 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,25 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
public class OffsetPattern extends AbstractPattern {
private final int dx,dy,dz;
private final Vector mutable = new Vector();
public OffsetPattern(int dx, int dy, int dz) {
this.dx = dx;
this.dy = dy;
this.dz = dz;
}
@Override
public BaseBlock apply(Vector position) {
mutable.x = position.x + dx;
mutable.y = position.y + dy;
mutable.z = position.z + dz;
return null;
}
}

View File

@ -7,6 +7,7 @@ import com.boydti.fawe.object.pattern.MaskedPattern;
import com.boydti.fawe.object.pattern.NoXPattern; import com.boydti.fawe.object.pattern.NoXPattern;
import com.boydti.fawe.object.pattern.NoYPattern; import com.boydti.fawe.object.pattern.NoYPattern;
import com.boydti.fawe.object.pattern.NoZPattern; import com.boydti.fawe.object.pattern.NoZPattern;
import com.boydti.fawe.object.pattern.OffsetPattern;
import com.boydti.fawe.object.pattern.PatternExtent; import com.boydti.fawe.object.pattern.PatternExtent;
import com.boydti.fawe.object.pattern.RandomOffsetPattern; import com.boydti.fawe.object.pattern.RandomOffsetPattern;
import com.boydti.fawe.object.pattern.RelativePattern; import com.boydti.fawe.object.pattern.RelativePattern;
@ -123,6 +124,17 @@ public class HashTagPatternParser extends InputParser<Pattern> {
} }
return new MaskedPattern(mask, extent, secondary); return new MaskedPattern(mask, extent, secondary);
} }
case "#offset":
try {
int x = Math.abs(Integer.parseInt(split2[1]));
int y = Math.abs(Integer.parseInt(split2[2]));
int z = Math.abs(Integer.parseInt(split2[3]));
rest = rest.substring(split2[1].length() + split2[2].length() + split2[3].length() + 3);
Pattern pattern = parseFromInput(rest, context);
return new OffsetPattern(x, y, z);
} catch (NumberFormatException e) {
throw new InputParseException("The correct format is #offset:<dx>:<dy>:<dz>:<pattern>");
}
case "#randomoffset": case "#randomoffset":
case "#spread": { case "#spread": {
try { try {
@ -133,7 +145,7 @@ public class HashTagPatternParser extends InputParser<Pattern> {
Pattern pattern = parseFromInput(rest, context); Pattern pattern = parseFromInput(rest, context);
return new RandomOffsetPattern(pattern, x, y, z); return new RandomOffsetPattern(pattern, x, y, z);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new InputParseException("The correct format is #spread:<dx>:<dy>:<dz>:<pattern>");
} }
} }
case "#l": case "#l":