mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 06:11:24 +00:00
create AdjacentPatternLocator
This commit is contained in:
+2
@@ -11,6 +11,7 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
|||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.feature.locator.config.AdjacentPatternLocatorTemplate;
|
||||||
import com.dfsek.terra.addons.feature.locator.config.AndLocatorTemplate;
|
import com.dfsek.terra.addons.feature.locator.config.AndLocatorTemplate;
|
||||||
import com.dfsek.terra.addons.feature.locator.config.GaussianRandomLocatorTemplate;
|
import com.dfsek.terra.addons.feature.locator.config.GaussianRandomLocatorTemplate;
|
||||||
import com.dfsek.terra.addons.feature.locator.config.Sampler3DLocatorTemplate;
|
import com.dfsek.terra.addons.feature.locator.config.Sampler3DLocatorTemplate;
|
||||||
@@ -63,6 +64,7 @@ public class LocatorAddon implements AddonInitializer {
|
|||||||
locatorRegistry.register(addon.key("GAUSSIAN_RANDOM"), GaussianRandomLocatorTemplate::new);
|
locatorRegistry.register(addon.key("GAUSSIAN_RANDOM"), GaussianRandomLocatorTemplate::new);
|
||||||
|
|
||||||
locatorRegistry.register(addon.key("PATTERN"), PatternLocatorTemplate::new);
|
locatorRegistry.register(addon.key("PATTERN"), PatternLocatorTemplate::new);
|
||||||
|
locatorRegistry.register(addon.key("ADJACENT_PATTERN"), AdjacentPatternLocatorTemplate::new);
|
||||||
|
|
||||||
locatorRegistry.register(addon.key("SAMPLER"), SamplerLocatorTemplate::new);
|
locatorRegistry.register(addon.key("SAMPLER"), SamplerLocatorTemplate::new);
|
||||||
locatorRegistry.register(addon.key("SAMPLER_3D"), Sampler3DLocatorTemplate::new);
|
locatorRegistry.register(addon.key("SAMPLER_3D"), Sampler3DLocatorTemplate::new);
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
*
|
||||||
|
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in this module's root directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.dfsek.terra.addons.feature.locator.config;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||||
|
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.feature.locator.locators.AdjacentPatternLocator;
|
||||||
|
import com.dfsek.terra.addons.feature.locator.patterns.Pattern;
|
||||||
|
import com.dfsek.terra.api.config.meta.Meta;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Locator;
|
||||||
|
import com.dfsek.terra.api.util.Range;
|
||||||
|
|
||||||
|
|
||||||
|
public class AdjacentPatternLocatorTemplate implements ObjectTemplate<Locator> {
|
||||||
|
@Value("range")
|
||||||
|
private @Meta Range range;
|
||||||
|
|
||||||
|
@Value("pattern")
|
||||||
|
private @Meta Pattern pattern;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Locator get() {
|
||||||
|
return new AdjacentPatternLocator(pattern, range);
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 Polyhedral Development
|
||||||
|
*
|
||||||
|
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||||
|
* reference the LICENSE file in this module's root directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.dfsek.terra.addons.feature.locator.locators;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.feature.locator.patterns.Pattern;
|
||||||
|
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Locator;
|
||||||
|
import com.dfsek.terra.api.util.Range;
|
||||||
|
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||||
|
|
||||||
|
|
||||||
|
public class AdjacentPatternLocator implements Locator {
|
||||||
|
private final Pattern pattern;
|
||||||
|
private final Range search;
|
||||||
|
|
||||||
|
public AdjacentPatternLocator(Pattern pattern, Range search) {
|
||||||
|
this.pattern = pattern;
|
||||||
|
this.search = search;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BinaryColumn getSuitableCoordinates(Column<?> column) {
|
||||||
|
BinaryColumn locations = new BinaryColumn(column.getMinY(), column.getMaxY());
|
||||||
|
|
||||||
|
for(int y : search) {
|
||||||
|
if(isValid(y, column)) locations.set(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
return locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user