mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Surface for ported built-ins: VINE trait, canPlaceOn, the sampler's fluid height and upper dimension, the mantle's planned blocks, a chunk sampler that covers the neighbors, stage timings from the chunk runner
This commit is contained in:
1 parent
f8d85dcd5e
commit
6c0c072afe
11 files changed
+139
-5
No files matched your search
@@ -38,4 +38,9 @@ public interface BlockRegistry {
|
||||
boolean inTag(BlockState state, ResourceId tag);
|
||||
/** Whether state can attach to the specified face of support, ignoring other neighbors. */
|
||||
boolean canAttach(BlockState state, BlockState support, BlockFace face);
|
||||
|
||||
/** Whether {@code state} can stand on {@code below}: the support rule the host checks before it writes a
|
||||
* decoration, such as a flower on grass but not on stone. Only the kinds of block count, not their properties.
|
||||
*/
|
||||
boolean canPlaceOn(BlockState state, BlockState below);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.volmit.block;
|
||||
|
||||
/** Host-defined block behavior; tags provide extensible material groups. */
|
||||
/** Host-defined block behavior; tags provide extensible material groups. {@code VINE} is a block that hangs from or
|
||||
* clings to the faces around it, such as vines and glow lichen.
|
||||
*/
|
||||
public enum BlockTrait {
|
||||
AIR, SOLID, OCCLUDING, FLUID, WATER, GRAVITY, FOLIAGE, DECORATION,
|
||||
AIR, SOLID, OCCLUDING, FLUID, WATER, GRAVITY, FOLIAGE, DECORATION, VINE,
|
||||
LOG, LEAVES, ORE, INVENTORY, BLOCK_ENTITY, CUSTOM, NEEDS_UPDATE
|
||||
}
|
||||
@@ -13,6 +13,9 @@ public interface GenerationContext extends InvocationContext {
|
||||
int originX();
|
||||
int originZ();
|
||||
|
||||
/** The terrain of the chunk and of the 16 blocks around it on every side, at full height: a chunk stage writes only
|
||||
* its own chunk, but may look at its neighbors' terrain, such as their heights.
|
||||
*/
|
||||
TerrainSampler terrain();
|
||||
FeatureSettings settings();
|
||||
|
||||
|
||||
@@ -24,13 +24,30 @@ public final class ChunkRunner {
|
||||
* stage draws from its own stream of that seed ({@link StageStreams}).
|
||||
*/
|
||||
public void generate(GenerationContext inputs, long invocationSeed) {
|
||||
generate(inputs, invocationSeed, StageTimings.NONE);
|
||||
}
|
||||
|
||||
/** Runs one chunk like {@link #generate(GenerationContext, long)} and reports to {@code timings} how long each
|
||||
* stage that ran took.
|
||||
*/
|
||||
public void generate(GenerationContext inputs, long invocationSeed, StageTimings timings) {
|
||||
Objects.requireNonNull(timings, "timings");
|
||||
if (graph.size() == 0) {
|
||||
return;
|
||||
}
|
||||
var settings = ChunkSettings.collect(graph.settingsTypes(), inputs::settings, inputs.originX(), inputs.originZ());
|
||||
var chunk = new ChunkInvocation(new StageInvocation(graph, invocationSeed, settings), inputs);
|
||||
for (int position = 0; position < graph.size(); position++) {
|
||||
chunk.stages().runInvocationStage(position, chunk);
|
||||
runTimed(chunk, position, timings);
|
||||
}
|
||||
}
|
||||
|
||||
private void runTimed(ChunkInvocation chunk, int position, StageTimings timings) {
|
||||
if (!chunk.stages().isActive(position)) {
|
||||
return;
|
||||
}
|
||||
long started = System.nanoTime();
|
||||
chunk.stages().runInvocationStage(position, chunk);
|
||||
timings.record(graph.stages().get(position), System.nanoTime() - started);
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,12 @@ final class PlacementViews {
|
||||
bounds();
|
||||
return new RestrictedMantleLayer<>(this, parent.layer(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<BlockState> blocks() {
|
||||
bounds();
|
||||
return new RestrictedMantleLayer<>(this, parent.blocks());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RestrictedMantleLayer<T> implements MantleLayer<T> {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.mantle.MantleEdit;
|
||||
@@ -30,6 +31,11 @@ final class ReadOnlyMantle implements Mantle {
|
||||
return new ReadOnlyLayer<>(mantle.layer(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<BlockState> blocks() {
|
||||
return new ReadOnlyLayer<>(mantle.blocks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.volmit.host;
|
||||
|
||||
/** Where a runner reports how long each stage it ran took, such as the host's generation metrics. Called on the
|
||||
* invocation's thread, once per stage that ran, in run order; a stage the invocation left inactive is not reported.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface StageTimings {
|
||||
/** Reports nothing. */
|
||||
StageTimings NONE = (stage, nanos) -> {
|
||||
};
|
||||
|
||||
void record(ResolvedStage stage, long nanos);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.volmit.mantle;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
/**
|
||||
* Invocation-scoped access to typed mantle data. X and Z are world block coordinates; Y is
|
||||
* the height above the dimension's bottom (0 = bottom), so it is never negative. The host translates
|
||||
@@ -22,6 +24,14 @@ public interface Mantle {
|
||||
|
||||
<T> MantleLayer<T> layer(MantleKey<T> key);
|
||||
|
||||
/** The blocks the mantle holds for chunks to take over: what placements wrote, such as objects and structures.
|
||||
* A chunk stage copies them into its chunk (Iris's {@code iris:matter}); absent positions read null, and air a
|
||||
* placement wrote is a block like any other. The host owns this layer, so it needs no registration. Stages read
|
||||
* it only, and writes throw UnsupportedOperationException: placements write blocks with
|
||||
* {@link com.volmit.placement.PlacementAccess#set}. A dimension that keeps no mantle holds none.
|
||||
*/
|
||||
MantleLayer<BlockState> blocks();
|
||||
|
||||
/** Only one edit may be active per view. Parent reads remain allowed, but parent
|
||||
* mutations are prohibited until the edit ends (IllegalStateException).
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.volmit.world;
|
||||
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/** Read-only host sampling for the same pack snapshot as the invocation.
|
||||
* X and Z are world coordinates; Y is the height above the dimension's bottom (0 = bottom).
|
||||
@@ -11,4 +12,15 @@ public interface TerrainSampler {
|
||||
BlockBox bounds();
|
||||
TerrainSample column(int worldX, int worldZ);
|
||||
BiomeSample biome(int worldX, int y, int worldZ);
|
||||
|
||||
/** The height up to which the host fills the world with fluid wherever the terrain lies lower, the sea level of the
|
||||
* dimension: a column's {@link TerrainSample#fluidY()} is this height when its surface is below it.
|
||||
*/
|
||||
int fluidHeight();
|
||||
|
||||
/** Where another dimension stacked above this one begins in the column, when one does: generation of this
|
||||
* dimension leaves that height and everything above it to the dimension above, so a module writes nothing there.
|
||||
* Empty when nothing sits above. Outside the bounds it throws like {@link #column}.
|
||||
*/
|
||||
OptionalInt upperDimensionY(int worldX, int worldZ);
|
||||
}
|
||||
Reference in new issue
Block a user