mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
ObjectsAt.placedBy: the biomes and regions whose settings place an object
This commit is contained in:
1 parent
46676fd99b
commit
ba96e0cbc2
4 files changed
+48
-8
No files matched your search
@@ -913,7 +913,8 @@ from a sapling, which drops a block has. A module answers such questions through
|
||||
- **Threading.** The host may call a provider from any thread, several at once. A provider that searches long
|
||||
(`StructureLocator.locate`) is called off the server's main thread.
|
||||
- **Services now.** `ObjectsAt` (`ALL`): pack object keys a module would place in a chunk, predicted without
|
||||
generating it. `StructureLocator` (`FIRST`): every structure key a module knows, the ones a world places, and the
|
||||
generating it, and the biomes and regions whose settings place a given object (`PlacedBy`, named by pack keys; the
|
||||
host builds its search area from them through the biome tree it owns). `StructureLocator` (`FIRST`): every structure key a module knows, the ones a world places, and the
|
||||
nearest start of one as a `LocateResult` (`Found`, `NotFound`, `SearchLimitReached`; a sealed interface, so callers
|
||||
switch over every outcome). Keys are pack keys as packs write them and match without regard to case.
|
||||
- **Why not per-world provider instances.** A factory per world (`world -> provider`) would let a provider hold its
|
||||
|
||||
@@ -264,11 +264,17 @@ them up in the pack's catalog instead of knowing the feature.
|
||||
|
||||
```java
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerService(ObjectsAt.class, RuinsModule::objectsAt);
|
||||
registry.registerService(ObjectsAt.class, new RuinsObjects());
|
||||
}
|
||||
|
||||
private static Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
return planted(world).contains(chunkX, chunkZ) ? Set.of("ruins/arch") : Set.of();
|
||||
final class RuinsObjects implements ObjectsAt {
|
||||
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
return planted(world).contains(chunkX, chunkZ) ? Set.of("ruins/arch") : Set.of();
|
||||
}
|
||||
|
||||
public PlacedBy placedBy(PackWorld world, String objectKey) {
|
||||
return PlacedBy.NOTHING;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -283,7 +289,7 @@ private static Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
|
||||
| Service | Providers | What the host asks |
|
||||
| --- | --- | --- |
|
||||
| `ObjectsAt` | `ALL` | The pack objects a module would place in a chunk, predicted without generating it (object search, studio tools). |
|
||||
| `ObjectsAt` | `ALL` | The pack objects a module would place in a chunk, predicted without generating it, and the biomes and regions of the layout that place a given object (`PlacedBy`), so the host can narrow an object search to the areas it can appear in. |
|
||||
| `StructureLocator` | `FIRST` | Every structure key the module knows (the structure index), the ones a world places (commands complete them), and the nearest start of one, as a `LocateResult`: `Found(position)`, `NotFound` or `SearchLimitReached`. Keys match without regard to case. |
|
||||
|
||||
```
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.volmit.service;
|
||||
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/** Which pack objects a module places in a chunk, predicted without generating it. The host's object search and its
|
||||
* studio tools ask every provider and use all the keys together.
|
||||
/** Which pack objects a module places, predicted without generating anything. The host's object search and its
|
||||
* studio tools ask every provider and use all the answers together.
|
||||
*/
|
||||
@Service(Providers.ALL)
|
||||
public interface ObjectsAt {
|
||||
@@ -15,4 +16,26 @@ public interface ObjectsAt {
|
||||
* there.
|
||||
*/
|
||||
Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* The biomes and regions of {@code world}'s layout whose own settings make this module place the object
|
||||
* {@code objectKey}. The host finds the areas where the object can appear from these: a biome counts for the areas
|
||||
* it generates in and, through its children, for the areas of the biomes inside it, so a provider names only the
|
||||
* layout entries that place the object themselves. Only biomes and regions the dimension can reach are named.
|
||||
*/
|
||||
PlacedBy placedBy(PackWorld world, String objectKey);
|
||||
|
||||
/** Layout entries that place an object, named by the keys packs write ({@code land/plains}, {@code temperate}). */
|
||||
record PlacedBy(Set<String> biomes, Set<String> regions) {
|
||||
public static final PlacedBy NOTHING = new PlacedBy(Set.of(), Set.of());
|
||||
|
||||
public PlacedBy {
|
||||
biomes = Set.copyOf(Objects.requireNonNull(biomes, "biomes"));
|
||||
regions = Set.copyOf(Objects.requireNonNull(regions, "regions"));
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return biomes.isEmpty() && regions.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,17 @@ class WorldStateExampleTest {
|
||||
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerLifecycle(this);
|
||||
registry.registerService(ObjectsAt.class, RuinsModule::objectsAt);
|
||||
registry.registerService(ObjectsAt.class, new ObjectsAt() {
|
||||
@Override
|
||||
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||
return RuinsModule.objectsAt(world, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacedBy placedBy(PackWorld world, String objectKey) {
|
||||
return PlacedBy.NOTHING;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user