mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-21 01:00:37 +00:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e6300df185 | |||
| 65eb66c3ca | |||
| aa3fe18339 | |||
| 6a6a3928cd | |||
| ac1258d233 | |||
| b6d42fdcc1 | |||
| a9251fa228 | |||
| 38a1571941 | |||
| b9af66848a | |||
| e9d30b8794 | |||
| 53dafa4a2c | |||
| df46c617f2 | |||
| e706ef89fc | |||
| a66c2a0749 | |||
| a5fe4d7928 | |||
| 966bcab370 | |||
| eae5a60cf9 | |||
| 9357b18964 | |||
| 86bb4d5a1a | |||
| 47bdd66fe7 | |||
| eb6b3704d0 | |||
| 8eb5a70d4d | |||
| 5dc9f419ac | |||
| 2215ea8336 | |||
| 998b6478f3 | |||
| efa4bf5bb4 | |||
| 2ad05cbbb6 | |||
| 1bbedf51b5 | |||
| bdcd93f164 | |||
| c4a366112e | |||
| cb08401536 | |||
| 9a16336f53 | |||
| 16705057e0 | |||
| d52cd0d7cf | |||
| 7d3382e623 | |||
| 87e437f889 | |||
| 292be6bcec | |||
| f03f39f1d7 | |||
| 8bfff6b010 | |||
| e5d30183ef | |||
| 3777fda641 | |||
| f684c60039 | |||
| ef088dd3f7 | |||
| 4f672dfb7b | |||
| b851b2f881 | |||
| 9c64353111 | |||
| c537605880 |
+1
-1
@@ -15,7 +15,7 @@ public class ApiAddon implements BaseAddon {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
public Version version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class ApiAddonLoader implements BootstrapBaseAddon<BaseAddon> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
public Version version() {
|
||||
return VERSION;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -66,12 +66,12 @@ public class ManifestAddon implements BaseAddon {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, VersionRange> getDependencies() {
|
||||
public Map<String, VersionRange> dependencies() {
|
||||
return manifest.getDependencies();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
public Version version() {
|
||||
return manifest.getVersion();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -132,7 +132,7 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
public Version version() {
|
||||
return VERSION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
schema-version: 1
|
||||
contributors:
|
||||
- Terra contributors
|
||||
id: biome-query-api
|
||||
id: api-biome-query
|
||||
version: @VERSION@
|
||||
entrypoints:
|
||||
- "com.dfsek.terra.addons.biome.query.BiomeQueryAPIAddon"
|
||||
@@ -0,0 +1,7 @@
|
||||
version = version("1.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
|
||||
|
||||
}
|
||||
+2
-2
@@ -17,7 +17,7 @@ import com.dfsek.terra.addons.image.image.Image;
|
||||
import com.dfsek.terra.addons.image.image.SuppliedImage;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.generic.Memo;
|
||||
|
||||
import static com.dfsek.terra.api.util.cache.CacheUtils.CACHE_EXECUTOR;
|
||||
|
||||
@@ -41,7 +41,7 @@ record ImageCache(LoadingCache<String, Image> cache) implements Properties {
|
||||
return new SuppliedImage(() -> images.cache.get(path));
|
||||
} else {
|
||||
// If images do not time out, image can be lazily loaded once instead of performing cache lookups for each image operation
|
||||
Lazy<Image> lazyImage = Lazy.lazy(() -> images.cache.get(path));
|
||||
Memo<Image> lazyImage = Memo.lazy(() -> images.cache.get(path));
|
||||
return new SuppliedImage(lazyImage::value);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
schema-version: 1
|
||||
contributors:
|
||||
- Terra contributors
|
||||
id: library-image
|
||||
id: api-image
|
||||
version: @VERSION@
|
||||
entrypoints:
|
||||
- "com.dfsek.terra.addons.image.ImageLibraryAddon"
|
||||
@@ -1,6 +1,6 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:biome-query-api"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
compileOnlyApi(project(":common:addons:api-biome-query"))
|
||||
}
|
||||
|
||||
+3
-2
@@ -9,6 +9,7 @@ import com.dfsek.terra.addons.biome.extrusion.api.Extrusion;
|
||||
import com.dfsek.terra.addons.biome.extrusion.utils.ExtrusionPipeline;
|
||||
import com.dfsek.terra.addons.biome.extrusion.utils.ExtrusionPipelineFactory;
|
||||
import com.dfsek.terra.api.util.Column;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Maybe;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
@@ -39,11 +40,11 @@ public class BiomeExtrusionProvider implements BiomeProvider {
|
||||
public Column<Biome> getColumn(int x, int z, long seed, int min, int max) {
|
||||
return delegate.getBaseBiome(x, z, seed)
|
||||
.map(base -> (Column<Biome>) new BaseBiomeColumn(this, base, min, max, x, z, seed))
|
||||
.orElseGet(() -> BiomeProvider.super.getColumn(x, z, seed, min, max));
|
||||
.get(() -> BiomeProvider.super.getColumn(x, z, seed, min, max));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
public Maybe<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
return delegate.getBaseBiome(x, z, seed);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,6 +27,6 @@ public class ReplaceableBiomeLoader implements TypeLoader<ReplaceableBiome> {
|
||||
return biomeRegistry
|
||||
.getByID((String) c)
|
||||
.map(ReplaceableBiome::of)
|
||||
.orElseThrow(() -> new LoadException("No such biome: " + c, depthTracker));
|
||||
.collectThrow(left -> new LoadException("No such biome: " + c + ": " + left, depthTracker));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ website:
|
||||
docs: https://terra.polydev.org
|
||||
license: MIT License
|
||||
depends:
|
||||
biome-query-api: "1.+"
|
||||
api-biome-query: "1.+"
|
||||
@@ -1,5 +1,5 @@
|
||||
# biome-provider-image-v2
|
||||
|
||||
Implements and registers the `IMAGE` biome provider, which
|
||||
utilizes various config types provided by the `library-image` addon to
|
||||
utilizes various config types provided by the `api-image` addon to
|
||||
distribute biomes based on images.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
version = version("2.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:library-image"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
compileOnlyApi(project(":common:addons:api-image"))
|
||||
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -11,6 +11,7 @@ import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
|
||||
import com.dfsek.terra.addons.image.converter.ColorConverter;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Maybe;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
@@ -40,8 +41,8 @@ public class ImageBiomeProvider implements BiomeProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
return Optional.of(getBiome(x, z));
|
||||
public Maybe<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
return Maybe.just(getBiome(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,4 +11,4 @@ website:
|
||||
docs: https://terra.polydev.org
|
||||
license: MIT License
|
||||
depends:
|
||||
library-image: "1.+"
|
||||
api-image: "1.+"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("2.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
+5
-2
@@ -8,6 +8,9 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline;
|
||||
|
||||
import com.dfsek.seismic.type.sampler.Sampler;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.data.types.Maybe;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
|
||||
@@ -106,8 +109,8 @@ public class PipelineBiomeProvider implements BiomeProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
return Optional.of(getBiome(x, z, seed));
|
||||
public Maybe<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
return Maybe.just(getBiome(x, z, seed));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.biome.PipelineBiome;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
@@ -27,6 +28,6 @@ public class PipelineBiomeLoader implements TypeLoader<PipelineBiome> {
|
||||
return biomeRegistry
|
||||
.getByID((String) c)
|
||||
.map(PipelineBiome::from)
|
||||
.orElseGet(() -> PipelineBiome.placeholder((String) c));
|
||||
.collect(left -> PipelineBiome.placeholder((String) c), Function.identity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
+4
-9
@@ -8,18 +8,13 @@
|
||||
package com.dfsek.terra.addons.biome.single;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.data.types.Maybe;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class SingleBiomeProvider implements BiomeProvider {
|
||||
private final Biome biome;
|
||||
|
||||
public SingleBiomeProvider(Biome biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
public record SingleBiomeProvider(Biome biome) implements BiomeProvider {
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int y, int z, long seed) {
|
||||
@@ -27,8 +22,8 @@ public class SingleBiomeProvider implements BiomeProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
return Optional.of(biome);
|
||||
public Maybe<Biome> getBaseBiome(int x, int z, long seed) {
|
||||
return Maybe.just(biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.2.1")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class ElevationInterpolator {
|
||||
gens[x + 1 + smooth][z + 1 + smooth] =
|
||||
provider
|
||||
.getBaseBiome(bx, bz, seed)
|
||||
.orElseGet(() -> provider.getBiome(bx, 0, bz, seed)) // kind of a hack
|
||||
.get(() -> provider.getBiome(bx, 0, bz, seed)) // kind of a hack
|
||||
.getContext()
|
||||
.get(noisePropertiesKey);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
+3
-3
@@ -39,7 +39,7 @@ public class AddonsCommandAddon implements AddonInitializer {
|
||||
.append(" - ")
|
||||
.append(addon.getID())
|
||||
.append('@')
|
||||
.append(addon.getVersion().getFormatted())
|
||||
.append(addon.version().getFormatted())
|
||||
.append('\n'));
|
||||
context.sender().sendMessage(addons.toString());
|
||||
})
|
||||
@@ -52,10 +52,10 @@ public class AddonsCommandAddon implements AddonInitializer {
|
||||
BaseAddon addon = context.get("addon");
|
||||
StringBuilder addonInfo = new StringBuilder("Addon ").append(addon.getID()).append('\n');
|
||||
|
||||
addonInfo.append("Version: ").append(addon.getVersion().getFormatted()).append('\n');
|
||||
addonInfo.append("Version: ").append(addon.version().getFormatted()).append('\n');
|
||||
|
||||
addonInfo.append("Dependencies:\n");
|
||||
addon.getDependencies().forEach((id, versions) -> addonInfo
|
||||
addon.dependencies().forEach((id, versions) -> addonInfo
|
||||
.append(" - ")
|
||||
.append(id)
|
||||
.append('@')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
+57
-52
@@ -2,10 +2,13 @@ package com.dfsek.terra.addons.commands.locate;
|
||||
|
||||
import com.dfsek.seismic.type.vector.Vector2Int;
|
||||
import com.dfsek.seismic.type.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.util.generic.either.Either;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.data.types.Either;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Maybe;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -13,6 +16,8 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
import static com.dfsek.terra.api.util.function.FunctionUtils.*;
|
||||
|
||||
|
||||
public class BiomeLocator {
|
||||
|
||||
@@ -27,9 +32,10 @@ public class BiomeLocator {
|
||||
* @param step The search step/increment. Higher values are faster but less accurate.
|
||||
* @param filter The condition to match the biome.
|
||||
* @param search3D If true, searches the entire vertical column at each step. If false, only checks originY.
|
||||
*
|
||||
* @return An Optional containing the location of the found biome, or empty if not found.
|
||||
*/
|
||||
public static Optional<Either<Vector3Int, Vector2Int>> search(
|
||||
public static Maybe<Either<Vector3Int, Vector2Int>> search(
|
||||
@NotNull BiomeProvider provider,
|
||||
@NotNull WorldProperties properties,
|
||||
int originX,
|
||||
@@ -44,64 +50,63 @@ public class BiomeLocator {
|
||||
int maxHeight = properties.getMaxHeight();
|
||||
|
||||
// 1. Check the exact center first
|
||||
Optional<Either<Vector3Int, Vector2Int>> centerResult = check(provider, seed, originX, originZ, step, filter, search3D, minHeight, maxHeight);
|
||||
if (centerResult.isPresent()) {
|
||||
return centerResult;
|
||||
}
|
||||
return
|
||||
check(provider, seed, originX, originZ, step, filter, search3D, minHeight, maxHeight)
|
||||
|
||||
// 2. Begin Parallel Square Spiral Search
|
||||
// We iterate rings sequentially to guarantee finding the *nearest* result.
|
||||
// However, we process all points within a specific ring in parallel.
|
||||
for (int r = step; r <= radius; r += step) {
|
||||
final int currentRadius = r;
|
||||
final int minX = -currentRadius;
|
||||
final int maxX = currentRadius;
|
||||
final int minZ = -currentRadius;
|
||||
final int maxZ = currentRadius;
|
||||
// 2. Begin Parallel Square Spiral Search
|
||||
// We iterate rings sequentially to guarantee finding the *nearest* result.
|
||||
// However, we process all points within a specific ring in parallel.
|
||||
.or(() -> {
|
||||
for(int r = step; r <= radius; r += step) {
|
||||
final int currentRadius = r;
|
||||
final int minX = -currentRadius;
|
||||
final int maxX = currentRadius;
|
||||
final int minZ = -currentRadius;
|
||||
final int maxZ = currentRadius;
|
||||
|
||||
Stream<int[]> northSide = IntStream.iterate(minX, n -> n < maxX, n -> n + step)
|
||||
.mapToObj(x -> new int[]{x, minZ}); // Fixed Z (min), varying X
|
||||
Stream<int[]> northSide = IntStream.iterate(minX, n -> n < maxX, n -> n + step)
|
||||
.mapToObj(x -> new int[]{ x, minZ }); // Fixed Z (min), varying X
|
||||
|
||||
Stream<int[]> eastSide = IntStream.iterate(minZ, n -> n < maxZ, n -> n + step)
|
||||
.mapToObj(z -> new int[]{maxX, z}); // Fixed X (max), varying Z
|
||||
Stream<int[]> eastSide = IntStream.iterate(minZ, n -> n < maxZ, n -> n + step)
|
||||
.mapToObj(z -> new int[]{ maxX, z }); // Fixed X (max), varying Z
|
||||
|
||||
Stream<int[]> southSide = IntStream.iterate(maxX, n -> n > minX, n -> n - step)
|
||||
.mapToObj(x -> new int[]{x, maxZ}); // Fixed Z (max), varying X
|
||||
Stream<int[]> southSide = IntStream.iterate(maxX, n -> n > minX, n -> n - step)
|
||||
.mapToObj(x -> new int[]{ x, maxZ }); // Fixed Z (max), varying X
|
||||
|
||||
Stream<int[]> westSide = IntStream.iterate(maxZ, n -> n > minZ, n -> n - step)
|
||||
.mapToObj(z -> new int[]{minX, z}); // Fixed X (min), varying Z
|
||||
Stream<int[]> westSide = IntStream.iterate(maxZ, n -> n > minZ, n -> n - step)
|
||||
.mapToObj(z -> new int[]{ minX, z }); // Fixed X (min), varying Z
|
||||
|
||||
Optional<Either<Vector3Int, Vector2Int>> ringResult = Stream.of(northSide, eastSide, southSide, westSide)
|
||||
.flatMap(Function.identity())
|
||||
.parallel()
|
||||
.map(coords -> check(
|
||||
provider,
|
||||
seed,
|
||||
originX + coords[0],
|
||||
originZ + coords[1],
|
||||
step,
|
||||
filter,
|
||||
search3D,
|
||||
minHeight,
|
||||
maxHeight
|
||||
))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.findFirst(); // findFirst() respects encounter order (North -> East -> South -> West)
|
||||
Optional<Either<Vector3Int, Vector2Int>> ringResult = Stream.of(northSide, eastSide, southSide, westSide)
|
||||
.flatMap(identity())
|
||||
.parallel()
|
||||
.map(coords -> check(
|
||||
provider,
|
||||
seed,
|
||||
originX + coords[0],
|
||||
originZ + coords[1],
|
||||
step,
|
||||
filter,
|
||||
search3D,
|
||||
minHeight,
|
||||
maxHeight
|
||||
))
|
||||
.flatMap(Maybe::toStream)
|
||||
.findFirst(); // findFirst() respects encounter order (North -> East -> South -> West)
|
||||
|
||||
if (ringResult.isPresent()) {
|
||||
return ringResult;
|
||||
}
|
||||
}
|
||||
if(ringResult.isPresent()) {
|
||||
return fromOptional(ringResult);
|
||||
}
|
||||
}
|
||||
return nothing();
|
||||
});
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to check a specific coordinate column or point.
|
||||
* This logic is executed inside the worker threads.
|
||||
*/
|
||||
private static Optional<Either<Vector3Int, Vector2Int>> check(
|
||||
private static Maybe<Either<Vector3Int, Vector2Int>> check(
|
||||
BiomeProvider provider,
|
||||
long seed,
|
||||
int x,
|
||||
@@ -112,20 +117,20 @@ public class BiomeLocator {
|
||||
int minHeight,
|
||||
int maxHeight
|
||||
) {
|
||||
if (search3D) {
|
||||
if(search3D) {
|
||||
// Iterate from bottom to top of the world using the step
|
||||
for (int y = minHeight; y < maxHeight; y += step) {
|
||||
if (filter.test(provider.getBiome(x, y, z, seed))) {
|
||||
return Optional.of(Either.left(Vector3Int.of(x, y, z)));
|
||||
for(int y = minHeight; y < maxHeight; y += step) {
|
||||
if(filter.test(provider.getBiome(x, y, z, seed))) {
|
||||
return just(left(Vector3Int.of(x, y, z)));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
return nothing();
|
||||
} else {
|
||||
// 2D Mode: Check only the base biome
|
||||
// We use a flatMap approach here to be safe with Optionals inside the stream
|
||||
return provider.getBaseBiome(x, z, seed)
|
||||
.filter(filter)
|
||||
.map(b -> Either.right(Vector2Int.of(x, z)));
|
||||
.map(b -> right(Vector2Int.of(x, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-23
@@ -3,14 +3,15 @@ package com.dfsek.terra.addons.commands.locate;
|
||||
|
||||
import com.dfsek.seismic.type.vector.Vector2Int;
|
||||
import com.dfsek.seismic.type.vector.Vector3Int;
|
||||
|
||||
import com.dfsek.terra.api.util.generic.data.types.Maybe;
|
||||
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.component.DefaultValue;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.description.Description;
|
||||
import org.incendo.cloud.parser.standard.IntegerParser;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
@@ -21,11 +22,13 @@ import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.generic.either.Either;
|
||||
import com.dfsek.terra.api.util.generic.data.types.Either;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import static com.dfsek.terra.api.util.generic.data.types.Either.collapse;
|
||||
|
||||
|
||||
public class LocateCommandAddon implements AddonInitializer {
|
||||
@Inject
|
||||
@@ -35,7 +38,7 @@ public class LocateCommandAddon implements AddonInitializer {
|
||||
private BaseAddon addon;
|
||||
|
||||
private static Registry<Biome> getBiomeRegistry(CommandContext<CommandSender> sender) {
|
||||
return sender.sender().getEntity().orElseThrow().world().getPack().getRegistry(Biome.class);
|
||||
return sender.sender().entity().orThrow().world().getPack().getRegistry(Biome.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,7 +66,7 @@ public class LocateCommandAddon implements AddonInitializer {
|
||||
.handler(context -> {
|
||||
// 1. Gather Context & Arguments
|
||||
Biome targetBiome = context.get("biome");
|
||||
Entity sender = context.sender().getEntity().orElseThrow(
|
||||
Entity sender = context.sender().entity().orThrow(
|
||||
() -> new Error("Only entities can run this command."));
|
||||
World world = sender.world();
|
||||
|
||||
@@ -83,7 +86,7 @@ public class LocateCommandAddon implements AddonInitializer {
|
||||
context.sender().sendMessage(
|
||||
"Searching for " + targetBiome.getID() + " within " + radius + " blocks" + modeMsg + "...");
|
||||
|
||||
Optional<Either<Vector3Int, Vector2Int>> result;
|
||||
Maybe<Either<Vector3Int, Vector2Int>> result;
|
||||
|
||||
// 3. Execute Search Loop
|
||||
while(true) {
|
||||
@@ -100,7 +103,7 @@ public class LocateCommandAddon implements AddonInitializer {
|
||||
|
||||
// Exit Conditions:
|
||||
// 1. Found a result
|
||||
if(result.isPresent()) {
|
||||
if(result.isJust()) {
|
||||
break;
|
||||
}
|
||||
// 2. Not in auto mode (only run once)
|
||||
@@ -118,22 +121,11 @@ public class LocateCommandAddon implements AddonInitializer {
|
||||
}
|
||||
|
||||
// 4. Handle Result
|
||||
if(result.isPresent()) {
|
||||
Either<Vector3Int, Vector2Int> location = result.get();
|
||||
String coords;
|
||||
|
||||
if(location.hasLeft()) { // 3D Result
|
||||
Vector3Int vec = location.getLeft().get();
|
||||
coords = String.format("%d, %d, %d", vec.getX(), vec.getY(), vec.getZ());
|
||||
} else { // 2D Result
|
||||
Vector2Int vec = location.getRight().get();
|
||||
coords = String.format("%d, ~, %d", vec.getX(), vec.getZ());
|
||||
}
|
||||
|
||||
context.sender().sendMessage("Found " + targetBiome.getID() + " at [" + coords + "]");
|
||||
} else {
|
||||
context.sender().sendMessage("Could not find " + targetBiome.getID() + " within " + radius + " blocks.");
|
||||
}
|
||||
context.sender().sendMessage(collapse(result.map(location -> location.collect(
|
||||
left -> String.format("%d, %d, %d", left.getX(), left.getY(), left.getZ()),
|
||||
right -> String.format("%d, ~, %d", right.getX(), right.getZ())))
|
||||
.map(coords -> "Found " + targetBiome.getID() + " at [" + coords + "]")
|
||||
.toEither("Could not find " + targetBiome.getID() + " within " + radius + " blocks.")));
|
||||
})
|
||||
.permission("terra.locate.biome")
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ public class StructureCommandAddon implements AddonInitializer {
|
||||
private BaseAddon addon;
|
||||
|
||||
private static Registry<Structure> getStructureRegistry(CommandContext<CommandSender> sender) {
|
||||
return sender.sender().getEntity().orElseThrow().world().getPack().getRegistry(Structure.class);
|
||||
return sender.sender().entity().orThrow().world().getPack().getRegistry(Structure.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +55,7 @@ public class StructureCommandAddon implements AddonInitializer {
|
||||
.optional("rotation", EnumParser.enumParser(Rotation.class), DefaultValue.constant(Rotation.NONE))
|
||||
.handler(context -> {
|
||||
Structure structure = context.get("structure");
|
||||
Entity sender = context.sender().getEntity().orElseThrow();
|
||||
Entity sender = context.sender().entity().orThrow();
|
||||
structure.generate(
|
||||
sender.position().toInt(),
|
||||
sender.world(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.1")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.0.1")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
import com.dfsek.terra.addons.flora.flora.gen.BlockLayer;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.BlockStateSet;
|
||||
|
||||
|
||||
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
|
||||
@@ -27,7 +27,7 @@ public class FloraTemplate implements AbstractableTemplate {
|
||||
private String id;
|
||||
@Value("rotatable")
|
||||
@Default
|
||||
private @Meta MaterialSet rotatable = MaterialSet.empty();
|
||||
private @Meta BlockStateSet rotatable = BlockStateSet.empty();
|
||||
|
||||
@Value("physics")
|
||||
@Default
|
||||
@@ -63,7 +63,7 @@ public class FloraTemplate implements AbstractableTemplate {
|
||||
return ceiling;
|
||||
}
|
||||
|
||||
public MaterialSet getRotatable() {
|
||||
public BlockStateSet getRotatable() {
|
||||
return rotatable;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -20,7 +20,7 @@ import java.util.random.RandomGeneratorFactory;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Direction;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.BlockStateSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
@@ -30,14 +30,14 @@ public class TerraFlora implements Structure {
|
||||
private final boolean physics;
|
||||
private final boolean ceiling;
|
||||
|
||||
private final MaterialSet testRotation;
|
||||
private final BlockStateSet testRotation;
|
||||
|
||||
private final Sampler distribution;
|
||||
|
||||
private final String id;
|
||||
|
||||
public TerraFlora(List<BlockLayer> layers, boolean physics, boolean ceiling,
|
||||
MaterialSet testRotation,
|
||||
BlockStateSet testRotation,
|
||||
Sampler distribution, String id) {
|
||||
this.physics = physics;
|
||||
this.testRotation = testRotation;
|
||||
@@ -55,7 +55,7 @@ public class TerraFlora implements Structure {
|
||||
|
||||
private void test(EnumSet<Direction> faces, Direction f, Vector3Int b, WritableWorld world) {
|
||||
if(testRotation.contains(
|
||||
world.getBlockState(b.getX() + f.getModX(), b.getY() + f.getModY(), b.getZ() + f.getModZ()).getBlockType()))
|
||||
world.getBlockState(b.getX() + f.getModX(), b.getY() + f.getModY(), b.getZ() + f.getModZ()).blockType()))
|
||||
faces.add(f);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("1.1.1")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:addon-loader-manifest"))
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user