mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Run built-in chunk modules on Iris's own block hunk
- IrisChunk gives Iris's built-in chunk stages the engine, Iris's block hunk and the chunk context, bound on the generating thread while the pack's chunk graph runs. - iris:perfection joins the built-in modules every pack loads. - PerfectionModuleTest runs it through the chunk graph.
This commit is contained in:
1 parent
2aab5ae9a3
commit
f052960e2f
5 files changed
+231
-5
No files matched your search
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Iris's own view of the chunk whose module stages are running: the engine, Iris's block hunk and the
|
||||
* chunk's sampled context. Iris's built-in chunk stages read them through {@link #current()}, bound on the
|
||||
* generating thread while the chunk graph runs, and work on Iris's block states directly; pack modules
|
||||
* cannot see this class.
|
||||
*/
|
||||
public final class IrisChunk {
|
||||
private static final ScopedValue<IrisChunk> CURRENT = ScopedValue.newInstance();
|
||||
|
||||
private final Engine engine;
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final Hunk<PlatformBlockState> blocks;
|
||||
private final ChunkContext context;
|
||||
|
||||
IrisChunk(Engine engine, int originX, int originZ, Hunk<PlatformBlockState> blocks, ChunkContext context) {
|
||||
this.engine = engine;
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.blocks = blocks;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/** The chunk generating on this thread. */
|
||||
public static IrisChunk current() {
|
||||
if (!CURRENT.isBound()) {
|
||||
throw new IllegalStateException("No Iris chunk is generating on this thread");
|
||||
}
|
||||
return CURRENT.get();
|
||||
}
|
||||
|
||||
void runBound(Runnable generation) {
|
||||
ScopedValue.where(CURRENT, this).run(generation);
|
||||
}
|
||||
|
||||
public Engine engine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
/** The chunk's first block along X. */
|
||||
public int originX() {
|
||||
return originX;
|
||||
}
|
||||
|
||||
/** The chunk's first block along Z. */
|
||||
public int originZ() {
|
||||
return originZ;
|
||||
}
|
||||
|
||||
/** The chunk's blocks, indexed from its first block; Iris leaves unset blocks null. */
|
||||
public Hunk<PlatformBlockState> blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** What the engine sampled for this chunk, such as its biomes and heights. */
|
||||
public ChunkContext context() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.modifier.PerfectionModule;
|
||||
import art.arcane.iris.engine.object.placement.PlacementModules;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -26,6 +27,7 @@ import com.volmit.host.PackModules;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The one {@link ModuleHost} every pack load uses: Iris's built-in modules, the built-in module API
|
||||
@@ -48,7 +50,7 @@ public final class IrisModuleHost {
|
||||
|
||||
/** The modules every pack loads before its own: Iris's built-in features. */
|
||||
public static List<IrisModule> builtInModules() {
|
||||
return PlacementModules.all();
|
||||
return Stream.concat(PlacementModules.all().stream(), Stream.of(new PerfectionModule())).toList();
|
||||
}
|
||||
|
||||
private static ModuleHost build() {
|
||||
|
||||
@@ -49,11 +49,11 @@ public final class ModuleChunkGeneration {
|
||||
|
||||
/** {@code x} and {@code z} are the chunk's first block, as engine stages receive them. */
|
||||
public static void generate(Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, ChunkContext context) {
|
||||
generate(engine.getData().getModules().pack(), engine, x, z, blocks,
|
||||
generate(engine.getData().getModules().pack(), engine, x, z, blocks, context,
|
||||
context.getRegion().get(CHUNK_CENTER, CHUNK_CENTER), context.getBiome().get(CHUNK_CENTER, CHUNK_CENTER), B::getState);
|
||||
}
|
||||
|
||||
static void generate(LoadedPack pack, Engine engine, int x, int z, Hunk<PlatformBlockState> blocks,
|
||||
static void generate(LoadedPack pack, Engine engine, int x, int z, Hunk<PlatformBlockState> blocks, ChunkContext context,
|
||||
IrisRegion centerRegion, IrisBiome centerBiome, Function<String, PlatformBlockState> platformStates) {
|
||||
ResolvedGraph chunk = pack.chunk();
|
||||
if (chunk.stages().isEmpty()) {
|
||||
@@ -63,6 +63,6 @@ public final class ModuleChunkGeneration {
|
||||
IrisGenerationContext inputs = new IrisGenerationContext(engine, x, z,
|
||||
new BlockStateHunk(blocks, platformStates), chunk.reach().blocks());
|
||||
long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), x >> CHUNK_SHIFT, z >> CHUNK_SHIFT);
|
||||
new ChunkRunner(chunk).generate(inputs, seed, settings);
|
||||
new IrisChunk(engine, x, z, blocks, context).runBound(() -> new ChunkRunner(chunk).generate(inputs, seed, settings));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user