mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Batch 2 of the API review: settings stacks, chunk helpers, pack context
- SettingsStack<F> replaces List<Entry<F>> wherever settings stack: entries in level order, values(), dimension(), level(Level) and mostSpecific(). - com.volmit.config.Level replaces FeatureAttachment.Target; FeatureAttachment folds into FeatureDescriptor.targets(). - FeatureSettings.declaredInChunk answers every entry any column of a chunk declares, each once. - ChunkContext gives chunkX/chunkZ, centreX/centreZ and area(). - registerSettings takes several types at once. - ModuleLifecycle.packLoaded(PackContext) carries resources, settings and the module's log. - TerrainSampler.surfaceHeight gives the surface in whole blocks. - Stage contexts drop worldSeed() and resources(); world() always answers. The scoped world is kept per world and module. - Javadoc fixes; README, DESIGN and CONTRACTS updated.
This commit is contained in:
1 parent
1677f4414b
commit
7143908d4b
67 files changed
+870
-423
No files matched your search
@@ -1,9 +1,10 @@
|
||||
package com.volmit.config;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.generation.ChunkContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -12,16 +13,39 @@ import java.util.Optional;
|
||||
* <p>Every level that declares the settings contributes its own entry: the dimension, the region and
|
||||
* the biome of the column, and in a placement the placement itself. Levels stack: nothing is merged or
|
||||
* overridden, and a module decides what several entries mean, such as running a deposit once per
|
||||
* entry. Entries are immutable lists in level order ({@link FeatureAttachment.Target} order). The
|
||||
* biome is the column's surface biome; cave biomes are not a level. Values must be treated as
|
||||
* entry. The biome is the column's surface biome; cave biomes are not a level. Values must be treated as
|
||||
* read-only. Bounds and lifetime match the invocation's sampler.
|
||||
*
|
||||
* <p>Something that spans several columns, such as a chunk-wide pass or a placed object, reads the
|
||||
* settings at one column it treats as its origin; per-chunk behaviour reads the chunk's centre column
|
||||
* (local 7, 7).
|
||||
* ({@link ChunkContext#centreX()}, {@link ChunkContext#centreZ()}).
|
||||
*/
|
||||
public interface FeatureSettings {
|
||||
<F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ);
|
||||
/** The entries of {@code featureType} at this column, in level order; empty when no level declares it. */
|
||||
<F extends IrisFeature> SettingsStack<F> at(Class<F> featureType, int worldX, int worldZ);
|
||||
|
||||
/** Every distinct entry of {@code featureType} at the 16 by 16 columns of chunk {@code chunkX}, {@code chunkZ}, in
|
||||
* level order; entries of one level in the order their first column was found, columns by X and then Z. Entries are
|
||||
* distinct by level and source. The chunk and mantle runners decide with it whether a conditioned stage runs in a
|
||||
* chunk. The default asks {@link #at} for every column; a host that knows which regions and biomes a chunk holds
|
||||
* answers it from them.
|
||||
*/
|
||||
default <F extends IrisFeature> SettingsStack<F> declaredInChunk(Class<F> featureType, int chunkX, int chunkZ) {
|
||||
var declarations = new HashSet<Declaration>();
|
||||
var distinct = new ArrayList<Entry<F>>();
|
||||
int originX = chunkX * ChunkContext.CHUNK_WIDTH;
|
||||
int originZ = chunkZ * ChunkContext.CHUNK_WIDTH;
|
||||
for (int x = 0; x < ChunkContext.CHUNK_WIDTH; x++) {
|
||||
for (int z = 0; z < ChunkContext.CHUNK_WIDTH; z++) {
|
||||
for (var entry : at(featureType, originX + x, originZ + z)) {
|
||||
if (declarations.add(new Declaration(entry.level(), entry.source()))) {
|
||||
distinct.add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return SettingsStack.of(distinct);
|
||||
}
|
||||
|
||||
/** The settings {@code biome} declares itself, whichever column it is found at: for a biome that is not a column's
|
||||
* surface biome, such as the cave biome of {@link com.volmit.world.BiomeSample#caveBiome()}, which is no level of
|
||||
@@ -38,7 +62,7 @@ public interface FeatureSettings {
|
||||
* @param source the resource that declares them, such as {@code overworld:biome/desert/dunes}
|
||||
* @param value the decoded settings
|
||||
*/
|
||||
record Entry<F extends IrisFeature>(FeatureAttachment.Target level, ResourceId source, F value) {
|
||||
record Entry<F extends IrisFeature>(Level level, ResourceId source, F value) {
|
||||
public Entry {
|
||||
Objects.requireNonNull(level, "level");
|
||||
Objects.requireNonNull(source, "source");
|
||||
@@ -46,3 +70,6 @@ public interface FeatureSettings {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** What makes two entries of a chunk the same declaration. */
|
||||
record Declaration(Level level, ResourceId source) {}
|
||||
Reference in new issue
Block a user