mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 17:56:03 +00:00
add match-all option to AdjacentPatternLocator
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature.locator.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
@@ -17,6 +18,7 @@ import com.dfsek.terra.api.structure.feature.Locator;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
|
||||
@SuppressWarnings({ "FieldCanBeLocal", "FieldMayBeFinal" })
|
||||
public class AdjacentPatternLocatorTemplate implements ObjectTemplate<Locator> {
|
||||
@Value("range")
|
||||
private @Meta Range range;
|
||||
@@ -24,8 +26,12 @@ public class AdjacentPatternLocatorTemplate implements ObjectTemplate<Locator> {
|
||||
@Value("pattern")
|
||||
private @Meta Pattern pattern;
|
||||
|
||||
@Value("match-all")
|
||||
@Default
|
||||
private @Meta boolean matchAll = false;
|
||||
|
||||
@Override
|
||||
public Locator get() {
|
||||
return new AdjacentPatternLocator(pattern, range);
|
||||
return new AdjacentPatternLocator(pattern, range, matchAll);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,12 @@ import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||
public class AdjacentPatternLocator implements Locator {
|
||||
private final Pattern pattern;
|
||||
private final Range search;
|
||||
private final boolean matchAll;
|
||||
|
||||
public AdjacentPatternLocator(Pattern pattern, Range search) {
|
||||
public AdjacentPatternLocator(Pattern pattern, Range search, boolean matchAll) {
|
||||
this.pattern = pattern;
|
||||
this.search = search;
|
||||
this.matchAll = matchAll;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,9 +37,16 @@ public class AdjacentPatternLocator implements Locator {
|
||||
}
|
||||
|
||||
private boolean isValid(int y, Column<?> column) {
|
||||
return pattern.matches(y, column.adjacent(0, -1)) ||
|
||||
pattern.matches(y, column.adjacent(0, 1)) ||
|
||||
pattern.matches(y, column.adjacent(-1, 0)) ||
|
||||
pattern.matches(y, column.adjacent(1, 0));
|
||||
if(matchAll) {
|
||||
return pattern.matches(y, column.adjacent(0, -1)) &&
|
||||
pattern.matches(y, column.adjacent(0, 1)) &&
|
||||
pattern.matches(y, column.adjacent(-1, 0)) &&
|
||||
pattern.matches(y, column.adjacent(1, 0));
|
||||
} else {
|
||||
return pattern.matches(y, column.adjacent(0, -1)) ||
|
||||
pattern.matches(y, column.adjacent(0, 1)) ||
|
||||
pattern.matches(y, column.adjacent(-1, 0)) ||
|
||||
pattern.matches(y, column.adjacent(1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user