This commit is contained in:
Jesse Boyd 2017-08-23 11:48:44 +10:00
parent b979db514e
commit b181e8e400
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 51 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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 = "<pattern>",
min = 1,
max = 1
)
public Pattern linear2d(Actor actor, LocalSession session, Pattern other) {
if (other instanceof RandomPattern) {
Set<Pattern> 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",