From b181e8e4008fca4b933d09fce9e7281527b1ba81 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 23 Aug 2017 11:48:44 +1000 Subject: [PATCH] Add l2d --- .../object/pattern/Linear2DBlockPattern.java | 35 +++++++++++++++++++ .../worldedit/command/PatternCommands.java | 16 +++++++++ 2 files changed, 51 insertions(+) create mode 100644 core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java diff --git a/core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java b/core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java new file mode 100644 index 00000000..be0bbf5b --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java @@ -0,0 +1,35 @@ +package com.boydti.fawe.object.pattern; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.pattern.AbstractPattern; +import com.sk89q.worldedit.function.pattern.Pattern; + +public class Linear2DBlockPattern extends AbstractPattern { + + private final Pattern[] patternsArray; + + public Linear2DBlockPattern(Pattern[] patterns) { + this.patternsArray = patterns; + } + + @Override + public BaseBlock apply(Vector position) { + int index = (position.getBlockX() + position.getBlockZ()) % patternsArray.length; + if (index < 0) { + index += patternsArray.length; + } + return patternsArray[index].apply(position); + } + + @Override + public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + int index = (get.getBlockX() + get.getBlockZ()) % patternsArray.length; + if (index < 0) { + index += patternsArray.length; + } + return patternsArray[index].apply(extent, set, get); + } +} diff --git a/core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java b/core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java index ce9a2881..314ffdf8 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/PatternCommands.java @@ -16,6 +16,7 @@ import com.boydti.fawe.object.pattern.ExpressionPattern; import com.boydti.fawe.object.pattern.FullClipboardPattern; import com.boydti.fawe.object.pattern.IdDataMaskPattern; import com.boydti.fawe.object.pattern.IdPattern; +import com.boydti.fawe.object.pattern.Linear2DBlockPattern; import com.boydti.fawe.object.pattern.Linear3DBlockPattern; import com.boydti.fawe.object.pattern.LinearBlockPattern; import com.boydti.fawe.object.pattern.MaskedPattern; @@ -433,6 +434,21 @@ public class PatternCommands extends MethodCommands { return other; } + @Command( + aliases = {"#linear2d", "#l2d"}, + desc = "Use the x,z coordinate to pick a block from the list", + usage = "", + min = 1, + max = 1 + ) + public Pattern linear2d(Actor actor, LocalSession session, Pattern other) { + if (other instanceof RandomPattern) { + Set patterns = ((RandomPattern) other).getPatterns(); + return new Linear2DBlockPattern(patterns.toArray(new Pattern[patterns.size()])); + } + return other; + } + @Command( aliases = {"="}, desc = "Expression pattern: http://wiki.sk89q.com/wiki/WorldEdit/Expression_syntax",