Tracked generated content ownership

- Generated furniture keeps ownership tokens for targeted removal
- Native writes invalidate pending custom content and tile records
- Regeneration and chunk updates remove invalidated content on owning threads
- Provider callbacks return ownership tokens across server platforms
- Regression fixtures cover terrain replacement and restart cleanup
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-18 17:58:30 -04:00
1 parent ed5483d75a
commit 34417b2f5b
53 files changed
+2082 -110

No files matched your search

@@ -231,7 +231,7 @@ public class ModdedNativeStructureWorldgenAccessTest {
recording.world(), generationCenter,
(x, z) -> SURFACE_FIRST_FREE_Y,
(x, z) -> FLOOR_FIRST_FREE_Y,
true,
true, true,
position -> false,
NativeBlockChangeSet.disabled());
int x = generationCenter.getMiddleBlockX();
@@ -250,7 +250,7 @@ public class ModdedNativeStructureWorldgenAccessTest {
recording.world(), generationCenter(),
(x, z) -> SURFACE_FIRST_FREE_Y,
(x, z) -> FLOOR_FIRST_FREE_Y,
false,
false, true,
position::equals,
NativeBlockChangeSet.disabled());
@@ -284,7 +284,7 @@ public class ModdedNativeStructureWorldgenAccessTest {
delegate, generationCenter(),
(x, z) -> SURFACE_FIRST_FREE_Y,
(x, z) -> FLOOR_FIRST_FREE_Y,
false,
false, true,
protectedCell::equals,
changes);
BlockPos written = protectedCell.above();
@@ -353,7 +353,7 @@ public class ModdedNativeStructureWorldgenAccessTest {
recording.world(), generationCenter(),
(x, z) -> SURFACE_FIRST_FREE_Y,
(x, z) -> FLOOR_FIRST_FREE_Y,
false,
false, true,
position -> false,
NativeBlockChangeSet.disabled());
}
@@ -1,5 +1,9 @@
package art.arcane.iris.modded.api;
import art.arcane.iris.generation.mantle.CustomBlockOwnership;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.integration.Identifier;
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeBlockPlacement;
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeEntityRuntime;
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeSpawnedEntity;
import net.minecraft.SharedConstants;
@@ -9,6 +13,7 @@ import org.junit.Test;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -20,6 +25,33 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ModdedCustomContentRegistryTest {
@Test
public void removalReturnsToOriginalProviderWithTokenAndPlacementState() {
ModdedDataProvider provider = mock(ModdedDataProvider.class);
Engine engine = mock(Engine.class);
NativeBlockPlacement placement = mock(NativeBlockPlacement.class);
ModdedBlockPlacementContext context = new ModdedBlockPlacementContext(
engine, placement, "provider_test:furniture/chair", Map.of("variant", "oak"));
when(provider.modId()).thenReturn("ownership_test");
when(provider.isReady()).thenReturn(true);
when(provider.isValidProvider("provider_test:furniture/chair", ModdedDataType.BLOCK)).thenReturn(true);
when(provider.processBlockPlacement(context)).thenReturn("entity-token");
when(provider.removeGenerated(context, "entity-token")).thenReturn(true);
ModdedCustomContentRegistry.Discovery discovery = ModdedCustomContentRegistry.discover(List.of(provider));
try {
CustomBlockOwnership.Entry ownership = ModdedCustomContentRegistry.processBlockPlacement(engine,
"provider_test:furniture/chair[variant=oak]", () -> placement);
assertEquals(new CustomBlockOwnership.Entry(
Identifier.fromString("ownership_test:provider_test/furniture/chair[variant=oak]"),
"entity-token", false), ownership);
assertTrue(ModdedCustomContentRegistry.removeGenerated(engine, ownership, () -> placement));
verify(provider).removeGenerated(context, "entity-token");
} finally {
discovery.rollback();
}
}
@BeforeClass
public static void bootstrapRegistries() {
SharedConstants.tryDetectVersion();
@@ -53,6 +53,8 @@ public class ModdedChunkUpdateServiceCarrierTest {
private static final String MOD_ID = "iris_carrier_guard_test";
private static final String LAMP = MOD_ID + ":lamp";
private static final String CHAIR = MOD_ID + ":chair";
private static final String FIRE = MOD_ID + ":fire";
private static final String SOUL_FIRE = MOD_ID + ":soul_fire";
private static final List<BlockPos> PLACED = new CopyOnWriteArrayList<>();
@BeforeClass
@@ -80,6 +82,7 @@ public class ModdedChunkUpdateServiceCarrierTest {
3, Blocks.COBBLESTONE.defaultBlockState(),
4, Blocks.COBBLESTONE.defaultBlockState()));
List<String> debug = new ArrayList<>();
Engine engine = engine(chunk);
try (MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
logging.when(() -> IrisLogging.debug(anyString(), any(Object[].class))).thenAnswer((InvocationOnMock invocation) -> {
@@ -88,7 +91,7 @@ public class ModdedChunkUpdateServiceCarrierTest {
return null;
});
new ModdedChunkUpdateService().updateRegeneratedChunk(engine(chunk), level, 0, 0);
new ModdedChunkUpdateService().updateRegeneratedChunk(engine, level, engine.getMantle().getMantle(), 0, 0);
}
assertEquals(List.of(new BlockPos(1, 6, 1), new BlockPos(4, 6, 4)), PLACED);
@@ -98,6 +101,24 @@ public class ModdedChunkUpdateServiceCarrierTest {
assertTrue(debug.getFirst(), debug.getFirst().contains("2 stale"));
}
@Test
public void extinguishedFireCarriersArePlacedWhileCoveredCarriersAreSkipped() {
RecordMantleChunk chunk = new RecordMantleChunk(List.of(
new Placed(1, FIRE), new Placed(2, SOUL_FIRE),
new Placed(3, FIRE), new Placed(4, SOUL_FIRE)));
NativeWorld level = level(Map.of(
1, Blocks.AIR.defaultBlockState(),
2, Blocks.CAVE_AIR.defaultBlockState(),
3, Blocks.COBBLESTONE.defaultBlockState(),
4, Blocks.COBBLESTONE.defaultBlockState()));
Engine engine = engine(chunk);
new ModdedChunkUpdateService().updateRegeneratedChunk(engine, level, engine.getMantle().getMantle(), 0, 0);
assertEquals(List.of(new BlockPos(1, 6, 1), new BlockPos(2, 6, 2)), PLACED);
assertTrue(chunk.customDeleted());
}
private static NativeWorld level(Map<Integer, BlockState> live) {
ServerLevel serverLevel = mock(ServerLevel.class);
when(serverLevel.getBlockState(any(BlockPos.class))).thenReturn(Blocks.STONE.defaultBlockState());
@@ -163,6 +184,18 @@ public class ModdedChunkUpdateServiceCarrierTest {
}
}
@Override
public <T> T get(int x, int y, int z, Class<T> type) {
if (type == Identifier.class && y == 70 && x == z) {
for (Placed record : records) {
if (record.offset() == x) {
return type.cast(Identifier.fromString(record.key()));
}
}
}
return null;
}
@Override
public void deleteSlices(Class<?> type) {
if (type == Identifier.class) {
@@ -183,23 +216,29 @@ public class ModdedChunkUpdateServiceCarrierTest {
@Override
public Collection<String> getTypes(ModdedDataType type) {
return type == ModdedDataType.BLOCK ? List.of(LAMP, CHAIR) : List.of();
return type == ModdedDataType.BLOCK ? List.of(LAMP, CHAIR, FIRE, SOUL_FIRE) : List.of();
}
@Override
public boolean isValidProvider(String id, ModdedDataType type) {
return type == ModdedDataType.BLOCK && (LAMP.equals(id) || CHAIR.equals(id));
return type == ModdedDataType.BLOCK && getTypes(type).contains(id);
}
@Override
public ModdedBlockData getBlockData(String blockId, Map<String, String> state) {
BlockState carrier = CHAIR.equals(blockId) ? Blocks.AIR.defaultBlockState() : Blocks.NOTE_BLOCK.defaultBlockState();
BlockState carrier = switch (blockId) {
case CHAIR -> Blocks.AIR.defaultBlockState();
case FIRE -> Blocks.FIRE.defaultBlockState();
case SOUL_FIRE -> Blocks.SOUL_FIRE.defaultBlockState();
default -> Blocks.NOTE_BLOCK.defaultBlockState();
};
return ModdedBlockData.deferred(ModdedBlockState.of(carrier, null));
}
@Override
public void processBlockPlacement(ModdedBlockPlacementContext context) {
public String processBlockPlacement(ModdedBlockPlacementContext context) {
PLACED.add(context.placement().position());
return null;
}
}
}
@@ -68,6 +68,29 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ModdedChunkUpdateServiceTest {
@Test
@SuppressWarnings("unchecked")
public void regeneratedCleanupUsesSuppliedMantleAfterCurrentRuntimeChanges() {
Mantle<Matter> selected = mock(Mantle.class);
Mantle<Matter> replacement = mock(Mantle.class);
MantleDataAdapter<Matter> adapter = mock(MantleDataAdapter.class);
MantleChunk<Matter> chunk = new MantleChunk<>(1, 0, 0, adapter, MantleHooks.NONE);
when(selected.isChunkLoaded(0, 0)).thenReturn(true);
when(selected.useChunk(0, 0)).thenAnswer(invocation -> chunk.use());
when(selected.hasFlag(0, 0, MantleFlag.ETCHED)).thenReturn(true);
NativeWorld level = mock(NativeWorld.class);
when(level.isChunkLoaded(0, 0)).thenReturn(true);
Engine engine = engineWith(replacement);
when(engine.getWorld().platformWorld()).thenReturn(level);
new ModdedChunkUpdateService().updateRegeneratedChunk(engine, level, selected, 0, 0);
verify(selected).useChunk(0, 0);
verify(replacement, never()).isChunkLoaded(anyInt(), anyInt());
verify(replacement, never()).useChunk(anyInt(), anyInt());
assertFalse(chunk.inUse());
}
@Test
public void fallingFluidUpdateRetainsLevelEightStateAndRequestsPhysics() {
SharedConstants.tryDetectVersion();
@@ -154,7 +177,7 @@ public class ModdedChunkUpdateServiceTest {
return null;
});
service.updateRegeneratedChunk(engine, level, 0, 0);
service.updateRegeneratedChunk(engine, level, engine.getMantle().getMantle(), 0, 0);
assertFalse(chunk.isFlagged(MantleFlag.ETCHED));
assertFalse(chunk.isFlagged(MantleFlag.UPDATE));
@@ -162,7 +185,7 @@ public class ModdedChunkUpdateServiceTest {
logging.verify(() -> IrisLogging.reportError(any(Throwable.class)), never());
logging.verify(() -> IrisLogging.reportError(anyString(), any(Throwable.class)), never());
service.updateRegeneratedChunk(engine, level, 0, 0);
service.updateRegeneratedChunk(engine, level, engine.getMantle().getMantle(), 0, 0);
assertTrue(chunk.isFlagged(MantleFlag.ETCHED));
assertTrue(chunk.deleted());
@@ -187,7 +210,7 @@ public class ModdedChunkUpdateServiceTest {
});
assertThrows(SavedBiomeUnavailableException.class,
() -> new ModdedChunkUpdateService().updateRegeneratedChunk(engine, level, 0, 0));
() -> new ModdedChunkUpdateService().updateRegeneratedChunk(engine, level, engine.getMantle().getMantle(), 0, 0));
assertFalse(chunk.isFlagged(MantleFlag.ETCHED));
assertFalse(chunk.isFlagged(MantleFlag.UPDATE));
@@ -215,13 +238,13 @@ public class ModdedChunkUpdateServiceTest {
});
assertSame(failure, assertThrows(IllegalStateException.class,
() -> service.updateRegeneratedChunk(engine, level, 0, 0)));
() -> service.updateRegeneratedChunk(engine, level, engine.getMantle().getMantle(), 0, 0)));
assertFalse(chunk.isFlagged(MantleFlag.UPDATE));
assertFalse(chunk.isFlagged(MantleFlag.ETCHED));
assertFalse(chunk.deleted());
verify(chunk.slice, never()).set(2, 5, 2, null);
service.updateRegeneratedChunk(engine, level, 0, 0);
service.updateRegeneratedChunk(engine, level, engine.getMantle().getMantle(), 0, 0);
assertTrue(chunk.isFlagged(MantleFlag.ETCHED));
assertTrue(chunk.deleted());