mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
d
This commit is contained in:
1 parent
ef2e1b8f58
commit
fc0fdf4ce4
81 files changed
+5109
-511
No files matched your search
+33
@@ -102,7 +102,12 @@ public class ModdedGenerationLeaseContractTest {
|
||||
String execution = method(source, "private static void executeDownload(");
|
||||
assertTrue(execution.contains("PackDownloader.DownloadCancellation cancellation"));
|
||||
assertTrue(execution.contains("catch (PackDownloader.PackDownloadCancelledException error)"));
|
||||
assertTrue(execution.contains("dispatchDownloadFeedback(source,"));
|
||||
assertFalse(execution.contains("scheduler.global("));
|
||||
assertFalse(execution.contains("lease.close();"));
|
||||
|
||||
String feedback = method(source, "private static void dispatchDownloadFeedback(");
|
||||
assertTrue(feedback.contains("source.getServer().execute(feedback);"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,6 +175,34 @@ public class ModdedGenerationLeaseContractTest {
|
||||
assertTrue(pending.contains("queuedFinalSave.get() != null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstPregenChunkFailureRetainsItsFullCause() throws IOException {
|
||||
String methodSource = source("art/arcane/iris/modded/command/ModdedPregenMethod.java");
|
||||
String logFailure = method(methodSource, "private void logChunkFailure(");
|
||||
|
||||
assertTrue(methodSource.contains("AtomicBoolean failureDetailLogged"));
|
||||
assertTrue(logFailure.contains("unwrap(failure)"));
|
||||
assertTrue(logFailure.contains("failureDetailLogged.compareAndSet(false, true)"));
|
||||
assertTrue(logFailure.contains("x, z, cause);"));
|
||||
assertTrue(logFailure.contains("cause.toString()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidPregenBoundsFailBeforeRuntimeMutation() throws IOException {
|
||||
String jobSource = source("art/arcane/iris/modded/command/ModdedPregenJob.java");
|
||||
String start = method(jobSource, "public static boolean start(");
|
||||
int taskConstruction = start.indexOf("PregenTask task = PregenTask.builder()");
|
||||
int profileMutation = start.indexOf("PregenPerformanceProfile.apply(engine);");
|
||||
|
||||
assertTrue(taskConstruction >= 0);
|
||||
assertTrue(profileMutation > taskConstruction);
|
||||
|
||||
String commandSource = source("art/arcane/iris/modded/command/ModdedPregenCommands.java");
|
||||
String command = method(commandSource, "static int pregenStart(");
|
||||
assertTrue(command.contains("catch (IllegalArgumentException failure)"));
|
||||
assertTrue(command.contains("IrisModdedCommands.fail(source, failure.getMessage())"));
|
||||
}
|
||||
|
||||
private static String source(String relativePath) throws IOException {
|
||||
String root = System.getProperty(SOURCE_ROOT_PROPERTY);
|
||||
assertTrue("Missing system property " + SOURCE_ROOT_PROPERTY, root != null && !root.isBlank());
|
||||
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IdMapper;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiSection;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiType;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.PalettedContainer;
|
||||
import net.minecraft.world.level.chunk.PalettedContainerFactory;
|
||||
import net.minecraft.world.level.chunk.PalettedContainerRO;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
import net.minecraft.world.level.chunk.Strategy;
|
||||
import net.minecraft.world.level.chunk.UpgradeData;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedNativeStructurePoiRegistrationTest {
|
||||
@BeforeClass
|
||||
public static void bootstrapMinecraftRegistries() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visitsOnlyExistingPoiBlocksBeforeNativePlacement() {
|
||||
ProtoChunk chunk = newChunk();
|
||||
BlockPos poiPosition = new BlockPos(3, 70, 5);
|
||||
BlockPos ordinaryPosition = new BlockPos(4, 70, 5);
|
||||
BlockState poiState = Blocks.BARREL.defaultBlockState();
|
||||
chunk.setBlockState(poiPosition, poiState, 0);
|
||||
chunk.setBlockState(ordinaryPosition, Blocks.STONE.defaultBlockState(), 0);
|
||||
Map<BlockPos, BlockState> visited = new LinkedHashMap<>();
|
||||
|
||||
ModdedNativeStructureStage.visitExistingPois(
|
||||
chunk, (position, state) -> visited.put(position.immutable(), state));
|
||||
|
||||
assertEquals(poiState, visited.get(poiPosition));
|
||||
assertFalse(visited.containsKey(ordinaryPosition));
|
||||
assertEquals(1, visited.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicatePrimingIsIdempotentForAnAlreadyRegisteredPoi() {
|
||||
BlockPos position = new BlockPos(3, 70, 5);
|
||||
Holder<PoiType> type = PoiTypes.forState(
|
||||
Blocks.BARREL.defaultBlockState()).orElseThrow();
|
||||
PoiSection section = new PoiSection(() -> { });
|
||||
|
||||
assertNotNull(section.add(position, type));
|
||||
assertNull(section.add(position, type));
|
||||
assertEquals(type, section.getType(position).orElseThrow());
|
||||
|
||||
section.remove(position);
|
||||
|
||||
assertTrue(section.getType(position).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worldgenPrimingQueuesBeforeTheLaterVanillaRemoval() {
|
||||
ProtoChunk chunk = newChunk();
|
||||
BlockPos position = new BlockPos(3, 70, 5);
|
||||
BlockState poiState = Blocks.BARREL.defaultBlockState();
|
||||
chunk.setBlockState(position, poiState, 0);
|
||||
PoiSection section = new PoiSection(() -> { });
|
||||
Deque<Runnable> serverQueue = new ArrayDeque<>();
|
||||
AtomicInteger missingRemovals = new AtomicInteger();
|
||||
|
||||
ModdedNativeStructureStage.visitExistingPois(chunk,
|
||||
(poiPosition, state) -> queuePoiTransition(
|
||||
serverQueue, section, poiPosition,
|
||||
Blocks.AIR.defaultBlockState(), state, missingRemovals));
|
||||
assertTrue(section.getType(position).isEmpty());
|
||||
queuePoiTransition(serverQueue, section, position,
|
||||
poiState, Blocks.AIR.defaultBlockState(), missingRemovals);
|
||||
|
||||
while (!serverQueue.isEmpty()) {
|
||||
serverQueue.removeFirst().run();
|
||||
}
|
||||
|
||||
assertEquals(0, missingRemovals.get());
|
||||
assertTrue(section.getType(position).isEmpty());
|
||||
}
|
||||
|
||||
private static void queuePoiTransition(Deque<Runnable> serverQueue,
|
||||
PoiSection section,
|
||||
BlockPos position,
|
||||
BlockState oldState,
|
||||
BlockState newState,
|
||||
AtomicInteger missingRemovals) {
|
||||
Optional<Holder<PoiType>> oldType = PoiTypes.forState(oldState);
|
||||
Optional<Holder<PoiType>> newType = PoiTypes.forState(newState);
|
||||
if (Objects.equals(oldType, newType)) {
|
||||
return;
|
||||
}
|
||||
BlockPos immutablePosition = position.immutable();
|
||||
oldType.ifPresent(type -> serverQueue.addLast(() -> {
|
||||
if (section.getType(immutablePosition).isEmpty()) {
|
||||
missingRemovals.incrementAndGet();
|
||||
return;
|
||||
}
|
||||
section.remove(immutablePosition);
|
||||
}));
|
||||
newType.ifPresent(type -> serverQueue.addLast(
|
||||
() -> section.add(immutablePosition, type)));
|
||||
}
|
||||
|
||||
private static ProtoChunk newChunk() {
|
||||
return new ProtoChunk(
|
||||
new ChunkPos(0, 0),
|
||||
UpgradeData.EMPTY,
|
||||
LevelHeightAccessor.create(-64, 384),
|
||||
palettedContainerFactory(),
|
||||
null);
|
||||
}
|
||||
|
||||
private static PalettedContainerFactory palettedContainerFactory() {
|
||||
Strategy<BlockState> blockStrategy = Strategy.createForBlockStates(Block.BLOCK_STATE_REGISTRY);
|
||||
Codec<PalettedContainer<BlockState>> blockCodec = PalettedContainer.codecRW(
|
||||
BlockState.CODEC, blockStrategy, Blocks.AIR.defaultBlockState());
|
||||
Biome biome = new Biome.BiomeBuilder()
|
||||
.hasPrecipitation(false)
|
||||
.temperature(0.8F)
|
||||
.downfall(0.4F)
|
||||
.specialEffects(new BiomeSpecialEffects.Builder().waterColor(0x3F76E4).build())
|
||||
.mobSpawnSettings(MobSpawnSettings.EMPTY)
|
||||
.generationSettings(BiomeGenerationSettings.EMPTY)
|
||||
.build();
|
||||
Holder<Biome> biomeHolder = Holder.direct(biome);
|
||||
IdMapper<Holder<Biome>> biomeIds = new IdMapper<>(1);
|
||||
biomeIds.add(biomeHolder);
|
||||
Strategy<Holder<Biome>> biomeStrategy = Strategy.createForBiomes(biomeIds);
|
||||
Codec<PalettedContainerRO<Holder<Biome>>> biomeCodec = PalettedContainer.codecRO(
|
||||
Biome.CODEC, biomeStrategy, biomeHolder);
|
||||
return new PalettedContainerFactory(
|
||||
blockStrategy,
|
||||
Blocks.AIR.defaultBlockState(),
|
||||
blockCodec,
|
||||
biomeStrategy,
|
||||
biomeHolder,
|
||||
biomeCodec);
|
||||
}
|
||||
}
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.entity.EntityTypeTest;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.ticks.LevelTickAccess;
|
||||
import net.minecraft.world.ticks.ScheduledTick;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedNativeStructureWorldgenAccessTest {
|
||||
private static final int GENERATION_CENTER_X = 60;
|
||||
private static final int GENERATION_CENTER_Z = 15;
|
||||
private static final int SURFACE_FIRST_FREE_Y = 80;
|
||||
private static final int FLOOR_FIRST_FREE_Y = 70;
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrapMinecraftRegistries() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceTwoTerrainReadsNeverReachTheDelegate() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
int x = generationCenter.getMiddleBlockX();
|
||||
int z = (generationCenter.z() + 2) << 4;
|
||||
|
||||
assertSame(Blocks.STONE, access.getBlockState(new BlockPos(x, FLOOR_FIRST_FREE_Y - 1, z)).getBlock());
|
||||
assertSame(Blocks.WATER, access.getBlockState(new BlockPos(x, FLOOR_FIRST_FREE_Y, z)).getBlock());
|
||||
assertSame(Blocks.AIR, access.getBlockState(new BlockPos(x, SURFACE_FIRST_FREE_Y, z)).getBlock());
|
||||
assertSame(Blocks.WATER.defaultBlockState().getFluidState(),
|
||||
access.getFluidState(new BlockPos(x, FLOOR_FIRST_FREE_Y, z)));
|
||||
assertEquals(SURFACE_FIRST_FREE_Y, access.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z));
|
||||
assertEquals(FLOOR_FIRST_FREE_Y, access.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z));
|
||||
assertNull(access.getChunk(generationCenter.x(), generationCenter.z() + 2, ChunkStatus.FEATURES, false));
|
||||
List<BlockState> loadedOnly = access.getBlockStatesIfLoaded(new AABB(
|
||||
x, FLOOR_FIRST_FREE_Y, z, x, FLOOR_FIRST_FREE_Y, z)).toList();
|
||||
List<BlockState> streamed = access.getBlockStates(new AABB(
|
||||
x, FLOOR_FIRST_FREE_Y, z, x, FLOOR_FIRST_FREE_Y, z)).toList();
|
||||
|
||||
assertTrue(loadedOnly.isEmpty());
|
||||
assertEquals(1, streamed.size());
|
||||
assertSame(Blocks.WATER, streamed.getFirst().getBlock());
|
||||
assertEquals(0, recording.terrainReads);
|
||||
assertEquals(0, recording.heightReads);
|
||||
assertEquals(0, recording.chunkReads);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceTwoMutationsAndSideEffectsNeverReachTheDelegate() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
BlockPos position = new BlockPos(
|
||||
generationCenter.getMiddleBlockX(),
|
||||
FLOOR_FIRST_FREE_Y,
|
||||
(generationCenter.z() + 2) << 4);
|
||||
|
||||
assertFalse(access.ensureCanWrite(position));
|
||||
assertFalse(access.setBlock(position, Blocks.DIRT.defaultBlockState(), 2));
|
||||
assertFalse(access.removeBlock(position, false));
|
||||
assertFalse(access.destroyBlock(position, false));
|
||||
access.updateNeighborsAt(position, Blocks.DIRT);
|
||||
access.neighborShapeChanged(
|
||||
Direction.NORTH, position, position.north(),
|
||||
Blocks.DIRT.defaultBlockState(), 2, 512);
|
||||
access.levelEvent(null, 2001, position, 0);
|
||||
access.gameEvent(null, Vec3.atCenterOf(position), null);
|
||||
access.addParticle(null, position.getX(), position.getY(), position.getZ(), 0, 0, 0);
|
||||
access.getBlockTicks().schedule(new ScheduledTick<>(
|
||||
Blocks.DIRT, position, 1L, 0L));
|
||||
|
||||
assertEquals(0, recording.mutations);
|
||||
assertEquals(0, recording.events);
|
||||
assertEquals(0, recording.blockTicks.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void radiusOneReadsWritesAndTicksRemainUnchanged() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
BlockPos position = new BlockPos(
|
||||
(generationCenter.x() + 1) << 4,
|
||||
FLOOR_FIRST_FREE_Y,
|
||||
(generationCenter.z() - 1) << 4);
|
||||
|
||||
assertTrue(access.isInsideGenerationRegion(
|
||||
generationCenter.x() + 1, generationCenter.z() - 1));
|
||||
assertSame(Blocks.DIRT, access.getBlockState(position).getBlock());
|
||||
assertEquals(91, access.getHeight(
|
||||
Heightmap.Types.WORLD_SURFACE_WG, position.getX(), position.getZ()));
|
||||
assertTrue(access.ensureCanWrite(position));
|
||||
assertTrue(access.setBlock(position, Blocks.STONE.defaultBlockState(), 2));
|
||||
assertTrue(access.removeBlock(position, false));
|
||||
assertTrue(access.destroyBlock(position, false));
|
||||
access.getBlockTicks().schedule(new ScheduledTick<>(
|
||||
Blocks.DIRT, position, 1L, 0L));
|
||||
|
||||
assertEquals(1, recording.terrainReads);
|
||||
assertEquals(1, recording.heightReads);
|
||||
assertEquals(4, recording.mutations);
|
||||
assertEquals(1, recording.blockTicks.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statuslessChunkReadsPreserveWorldgenDelegateSemantics() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
|
||||
assertNull(access.getChunk(generationCenter.getWorldPosition()));
|
||||
|
||||
assertEquals(1, recording.statuslessChunkReads);
|
||||
assertEquals(0, recording.statusChunkReads);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void entityQueriesRejectDisjointAreasAndClampOverlaps() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ModdedNativeStructureWorldgenAccess access = access(recording);
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
int safeMaxX = generationCenter.getMaxBlockX() + 17;
|
||||
int safeMinZ = generationCenter.getMinBlockZ() - 16;
|
||||
int safeMaxZ = generationCenter.getMaxBlockZ() + 17;
|
||||
AABB disjoint = new AABB(
|
||||
safeMaxX, -64, safeMinZ,
|
||||
safeMaxX + 16, 320, safeMaxZ);
|
||||
AABB overlap = new AABB(
|
||||
safeMaxX - 8, -128, safeMinZ - 8,
|
||||
safeMaxX + 16, 400, safeMaxZ + 8);
|
||||
EntityTypeTest<Entity, Entity> type = EntityTypeTest.forClass(Entity.class);
|
||||
|
||||
assertTrue(access.getEntities((Entity) null, disjoint, entity -> true).isEmpty());
|
||||
assertTrue(access.getEntities(type, disjoint, entity -> true).isEmpty());
|
||||
access.getEntities((Entity) null, overlap, entity -> true);
|
||||
access.getEntities(type, overlap, entity -> true);
|
||||
|
||||
assertEquals(2, recording.entityAreas.size());
|
||||
for (AABB delegatedArea : recording.entityAreas) {
|
||||
assertEquals(safeMaxX - 8, delegatedArea.minX, 0D);
|
||||
assertEquals(-64, delegatedArea.minY, 0D);
|
||||
assertEquals(safeMinZ, delegatedArea.minZ, 0D);
|
||||
assertEquals(safeMaxX, delegatedArea.maxX, 0D);
|
||||
assertEquals(320, delegatedArea.maxY, 0D);
|
||||
assertEquals(safeMaxZ, delegatedArea.maxZ, 0D);
|
||||
}
|
||||
}
|
||||
|
||||
private static ModdedNativeStructureWorldgenAccess access(RecordingDelegate recording) {
|
||||
return ModdedNativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter(),
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y);
|
||||
}
|
||||
|
||||
private static ChunkPos generationCenter() {
|
||||
return new ChunkPos(GENERATION_CENTER_X, GENERATION_CENTER_Z);
|
||||
}
|
||||
|
||||
private static final class RecordingDelegate implements InvocationHandler {
|
||||
private final Holder<Biome> biome;
|
||||
private final BiomeManager biomeManager;
|
||||
private final RecordingTicks<Block> blockTicks;
|
||||
private final RecordingTicks<Fluid> fluidTicks;
|
||||
private final List<AABB> entityAreas;
|
||||
private int terrainReads;
|
||||
private int heightReads;
|
||||
private int chunkReads;
|
||||
private int statuslessChunkReads;
|
||||
private int statusChunkReads;
|
||||
private int mutations;
|
||||
private int events;
|
||||
|
||||
private RecordingDelegate() {
|
||||
this.biome = Holder.direct((Biome) null);
|
||||
this.biomeManager = new BiomeManager((x, y, z) -> biome, 13L);
|
||||
this.blockTicks = new RecordingTicks<>();
|
||||
this.fluidTicks = new RecordingTicks<>();
|
||||
this.entityAreas = new ArrayList<>();
|
||||
}
|
||||
|
||||
private WorldGenLevel world() {
|
||||
return (WorldGenLevel) Proxy.newProxyInstance(
|
||||
WorldGenLevel.class.getClassLoader(),
|
||||
new Class<?>[]{WorldGenLevel.class}, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] arguments) {
|
||||
String name = method.getName();
|
||||
if (name.equals("getSeaLevel")) {
|
||||
return 63;
|
||||
}
|
||||
if (name.equals("getBiome")) {
|
||||
return biome;
|
||||
}
|
||||
if (name.equals("getBiomeManager")) {
|
||||
return biomeManager;
|
||||
}
|
||||
if (name.equals("getBlockTicks")) {
|
||||
return blockTicks;
|
||||
}
|
||||
if (name.equals("getFluidTicks")) {
|
||||
return fluidTicks;
|
||||
}
|
||||
if (name.equals("getMinY")) {
|
||||
return -64;
|
||||
}
|
||||
if (name.equals("getHeight") && arguments == null) {
|
||||
return 384;
|
||||
}
|
||||
if (name.equals("getHeight")) {
|
||||
heightReads++;
|
||||
return 91;
|
||||
}
|
||||
if (name.equals("getBlockState")) {
|
||||
terrainReads++;
|
||||
return Blocks.DIRT.defaultBlockState();
|
||||
}
|
||||
if (name.equals("getFluidState")) {
|
||||
terrainReads++;
|
||||
return Blocks.WATER.defaultBlockState().getFluidState();
|
||||
}
|
||||
if (name.equals("getChunk")) {
|
||||
chunkReads++;
|
||||
if (arguments.length == 2) {
|
||||
statuslessChunkReads++;
|
||||
} else {
|
||||
statusChunkReads++;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (name.equals("getChunkIfLoadedImmediately")) {
|
||||
chunkReads++;
|
||||
return null;
|
||||
}
|
||||
if (name.equals("getEntities")) {
|
||||
entityAreas.add((AABB) arguments[1]);
|
||||
return List.of();
|
||||
}
|
||||
if (name.equals("ensureCanWrite") || name.equals("setBlock")
|
||||
|| name.equals("removeBlock") || name.equals("destroyBlock")) {
|
||||
mutations++;
|
||||
return true;
|
||||
}
|
||||
if (name.equals("updateNeighborsAt") || name.equals("neighborShapeChanged")) {
|
||||
mutations++;
|
||||
return null;
|
||||
}
|
||||
if (name.equals("levelEvent") || name.equals("gameEvent") || name.equals("addParticle")) {
|
||||
events++;
|
||||
return null;
|
||||
}
|
||||
if (name.equals("hashCode")) {
|
||||
return System.identityHashCode(proxy);
|
||||
}
|
||||
if (name.equals("equals")) {
|
||||
return proxy == arguments[0];
|
||||
}
|
||||
if (name.equals("toString")) {
|
||||
return "native-structure-worldgen-test-delegate";
|
||||
}
|
||||
throw new UnsupportedOperationException(method.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingTicks<T> implements LevelTickAccess<T> {
|
||||
private int count;
|
||||
|
||||
@Override
|
||||
public void schedule(ScheduledTick<T> tick) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScheduledTick(BlockPos position, T type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willTickThisTick(BlockPos position, T type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedStructureTemplateCacheTest {
|
||||
@Test
|
||||
public void concurrentCacheOwnsDistinctAndSharedMappingsExactlyOnce() throws Exception {
|
||||
ConcurrentHashMap<String, Integer> cache = new ConcurrentHashMap<>();
|
||||
ExecutorService executor = Executors.newFixedThreadPool(32);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
AtomicInteger mappingCalls = new AtomicInteger();
|
||||
List<Future<Integer>> futures = new ArrayList<>();
|
||||
try {
|
||||
for (int task = 0; task < 256; task++) {
|
||||
int value = task;
|
||||
String key = task % 2 == 0 ? "shared" : "distinct-" + task;
|
||||
futures.add(executor.submit(() -> {
|
||||
start.await();
|
||||
return cache.computeIfAbsent(key, ignored -> {
|
||||
mappingCalls.incrementAndGet();
|
||||
Thread.yield();
|
||||
return value;
|
||||
});
|
||||
}));
|
||||
}
|
||||
start.countDown();
|
||||
for (Future<Integer> future : futures) {
|
||||
assertNotNull(future.get(10, TimeUnit.SECONDS));
|
||||
}
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
assertEquals(129, cache.size());
|
||||
assertEquals(129, mappingCalls.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requiredCommonMixinConfigRegistersPaletteConcurrencyFix() throws Exception {
|
||||
InputStream resource = ModdedStructureTemplateCacheTest.class.getClassLoader()
|
||||
.getResourceAsStream("irisworldgen.entity.mixins.json");
|
||||
assertNotNull(resource);
|
||||
String config;
|
||||
try (InputStream input = resource) {
|
||||
config = new String(input.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
assertTrue(config.contains("\"StructureTemplatePaletteConcurrencyMixin\""));
|
||||
|
||||
Path source = Path.of(System.getProperty("iris.moddedCommonSources"))
|
||||
.resolve("art/arcane/iris/modded/mixin/StructureTemplatePaletteConcurrencyMixin.java");
|
||||
String mixin = Files.readString(source);
|
||||
assertTrue(mixin.contains("@Mixin(StructureTemplate.Palette.class)"));
|
||||
assertTrue(mixin.contains("@Shadow\n @Final\n @Mutable"));
|
||||
assertTrue(mixin.contains("private Map<Block, List<StructureTemplate.StructureBlockInfo>> cache;"));
|
||||
assertTrue(mixin.contains("@Inject(method = \"<init>(Ljava/util/List;)V\", at = @At(\"RETURN\"))"));
|
||||
assertTrue(mixin.contains("cache = new ConcurrentHashMap<>();"));
|
||||
}
|
||||
}
|
||||
+18
@@ -67,6 +67,11 @@ public class NativeStructureFailureContractTest {
|
||||
assertTrue(placement.contains("\"terrain preparation\""));
|
||||
assertTrue(placement.contains("\"foundation repair\""));
|
||||
assertFalse(placement.contains("\"terrain carving\""));
|
||||
assertTrue(placement.contains("visitExistingPois(chunk"));
|
||||
assertTrue(placement.contains("level.updatePOIOnBlockStateChange("));
|
||||
assertTrue(placement.contains("Blocks.AIR.defaultBlockState(), state"));
|
||||
assertTrue(placement.indexOf("visitExistingPois(chunk")
|
||||
< placement.indexOf("WorldgenTerrainHeightmaps.primeStructurePlacement("));
|
||||
assertTrue(placement.contains("prepareSurfaceStructures"));
|
||||
assertTrue(placement.contains("clearIntersectingVegetation"));
|
||||
assertTrue(placement.indexOf("clearIntersectingVegetation")
|
||||
@@ -95,6 +100,19 @@ public class NativeStructureFailureContractTest {
|
||||
assertTrue(source.contains("int minY = chunk.getMinY() + 1;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeStructurePostProcessingUsesBoundedWorldgenAccess() throws IOException {
|
||||
String source = moddedSource("ModdedNativeStructureStage.java");
|
||||
int placementStart = source.indexOf("private void placeVanillaStructure");
|
||||
int placementEnd = source.indexOf("private List<List<Structure>> structuresByStep", placementStart);
|
||||
String placement = source.substring(placementStart, placementEnd);
|
||||
|
||||
assertTrue(placement.contains("ModdedNativeStructureWorldgenAccess.create("));
|
||||
assertTrue(placement.contains("NativeStructurePostProcessor.place(\n boundedWorld"));
|
||||
assertFalse(placement.contains("NativeStructurePostProcessor.place(world,"));
|
||||
assertTrue(placement.contains("world.setCurrentlyGenerating(null);"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structureFailurePreservesPhaseIdentityChunkAndCause() {
|
||||
IllegalArgumentException cause = new IllegalArgumentException("broken placement");
|
||||
|
||||
Reference in new issue
Block a user