mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Port custom block recording into the iris:custom module and delete the custom modifier
This commit is contained in:
1 parent
3a224c6b03
commit
edb47e6973
2 files changed
+69
-69
No files matched your search
@@ -20,19 +20,30 @@ package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.custom.CustomStages;
|
||||
import art.arcane.iris.builtin.perfection.PerfectionStages;
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.core.modules.IrisChunk;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.stage.ChunkStageContext;
|
||||
import com.volmit.stage.StageGraph;
|
||||
|
||||
/**
|
||||
* Module {@code iris:custom}: records the chunk's content-plugin blocks for the server to place later. A thin
|
||||
* wrapper: the stage runs {@link IrisCustomModifier} unchanged, one per engine runtime, except while
|
||||
* maintenance regeneration bypasses the mantle.
|
||||
* Module {@code iris:custom}: records the chunk's content-plugin blocks for the server to place later: each
|
||||
* custom block's placement key goes into the mantle and the block itself is replaced by its base state. Skipped
|
||||
* while maintenance regeneration bypasses the mantle.
|
||||
*/
|
||||
public final class CustomModule implements IrisModule {
|
||||
private static final String VERSION = "built-in";
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int SECTION_MASK = 15;
|
||||
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
@@ -49,7 +60,60 @@ public final class CustomModule implements IrisModule {
|
||||
if (chunk.bypassesMantleStages()) {
|
||||
return;
|
||||
}
|
||||
chunk.state(IrisCustomModifier.class, IrisCustomModifier::new)
|
||||
.modify(chunk.originX(), chunk.originZ(), chunk.blocks(), chunk.multicore(), chunk.context());
|
||||
chunk.state(CustomBlockRecording.class, CustomBlockRecording::new).record(chunk.originX(), chunk.originZ(), chunk.blocks(), chunk.multicore());
|
||||
}
|
||||
|
||||
/** Moves the custom blocks of a chunk into the mantle for one engine runtime. */
|
||||
static final class CustomBlockRecording {
|
||||
private final Engine engine;
|
||||
|
||||
CustomBlockRecording(Engine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/** Records the custom blocks of the chunk whose first block is {@code x}, {@code z}, when its mantle chunk is flagged as having some. */
|
||||
void record(int x, int z, Hunk<PlatformBlockState> output, boolean multicore) {
|
||||
MantleChunk<Matter> mc = engine.getMantle().getMantle().getChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT);
|
||||
if (!mc.isFlagged(MantleFlag.CUSTOM_ACTIVE)) {
|
||||
return;
|
||||
}
|
||||
mc.use();
|
||||
|
||||
BurstExecutor burst = MultiBurst.burst.burst(output.getHeight());
|
||||
burst.setMulticore(multicore);
|
||||
// complete() must run before release() even when queueing throws — detached burst
|
||||
// tasks must never write into a released chunk, and a lost permit wedges close().
|
||||
try {
|
||||
for (int y = 0; y < output.getHeight(); y++) {
|
||||
int finalY = y;
|
||||
burst.queue(() -> {
|
||||
for (int rX = 0; rX < output.getWidth(); rX++) {
|
||||
for (int rZ = 0; rZ < output.getDepth(); rZ++) {
|
||||
PlatformBlockState b = output.get(rX, finalY, rZ);
|
||||
if (b == null || !b.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
String placementKey = b.deferredPlacementKey();
|
||||
PlatformBlockState baseState = b.placementBaseState();
|
||||
if (placementKey == null || baseState == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mc.getOrCreate(finalY >> CHUNK_SHIFT)
|
||||
.slice(Identifier.class)
|
||||
.set(rX, finalY & SECTION_MASK, rZ, Identifier.fromString(placementKey));
|
||||
output.set(rX, finalY, rZ, baseState);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
burst.complete();
|
||||
} finally {
|
||||
mc.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineAssignedModifier;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.parallel.BurstExecutor;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
public class IrisCustomModifier extends EngineAssignedModifier<PlatformBlockState> {
|
||||
public IrisCustomModifier(Engine engine) {
|
||||
super(engine, "Custom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModify(int x, int z, Hunk<PlatformBlockState> output, boolean multicore, ChunkContext context) {
|
||||
MantleChunk<Matter> mc = getEngine().getMantle().getMantle().getChunk(x >> 4, z >> 4);
|
||||
if (!mc.isFlagged(MantleFlag.CUSTOM_ACTIVE)) {
|
||||
return;
|
||||
}
|
||||
mc.use();
|
||||
|
||||
BurstExecutor burst = MultiBurst.burst.burst(output.getHeight());
|
||||
burst.setMulticore(multicore);
|
||||
// complete() must run before release() even when queueing throws — detached burst
|
||||
// tasks must never write into a released chunk, and a lost permit wedges close().
|
||||
try {
|
||||
for (int y = 0; y < output.getHeight(); y++) {
|
||||
int finalY = y;
|
||||
burst.queue(() -> {
|
||||
for (int rX = 0; rX < output.getWidth(); rX++) {
|
||||
for (int rZ = 0; rZ < output.getDepth(); rZ++) {
|
||||
PlatformBlockState b = output.get(rX, finalY, rZ);
|
||||
if (b == null || !b.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
String placementKey = b.deferredPlacementKey();
|
||||
PlatformBlockState baseState = b.placementBaseState();
|
||||
if (placementKey == null || baseState == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mc.getOrCreate(finalY >> 4)
|
||||
.slice(Identifier.class)
|
||||
.set(rX, finalY & 15, rZ, Identifier.fromString(placementKey));
|
||||
output.set(rX, finalY, rZ, baseState);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
burst.complete();
|
||||
} finally {
|
||||
mc.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user