From b414229c917c7e8744af5f4bbbab64cc28d09b7a Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 28 Sep 2016 23:19:00 +1000 Subject: [PATCH] Add offset pattern --- .../fawe/object/pattern/OffsetPattern.java | 25 +++++++++++++++++++ .../factory/HashTagPatternParser.java | 14 ++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java new file mode 100644 index 00000000..e3881132 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java @@ -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; + } +} diff --git a/core/src/main/java/com/sk89q/worldedit/extension/factory/HashTagPatternParser.java b/core/src/main/java/com/sk89q/worldedit/extension/factory/HashTagPatternParser.java index f5a4a1e8..d794cfbe 100644 --- a/core/src/main/java/com/sk89q/worldedit/extension/factory/HashTagPatternParser.java +++ b/core/src/main/java/com/sk89q/worldedit/extension/factory/HashTagPatternParser.java @@ -7,6 +7,7 @@ import com.boydti.fawe.object.pattern.MaskedPattern; import com.boydti.fawe.object.pattern.NoXPattern; import com.boydti.fawe.object.pattern.NoYPattern; 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.RandomOffsetPattern; import com.boydti.fawe.object.pattern.RelativePattern; @@ -123,6 +124,17 @@ public class HashTagPatternParser extends InputParser { } 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::::"); + } case "#randomoffset": case "#spread": { try { @@ -133,7 +145,7 @@ public class HashTagPatternParser extends InputParser { Pattern pattern = parseFromInput(rest, context); return new RandomOffsetPattern(pattern, x, y, z); } catch (NumberFormatException e) { - + throw new InputParseException("The correct format is #spread::::"); } } case "#l":