mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
Batch 7 stage 4a: host biome height, sky biome and platform biome writes
IrisTerrainSampler answers biomeHeight and skyBiome the way IrisFloatingHost did; IrisModuleMantle stores setPlatformBiome as the custom biome inject the biome pass reads. IrisFloatingHost is deleted. A new test pins that sky and custom biome picks ignore the random when an engine is given, which is why the api takes none.
This commit is contained in:
1 parent
c0ed5ed81e
commit
7471f9fc42
15 files changed
+215
-89
No files matched your search
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterBiomeInject;
|
||||
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
/** Iris's answers to {@code iris:floating}: a biome's terrain height by its generators, and sky biomes into the engine's mantle. */
|
||||
final class IrisFloatingHost implements FloatingHost {
|
||||
private final Engine engine;
|
||||
|
||||
IrisFloatingHost(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double biomeHeight(ResourceId biome, int worldX, int worldZ, long seed) {
|
||||
return irisBiome(biome).getHeight(engine, worldX, worldZ, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintSkyBiome(ResourceId biome, int worldX, int worldZ, int[] ys, RNG random) {
|
||||
MatterBiomeInject matter = skyBiomeMatter(irisBiome(biome), worldX, worldZ, random);
|
||||
for (int y : ys) {
|
||||
engine.getMantle().getMantle().set(worldX, y, worldZ, matter);
|
||||
}
|
||||
}
|
||||
|
||||
private MatterBiomeInject skyBiomeMatter(IrisBiome target, int worldX, int worldZ, RNG random) {
|
||||
if (target.isCustom()) {
|
||||
IrisBiomeCustom custom = target.getCustomBiome(random, engine, worldX, 0, worldZ);
|
||||
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(engine.getDimension().getLoadKey() + ":" + custom.getId()));
|
||||
}
|
||||
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(target.getSkyBiomeKey(random, engine, worldX, 0, worldZ)));
|
||||
}
|
||||
|
||||
private IrisBiome irisBiome(ResourceId biome) {
|
||||
return ((IrisPackResources) engine.getData().getPackResources()).irisBiome(biome)
|
||||
.orElseThrow(() -> new IllegalArgumentException("The pack has no biome " + biome));
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,12 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterBiomeInject;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.host.MantleRegistration;
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
@@ -116,6 +120,18 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
||||
return new MantleCaverns(bounds, chunks).isCarved(x, y, z);
|
||||
}
|
||||
|
||||
/** Stored as the biome pass reads it: the platform's id for the biome, as a custom biome inject. */
|
||||
@Override
|
||||
public void setPlatformBiome(int x, int y, int z, ResourceId biome) {
|
||||
Objects.requireNonNull(biome, "biome");
|
||||
requireNoOpenEdit();
|
||||
MatterBiomeInject inject = BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(biome.toString()));
|
||||
MantleChunk<Matter> chunk = chunkAt(x, y, z);
|
||||
synchronized (chunk) {
|
||||
chunk.getOrCreate(y >> SECTION_SHIFT).slice(MatterBiomeInject.class).set(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK, inject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
if (openEdit != null) {
|
||||
@@ -272,6 +288,11 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
||||
throw new UnsupportedOperationException("Mantle edits cannot be nested; write through this edit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlatformBiome(int x, int y, int z, ResourceId biome) {
|
||||
throw new UnsupportedOperationException("An edit buffers module layers only; set platform biomes on the mantle itself");
|
||||
}
|
||||
|
||||
/** Publishes every change, or none when a chunk it touches is missing; the edit then only closes. */
|
||||
@Override
|
||||
public void commit() {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.LegacyStreams;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
|
||||
import art.arcane.iris.builtin.structure.StructureHost;
|
||||
@@ -38,7 +37,7 @@ import java.util.function.Function;
|
||||
* state modules keep for it. {@link ModuleWorlds} makes one when the runtime is built and a new one whenever the
|
||||
* pack's resources reload under it. Iris's built-in modules reach what they need of Iris through its
|
||||
* {@linkplain #extension extensions}: the spawners' cooldowns Iris saves with the world, Iris's legacy random streams,
|
||||
* and the floating and structure hosts.
|
||||
* and the structure host.
|
||||
*/
|
||||
public final class IrisPackWorld implements PackWorld {
|
||||
private final Engine engine;
|
||||
@@ -49,7 +48,6 @@ public final class IrisPackWorld implements PackWorld {
|
||||
private volatile RunningWorld running;
|
||||
private final LegacyStreams legacyStreams;
|
||||
private final Placements placements;
|
||||
private volatile IrisFloatingHost floatingHost;
|
||||
private volatile IrisStructureHost structureHost;
|
||||
|
||||
IrisPackWorld(Engine engine) {
|
||||
@@ -133,24 +131,12 @@ public final class IrisPackWorld implements PackWorld {
|
||||
if (type == LegacyStreams.class) {
|
||||
return legacyStreams;
|
||||
}
|
||||
if (type == FloatingHost.class) {
|
||||
return floating();
|
||||
}
|
||||
if (type == StructureHost.class) {
|
||||
return structures();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private FloatingHost floating() {
|
||||
IrisFloatingHost host = floatingHost;
|
||||
if (host == null) {
|
||||
host = new IrisFloatingHost(engine);
|
||||
floatingHost = host;
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
private StructureHost structures() {
|
||||
IrisStructureHost host = structureHost;
|
||||
if (host == null) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
import com.volmit.placement.PlacementContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.BlockView;
|
||||
@@ -129,6 +130,16 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
public Optional<UpperDimension> upperDimension() {
|
||||
throw withoutEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double biomeHeight(ResourceId biome, int worldX, int worldZ, long seed) {
|
||||
throw withoutEngine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceId> skyBiome(ResourceId biome, int worldX, int worldZ) {
|
||||
throw withoutEngine();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import art.arcane.iris.engine.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.resource.ResourceId;
|
||||
@@ -44,6 +45,8 @@ import java.util.OptionalInt;
|
||||
*/
|
||||
final class IrisTerrainSampler implements TerrainSampler {
|
||||
private static final int CHUNK_WIDTH_BLOCKS = 16;
|
||||
/** Passed where Iris's biome picks take a random they ignore when given the engine. */
|
||||
private static final RNG UNUSED_RANDOM = new RNG(0L);
|
||||
|
||||
private final Engine engine;
|
||||
private final PackResourceIds ids;
|
||||
@@ -160,6 +163,31 @@ final class IrisTerrainSampler implements TerrainSampler {
|
||||
return Optional.ofNullable(engine.getComplex().getImageMapRuntime().sampleSurfaceBlock(worldX, worldZ)).map(states::toApi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double biomeHeight(ResourceId biome, int worldX, int worldZ, long seed) {
|
||||
requireInside(worldX, bounds.minY(), worldZ);
|
||||
return irisBiome(biome).getHeight(engine, worldX, worldZ, seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* The biome generator Iris picks custom and sky biomes with is seeded from the world's biome seed whenever there is an
|
||||
* engine, so these picks need no random of their own.
|
||||
*/
|
||||
@Override
|
||||
public Optional<ResourceId> skyBiome(ResourceId biome, int worldX, int worldZ) {
|
||||
requireInside(worldX, bounds.minY(), worldZ);
|
||||
IrisBiome target = irisBiome(biome);
|
||||
String key = target.isCustom()
|
||||
? engine.getDimension().getLoadKey() + ":" + target.getCustomBiome(UNUSED_RANDOM, engine, worldX, 0, worldZ).getId()
|
||||
: target.getSkyBiomeKey(UNUSED_RANDOM, engine, worldX, 0, worldZ);
|
||||
return Optional.ofNullable(key).map(ResourceId::ofPlatformKey);
|
||||
}
|
||||
|
||||
private IrisBiome irisBiome(ResourceId biome) {
|
||||
return ((IrisPackResources) engine.getData().getPackResources()).irisBiome(biome)
|
||||
.orElseThrow(() -> new IllegalArgumentException("The pack has no biome " + biome));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
return engine.getMinHeight();
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.volmit.mantle.MantleEdit;
|
||||
import com.volmit.mantle.MantleKey;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleVisitor;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
@@ -83,6 +84,11 @@ final class PlacementMantle implements Mantle, AutoCloseable {
|
||||
throw new UnsupportedOperationException("The placement owns the mantle edit; write through layer()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlatformBiome(int x, int y, int z, ResourceId biome) {
|
||||
throw new UnsupportedOperationException("A placement writes blocks and module layers; stages set platform biomes");
|
||||
}
|
||||
|
||||
/** Publishes everything the placement wrote, or nothing when a mantle chunk it touches is missing. */
|
||||
void commit() {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user