Finish new patterns
This commit is contained in:
parent
1e79ae4a0f
commit
bd90df7635
@ -0,0 +1,28 @@
|
|||||||
|
package com.boydti.fawe.object.pattern;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
||||||
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class Linear3DBlockPattern extends AbstractPattern {
|
||||||
|
|
||||||
|
private final Collection<Pattern> patterns;
|
||||||
|
private final Pattern[] patternsArray;
|
||||||
|
|
||||||
|
public Linear3DBlockPattern(Pattern[] patterns) {
|
||||||
|
this.patternsArray = patterns;
|
||||||
|
this.patterns = Arrays.asList(patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock apply(Vector position) {
|
||||||
|
int index = (position.getBlockX() + position.getBlockY() + position.getBlockZ()) % patternsArray.length;
|
||||||
|
if (index < 0) {
|
||||||
|
index += patternsArray.length;
|
||||||
|
}
|
||||||
|
return patternsArray[index].apply(position);
|
||||||
|
}
|
||||||
|
}
|
@ -3,21 +3,31 @@ package com.boydti.fawe.object.pattern;
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
import com.sk89q.worldedit.function.pattern.AbstractPattern;
|
||||||
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class LinearBlockPattern extends AbstractPattern {
|
public class LinearBlockPattern extends AbstractPattern implements ResettablePattern {
|
||||||
|
|
||||||
private final BaseBlock[] blocks;
|
private final Collection<Pattern> patterns;
|
||||||
|
private final Pattern[] patternsArray;
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
public LinearBlockPattern(BaseBlock[] blocks) {
|
public LinearBlockPattern(Pattern[] patterns) {
|
||||||
this.blocks = blocks;
|
this.patternsArray = patterns;
|
||||||
|
this.patterns = Arrays.asList(patterns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseBlock apply(Vector position) {
|
public BaseBlock apply(Vector position) {
|
||||||
if (index == blocks.length) {
|
if (index == patternsArray.length) {
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
return blocks[index++];
|
return patternsArray[index++].apply(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.sk89q.worldedit.extension.factory;
|
package com.sk89q.worldedit.extension.factory;
|
||||||
|
|
||||||
import com.boydti.fawe.object.pattern.ExistingPattern;
|
import com.boydti.fawe.object.pattern.ExistingPattern;
|
||||||
|
import com.boydti.fawe.object.pattern.Linear3DBlockPattern;
|
||||||
import com.boydti.fawe.object.pattern.LinearBlockPattern;
|
import com.boydti.fawe.object.pattern.LinearBlockPattern;
|
||||||
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;
|
||||||
@ -9,7 +10,6 @@ import com.boydti.fawe.object.pattern.RelativePattern;
|
|||||||
import com.sk89q.worldedit.EmptyClipboardException;
|
import com.sk89q.worldedit.EmptyClipboardException;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
@ -32,6 +32,7 @@ public class HashTagPatternParser extends InputParser<Pattern> {
|
|||||||
switch (input.toLowerCase().charAt(0)) {
|
switch (input.toLowerCase().charAt(0)) {
|
||||||
case '#': {
|
case '#': {
|
||||||
switch (input) {
|
switch (input) {
|
||||||
|
case "#*":
|
||||||
case "#existing": {
|
case "#existing": {
|
||||||
return new ExistingPattern(context.requireExtent());
|
return new ExistingPattern(context.requireExtent());
|
||||||
}
|
}
|
||||||
@ -53,40 +54,55 @@ public class HashTagPatternParser extends InputParser<Pattern> {
|
|||||||
}
|
}
|
||||||
String[] split2 = input.split(":");
|
String[] split2 = input.split(":");
|
||||||
if (split2.length > 1) {
|
if (split2.length > 1) {
|
||||||
switch (split2[0]) {
|
String rest = input.substring(split2[0].length() + 1);
|
||||||
|
switch (split2[0].toLowerCase()) {
|
||||||
|
case "#~":
|
||||||
|
case "#r":
|
||||||
case "#relative":
|
case "#relative":
|
||||||
case "#rel": {
|
case "#rel": {
|
||||||
String rest = input.substring(5);
|
|
||||||
return new RelativePattern(parseFromInput(rest, context));
|
return new RelativePattern(parseFromInput(rest, context));
|
||||||
}
|
}
|
||||||
|
case "#!x":
|
||||||
|
case "#nx":
|
||||||
case "#nox": {
|
case "#nox": {
|
||||||
String rest = input.substring(5);
|
|
||||||
return new NoXPattern(parseFromInput(rest, context));
|
return new NoXPattern(parseFromInput(rest, context));
|
||||||
}
|
}
|
||||||
|
case "#!y":
|
||||||
|
case "#ny":
|
||||||
case "#noy": {
|
case "#noy": {
|
||||||
String rest = input.substring(5);
|
|
||||||
return new NoYPattern(parseFromInput(rest, context));
|
return new NoYPattern(parseFromInput(rest, context));
|
||||||
}
|
}
|
||||||
|
case "#!z":
|
||||||
|
case "#nz":
|
||||||
case "#noz": {
|
case "#noz": {
|
||||||
String rest = input.substring(5);
|
|
||||||
return new NoZPattern(parseFromInput(rest, context));
|
return new NoZPattern(parseFromInput(rest, context));
|
||||||
}
|
}
|
||||||
|
case "#l":
|
||||||
|
case "#linear": {
|
||||||
|
ArrayList<Pattern> patterns = new ArrayList<>();
|
||||||
|
for (String token : rest.split(",")) {
|
||||||
|
patterns.add(parseFromInput(token, context));
|
||||||
|
}
|
||||||
|
if (patterns.isEmpty()) {
|
||||||
|
throw new InputParseException("No blocks provided for linear pattern e.g. [stone,wood");
|
||||||
|
}
|
||||||
|
return new LinearBlockPattern(patterns.toArray(new Pattern[patterns.size()]));
|
||||||
|
}
|
||||||
|
case "#l3d":
|
||||||
|
case "#linear3D": {
|
||||||
|
ArrayList<Pattern> patterns = new ArrayList<>();
|
||||||
|
for (String token : rest.split(",")) {
|
||||||
|
patterns.add(parseFromInput(token, context));
|
||||||
|
}
|
||||||
|
if (patterns.isEmpty()) {
|
||||||
|
throw new InputParseException("No blocks provided for linear pattern e.g. [stone,wood");
|
||||||
|
}
|
||||||
|
return new Linear3DBlockPattern(patterns.toArray(new Pattern[patterns.size()]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new InputParseException("Invalid, see: https://github.com/boy0001/FastAsyncWorldedit/wiki/WorldEdit-and-FAWE-patterns");
|
throw new InputParseException("Invalid, see: https://github.com/boy0001/FastAsyncWorldedit/wiki/WorldEdit-and-FAWE-patterns");
|
||||||
}
|
}
|
||||||
case '[': {
|
|
||||||
ArrayList<BaseBlock> blocks = new ArrayList<>();
|
|
||||||
for (String token : input.substring(1).split(",")) {
|
|
||||||
BlockFactory blockRegistry = worldEdit.getBlockFactory();
|
|
||||||
BaseBlock block = blockRegistry.parseFromInput(token, context);
|
|
||||||
blocks.add(block);
|
|
||||||
}
|
|
||||||
if (blocks.isEmpty()) {
|
|
||||||
throw new InputParseException("No blocks provided for linear pattern e.g. [stone,wood");
|
|
||||||
}
|
|
||||||
return new LinearBlockPattern(blocks.toArray(new BaseBlock[blocks.size()]));
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
String[] items = input.split(",");
|
String[] items = input.split(",");
|
||||||
if (items.length == 1) {
|
if (items.length == 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user