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