mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
Merge upstream port lane c
This commit is contained in:
commit
55786d6297
50 files changed
+2014
-256
No files matched your search
@@ -357,6 +357,111 @@ public class DatapackIngestServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadCopiesLocalFileUrl() throws Exception {
|
||||
Path source = temporaryFolder.newFile("local source.zip").toPath();
|
||||
Files.writeString(source, "local-archive", StandardCharsets.UTF_8);
|
||||
File destination = new File(temporaryFolder.newFolder("local-download"), "pack.zip");
|
||||
|
||||
DatapackIngestService.DownloadResult result = DatapackIngestService.download(
|
||||
source.toUri().toASCIIString(),
|
||||
destination,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
assertFalse(result.notModified());
|
||||
assertEquals("local-archive", Files.readString(destination.toPath(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedLocalDownloadPreservesExistingDestination() throws Exception {
|
||||
Path missing = temporaryFolder.getRoot().toPath().resolve("missing.zip");
|
||||
File destination = new File(temporaryFolder.newFolder("local-download-existing"), "pack.zip");
|
||||
Files.writeString(destination.toPath(), "existing", StandardCharsets.UTF_8);
|
||||
|
||||
try {
|
||||
DatapackIngestService.download(
|
||||
missing.toUri().toASCIIString(),
|
||||
destination,
|
||||
null,
|
||||
null
|
||||
);
|
||||
fail("Expected missing local source rejection");
|
||||
} catch (IOException expected) {
|
||||
assertTrue(expected.getMessage().contains("regular non-symbolic-link file"));
|
||||
}
|
||||
|
||||
assertEquals("existing", Files.readString(destination.toPath(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localDropFolderDiscoversOnlyTopLevelZipFilesInStableOrder() throws Exception {
|
||||
File imports = temporaryFolder.newFolder("local-imports");
|
||||
Path first = new File(imports, "Alpha Pack.ZIP").toPath();
|
||||
Path second = new File(imports, "bravo.zip").toPath();
|
||||
Files.writeString(first, "alpha", StandardCharsets.UTF_8);
|
||||
Files.writeString(second, "bravo", StandardCharsets.UTF_8);
|
||||
Files.writeString(new File(imports, "ignored.txt").toPath(), "ignored", StandardCharsets.UTF_8);
|
||||
Path nested = new File(imports, "nested/hidden.zip").toPath();
|
||||
Files.createDirectories(nested.getParent());
|
||||
Files.writeString(nested, "nested", StandardCharsets.UTF_8);
|
||||
|
||||
List<String> discovered = DatapackIngestService.discoverLocalDatapackImports(imports);
|
||||
|
||||
assertEquals(List.of(
|
||||
first.toAbsolutePath().normalize().toUri().toASCIIString(),
|
||||
second.toAbsolutePath().normalize().toUri().toASCIIString()
|
||||
), discovered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localDropFolderSkipsSymbolicLinkArchives() throws Exception {
|
||||
File imports = temporaryFolder.newFolder("local-imports-links");
|
||||
Path real = temporaryFolder.newFile("linked-target.zip").toPath();
|
||||
Path link = new File(imports, "linked.zip").toPath();
|
||||
try {
|
||||
Files.createSymbolicLink(link, real);
|
||||
} catch (UnsupportedOperationException | IOException unsupported) {
|
||||
return;
|
||||
}
|
||||
|
||||
assertTrue(DatapackIngestService.discoverLocalDatapackImports(imports).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredFileSourceNormalizesToTheDiscoveredArchiveUri() throws Exception {
|
||||
Path source = temporaryFolder.newFile("normalized-local.zip").toPath();
|
||||
String discovered = source.toAbsolutePath().normalize().toUri().toASCIIString();
|
||||
String alternate = discovered.replace("file:///", "file:/");
|
||||
|
||||
assertEquals(discovered, DatapackIngestService.normalizeConfiguredSource(alternate));
|
||||
assertEquals(
|
||||
Set.of("https://example.test/dimension.zip", discovered),
|
||||
DatapackIngestService.mergeConfiguredImports(
|
||||
List.of("https://example.test/dimension.zip", alternate),
|
||||
List.of(discovered)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startupValidationFingerprintChangesWithLocalSourceBytes() throws Exception {
|
||||
File root = temporaryFolder.newFolder("startup-local-source-fingerprint");
|
||||
Path source = temporaryFolder.newFile("startup-local.zip").toPath();
|
||||
KList<File> worldFolders = new KList<>();
|
||||
String sourceUrl = source.toUri().toASCIIString();
|
||||
Files.writeString(source, "alpha", StandardCharsets.UTF_8);
|
||||
String before = DatapackIngestService.startupValidationFingerprint(
|
||||
root, worldFolders, List.of(sourceUrl));
|
||||
|
||||
FileTime originalTime = Files.getLastModifiedTime(source);
|
||||
Files.writeString(source, "bravo", StandardCharsets.UTF_8);
|
||||
Files.setLastModifiedTime(source, originalTime);
|
||||
String after = DatapackIngestService.startupValidationFingerprint(
|
||||
root, worldFolders, List.of(sourceUrl));
|
||||
|
||||
assertFalse(before.equals(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removalRequiresMatchingIrisOwnership() throws Exception {
|
||||
File unmanaged = datapackDirectory("unmanaged");
|
||||
|
||||
@@ -8,6 +8,9 @@ import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -104,6 +107,25 @@ public class ModrinthResolverTest {
|
||||
assertFalse(resolved.getVersionId().isBlank());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileUrlResolvesAsDirectArchiveWithDecodedFilename() throws Exception {
|
||||
Path directory = Files.createTempDirectory("iris-local-resolver");
|
||||
Path archive = directory.resolve("local pack.zip");
|
||||
try {
|
||||
Files.writeString(archive, "archive", StandardCharsets.UTF_8);
|
||||
|
||||
ModrinthResolver.ResolvedDatapack resolved = ModrinthResolver.resolve(
|
||||
archive.toUri().toASCIIString(), "26.2");
|
||||
|
||||
assertTrue(resolved.isDirect());
|
||||
assertEquals("local pack.zip", resolved.getFileName());
|
||||
assertFalse(resolved.getVersionId().isBlank());
|
||||
} finally {
|
||||
Files.deleteIfExists(archive);
|
||||
Files.deleteIfExists(directory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boundedApiReaderAcceptsTheExactCharacterLimit() throws Exception {
|
||||
String response = "1234\n5678";
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package art.arcane.iris.engine.mantle;
|
||||
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.DeferredPlacementRecords.WrittenBlocks;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.util.project.matter.TileWrapper;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class DeferredPlacementRecordsTest {
|
||||
private static final int MIN_HEIGHT = -64;
|
||||
private static final int SECTION_COUNT = 24;
|
||||
|
||||
private Engine engine;
|
||||
private Mantle<Matter> mantle;
|
||||
private MantleChunk<Matter> chunk;
|
||||
private Matter section;
|
||||
private MatterSlice<Identifier> identifiers;
|
||||
private MatterSlice<TileWrapper> tiles;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
IrisPlatforms.unbind();
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(registries.block(anyString())).thenReturn(mock(PlatformBlockState.class));
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
IrisPlatforms.bind(platform);
|
||||
|
||||
engine = mock(Engine.class);
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
mantle = mock(Mantle.class);
|
||||
chunk = mock(MantleChunk.class);
|
||||
section = mock(Matter.class);
|
||||
identifiers = mock(MatterSlice.class);
|
||||
tiles = mock(MatterSlice.class);
|
||||
|
||||
when(engine.getMantle()).thenReturn(engineMantle);
|
||||
when(engine.getMinHeight()).thenReturn(MIN_HEIGHT);
|
||||
when(engineMantle.getMantle()).thenReturn(mantle);
|
||||
when(mantle.getChunk(anyInt(), anyInt())).thenReturn(chunk);
|
||||
when(chunk.use()).thenReturn(chunk);
|
||||
when(chunk.sectionCount()).thenReturn(SECTION_COUNT);
|
||||
when(chunk.exists(anyInt())).thenReturn(true);
|
||||
when(chunk.get(anyInt())).thenReturn(section);
|
||||
when(section.hasSlice(Identifier.class)).thenReturn(true);
|
||||
when(section.hasSlice(TileWrapper.class)).thenReturn(true);
|
||||
when(section.getSlice(Identifier.class)).thenReturn(identifiers);
|
||||
when(section.getSlice(TileWrapper.class)).thenReturn(tiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writtenPositionsLoseTheirCustomAndTileRecords() {
|
||||
WrittenBlocks written = new WrittenBlocks();
|
||||
written.add(19, 70, 5);
|
||||
|
||||
DeferredPlacementRecords.clearWritten(engine, written);
|
||||
|
||||
int mantleY = 70 - MIN_HEIGHT;
|
||||
verify(chunk).get(mantleY >> 4);
|
||||
verify(identifiers).set(3, mantleY & 15, 5, null);
|
||||
verify(tiles).set(3, mantleY & 15, 5, null);
|
||||
verify(mantle).getChunk(1, 0);
|
||||
verify(chunk).release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eachTouchedChunkIsAcquiredOnceAndReleasedOnce() {
|
||||
WrittenBlocks written = new WrittenBlocks();
|
||||
written.add(1, 70, 1);
|
||||
written.add(2, 71, 2);
|
||||
written.add(-1, 70, 1);
|
||||
|
||||
DeferredPlacementRecords.clearWritten(engine, written);
|
||||
|
||||
verify(mantle).getChunk(0, 0);
|
||||
verify(mantle).getChunk(-1, 0);
|
||||
verify(chunk, times(2)).release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void positionsBelowTheWorldOrInMissingSectionsAreIgnored() {
|
||||
when(chunk.exists(anyInt())).thenReturn(false);
|
||||
WrittenBlocks written = new WrittenBlocks();
|
||||
written.add(1, MIN_HEIGHT - 1, 1);
|
||||
written.add(1, 70, 1);
|
||||
|
||||
DeferredPlacementRecords.clearWritten(engine, written);
|
||||
|
||||
verify(identifiers, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
verify(tiles, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slicesThatWereNeverCreatedAreNotCreatedByClearing() {
|
||||
when(section.hasSlice(Identifier.class)).thenReturn(false);
|
||||
WrittenBlocks written = new WrittenBlocks();
|
||||
written.add(1, 70, 1);
|
||||
|
||||
DeferredPlacementRecords.clearWritten(engine, written);
|
||||
|
||||
verify(section, never()).getSlice(Identifier.class);
|
||||
verify(tiles).set(1, (70 - MIN_HEIGHT) & 15, 1, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noWritesLeaveTheMantleUntouched() {
|
||||
DeferredPlacementRecords.clearWritten(engine, new WrittenBlocks());
|
||||
|
||||
verifyNoInteractions(mantle);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,18 @@ public class PlacementReachTest {
|
||||
assertEquals(53, PlacementReach.of(new ObjectSize(5, 48, 7), placement));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slopeTiltReachesAsFarAsAVerticalRotationEvenWhenTheRotationIsDisabled() {
|
||||
String disabledRotation = "\"rotation\":{\"enabled\":false}";
|
||||
ObjectPlacement flat = TestSettings.of(ObjectPlacement.class, "{" + disabledRotation + ",\"translate\":{\"x\":3,\"y\":4}}");
|
||||
ObjectPlacement tilted = TestSettings.of(ObjectPlacement.class,
|
||||
"{" + disabledRotation + ",\"rotateTowardsSlope\":true,\"translate\":{\"x\":3,\"y\":4}}");
|
||||
ObjectSize tallObject = new ObjectSize(5, 48, 7);
|
||||
|
||||
assertEquals(10, PlacementReach.of(tallObject, flat));
|
||||
assertEquals(53, PlacementReach.of(tallObject, tilted));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scaleWarpAndVacuumExpandPlacementReach() {
|
||||
ObjectPlacement placement = TestSettings.of(ObjectPlacement.class,
|
||||
|
||||
+11
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.engine.object.placement;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -18,6 +19,16 @@ public class IrisObjectStructurePieceAirTest {
|
||||
assertTrue(BlocksModule.shouldPlaceObjectBlock(false, false, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBlockTurnedIntoAirHadNoValidOrientationAndIsDropped() {
|
||||
BlockState torch = new BlockState("minecraft:wall_torch");
|
||||
BlockState air = new BlockState("minecraft:air");
|
||||
|
||||
assertTrue(BlocksModule.isDroppedByRotation(torch, air));
|
||||
assertFalse(BlocksModule.isDroppedByRotation(torch, torch));
|
||||
assertFalse(BlocksModule.isDroppedByRotation(air, air));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vineReplacementRemainsRejectedForEveryPlacementMode() {
|
||||
assertFalse(BlocksModule.shouldPlaceObjectBlock(false, false, true));
|
||||
|
||||
+11
-7
@@ -110,7 +110,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
placer.carve(0, SURFACE_Y, 0);
|
||||
|
||||
assertEquals("mode " + mode + " must skip over a carved column",
|
||||
-1, place(placer, placement(mode), -1));
|
||||
-1, placeAutomatic(placer, placement(mode)));
|
||||
assertTrue("mode " + mode + " must not write blocks", placer.written().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
placer.carve(2, SURFACE_Y, 0);
|
||||
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1));
|
||||
assertEquals(-1, placeAutomatic(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,14 +128,14 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
placer.carve(6, SURFACE_Y, 0);
|
||||
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1) >= 0);
|
||||
assertTrue(placeAutomatic(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void solidGroundStillPlaces() {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1) >= 0);
|
||||
assertTrue(placeAutomatic(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,7 +153,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
ObjectPlacement.Builder placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.forcePlace(true);
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(placeAutomatic(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,7 +163,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
ObjectPlacement.Builder placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.requireSurfaceSupport(false);
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(placeAutomatic(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,7 +248,11 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
ObjectPlacement.Builder placement = placement(ObjectPlaceMode.FLOATING);
|
||||
placement.translate(ObjectTranslate.of(0, SURFACE_Y + 40, 0, 0));
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(placeAutomatic(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
private int placeAutomatic(SurfacePlacer placer, ObjectPlacement.Builder placement) {
|
||||
return ModuleObjectPlacement.placeAutomatic(object(), 0, 0, placer, placement.build(), new RNG(1234L), null, null, data).heightOrRejected();
|
||||
}
|
||||
|
||||
private int place(SurfacePlacer placer, ObjectPlacement.Builder placement, int anchorY) {
|
||||
|
||||
+14
-8
@@ -33,6 +33,7 @@ import java.util.HexFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -108,9 +109,14 @@ public class ObjectPlaceModePinTest {
|
||||
.translate(ObjectTranslate.of(0, mode == ObjectPlaceMode.FLOATING ? 140 : 2, 0, 0))
|
||||
.build();
|
||||
CarveResult cave = isCaveMode(mode) ? new CarveResult(CAVE_FLOOR_Y, CEILING_Y) : null;
|
||||
int requestedY = requestedY(mode);
|
||||
ModuleObjectPlacement.place(pinnedObject(), OBJECT_X, requestedY, OBJECT_Z, placer, config,
|
||||
new RNG(PLACEMENT_SEED), null, cave, data);
|
||||
OptionalInt requestedY = requestedY(mode);
|
||||
if (requestedY.isPresent()) {
|
||||
ModuleObjectPlacement.place(pinnedObject(), OBJECT_X, requestedY.getAsInt(), OBJECT_Z, placer, config,
|
||||
new RNG(PLACEMENT_SEED), null, cave, data);
|
||||
} else {
|
||||
ModuleObjectPlacement.placeAutomatic(pinnedObject(), OBJECT_X, OBJECT_Z, placer, config,
|
||||
new RNG(PLACEMENT_SEED), null, cave, data);
|
||||
}
|
||||
return placer.writes();
|
||||
}
|
||||
|
||||
@@ -119,12 +125,12 @@ public class ObjectPlaceModePinTest {
|
||||
}
|
||||
|
||||
/** Cave modes and structure pieces are placed at a height, the way their callers place them; the rest sample. */
|
||||
private static int requestedY(ObjectPlaceMode mode) {
|
||||
private static OptionalInt requestedY(ObjectPlaceMode mode) {
|
||||
return switch (mode) {
|
||||
case CEILING_HANG -> CEILING_Y - 9;
|
||||
case ORGANIC_STILT -> CAVE_FLOOR_Y + 12;
|
||||
case STRUCTURE_PIECE -> 90;
|
||||
default -> -1;
|
||||
case CEILING_HANG -> OptionalInt.of(CEILING_Y - 9);
|
||||
case ORGANIC_STILT -> OptionalInt.of(CAVE_FLOOR_Y + 12);
|
||||
case STRUCTURE_PIECE -> OptionalInt.of(90);
|
||||
default -> OptionalInt.empty();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+78
-7
@@ -37,6 +37,7 @@ import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleSetup;
|
||||
@@ -203,7 +204,7 @@ public class ObjectPlacementRegressionTest {
|
||||
placement.mode(ObjectPlaceMode.MAX_HEIGHT);
|
||||
placement.rotation(ObjectRotation.of(0, 45, 0));
|
||||
|
||||
placed(boxObject(5, 1, 3), 0, -1, 0, placer, placement.build(), new RNG(2L), data);
|
||||
placedAutomatic(boxObject(5, 1, 3), 0, 0, placer, placement.build(), new RNG(2L), data);
|
||||
|
||||
assertTrue(placer.sampledColumns().contains("-2:-2"));
|
||||
assertTrue(placer.sampledColumns().contains("2:2"));
|
||||
@@ -334,7 +335,7 @@ public class ObjectPlacementRegressionTest {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
ObjectPlacement.Builder config = placement();
|
||||
config.mode(ObjectPlaceMode.ERODE_STILT);
|
||||
assertEquals(ANCHOR_Y, placed(lineObject(1), 0, -1, 0, placer, config.build(), new RNG(2L), data));
|
||||
assertEquals(ANCHOR_Y, placedAutomatic(lineObject(1), 0, 0, placer, config.build(), new RNG(2L), data));
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@@ -527,12 +528,36 @@ public class ObjectPlacementRegressionTest {
|
||||
assertNull(storage.value(MARKS, TEXT, 1, ANCHOR_Y, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitHeightBelowZeroIsPlacedWhereAsked() {
|
||||
for (int requestedY : new int[]{-1, -3}) {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
ObjectPlacementResult result = ModuleObjectPlacement.place(lineObject(1), 0, requestedY, 0, placer,
|
||||
placement().build(), new RNG(2L), null, null, data);
|
||||
assertTrue(result.isPlaced());
|
||||
assertEquals(requestedY, result.height());
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == requestedY));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void automaticHeightSamplesTheTerrain() {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
ObjectPlacementResult result = ModuleObjectPlacement.placeAutomatic(lineObject(1), 0, 0, placer,
|
||||
placement().build(), new RNG(2L), null, null, data);
|
||||
assertTrue(result.isPlaced());
|
||||
assertEquals(ANCHOR_Y, result.height());
|
||||
assertFalse(placer.sampledColumns().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromBottomKeepsItsAnchorWithoutSamplingTerrain() {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
ObjectPlacement.Builder config = placement();
|
||||
config.fromBottom(true);
|
||||
assertEquals(2, placed(lineObject(1), 0, -1, 0, placer, config.build(), new RNG(2L), data));
|
||||
assertEquals(2, placedAutomatic(lineObject(1), 0, 0, placer, config.build(), new RNG(2L), data));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
}
|
||||
|
||||
@@ -542,7 +567,7 @@ public class ObjectPlacementRegressionTest {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
ObjectPlacement.Builder config = placement().bore(true).snow(0.1);
|
||||
CarveResult cave = null;
|
||||
int anchor = ANCHOR_Y;
|
||||
boolean automatic = false;
|
||||
switch (reason) {
|
||||
case "carving-anchor" -> {
|
||||
placer.carved = true;
|
||||
@@ -550,7 +575,7 @@ public class ObjectPlacementRegressionTest {
|
||||
}
|
||||
case "underwater-anchor" -> {
|
||||
placer.underwater = true;
|
||||
anchor = -1;
|
||||
automatic = true;
|
||||
}
|
||||
case "cave-clearance" -> cave = new CarveResult(ANCHOR_Y, ANCHOR_Y + 1);
|
||||
case "fluid-height" -> {
|
||||
@@ -559,13 +584,13 @@ public class ObjectPlacementRegressionTest {
|
||||
}
|
||||
case "height-clamp" -> config.clamp(TestSettings.of(ObjectLimit.class, "{\"maximumHeight\":" + (ANCHOR_Y - 1) + "}"));
|
||||
}
|
||||
ObjectPlacementResult result = place(config, anchor, placer, cave);
|
||||
ObjectPlacementResult result = place(config, automatic, placer, cave);
|
||||
assertEquals(Optional.of(reason), result.rejection());
|
||||
assertEquals(-1, result.heightOrRejected());
|
||||
assertTrue(reason, placer.writes().isEmpty());
|
||||
|
||||
config.forcePlace(true);
|
||||
assertTrue(reason, place(config, anchor, placer, cave).isPlaced());
|
||||
assertTrue(reason, place(config, automatic, placer, cave).isPlaced());
|
||||
assertFalse(reason, placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -585,6 +610,41 @@ public class ObjectPlacementRegressionTest {
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void obliqueRotationRejectsNativePiecesBeyondTheUnrotatedRadius() {
|
||||
int reach = 14;
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(new KList<>(
|
||||
NativeStructureVolume.of("minecraft:village", reach, ANCHOR_Y, 0, reach, ANCHOR_Y, 0),
|
||||
NativeStructureVolume.of("minecraft:village", -reach, ANCHOR_Y, 0, -reach, ANCHOR_Y, 0),
|
||||
NativeStructureVolume.of("minecraft:village", 0, ANCHOR_Y, reach, 0, ANCHOR_Y, reach),
|
||||
NativeStructureVolume.of("minecraft:village", 0, ANCHOR_Y, -reach, 0, ANCHOR_Y, -reach)));
|
||||
IrisObject object = new IrisObject(21, 1, 21);
|
||||
object.setUnsigned(20, 0, 20, solid);
|
||||
RecordingPlacer placer = new RecordingPlacer(engine);
|
||||
|
||||
ObjectPlacementResult result = ModuleObjectPlacement.place(object, 0, ANCHOR_Y, 0, placer,
|
||||
placement().rotation(ObjectRotation.of(0, 45, 0)).build(), new RNG(2L), null, null, data);
|
||||
|
||||
assertEquals(Optional.of("native-structure"), result.rejection());
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void offCenterOriginRejectsNativePiecesAtTheFarEdge() {
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(
|
||||
new KList<>(NativeStructureVolume.of("minecraft:village", 8, ANCHOR_Y, 0, 8, ANCHOR_Y, 0)));
|
||||
IrisObject object = new IrisObject(9, 1, 1);
|
||||
object.setCenter(new Vector3i(0, 0, 0));
|
||||
object.setUnsigned(8, 0, 0, solid);
|
||||
RecordingPlacer placer = new RecordingPlacer(engine);
|
||||
|
||||
ObjectPlacementResult result = ModuleObjectPlacement.place(object, 0, ANCHOR_Y, 0, placer,
|
||||
placement().rotation(ObjectRotation.of(0, 0, 0)).build(), new RNG(2L), null, null, data);
|
||||
|
||||
assertEquals(Optional.of("native-structure"), result.rejection());
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collisionRejectionPrecedesBoreAndAllowedObjectsOverrideForbiddenOnes() {
|
||||
PlacedObject forbidden = new PlacedObject(object("forbidden"), 1, 0, 0);
|
||||
@@ -675,10 +735,21 @@ public class ObjectPlacementRegressionTest {
|
||||
}
|
||||
|
||||
/** The height {@code object} was placed at, or -1 when the placement rejected it. */
|
||||
private static int placedAutomatic(IrisObject object, int x, int z, IObjectPlacer placer, ObjectPlacement config, RNG rng, IrisData data) {
|
||||
return ModuleObjectPlacement.placeAutomatic(object, x, z, placer, config, rng, null, null, data).heightOrRejected();
|
||||
}
|
||||
|
||||
private static int placed(IrisObject object, int x, int y, int z, IObjectPlacer placer, ObjectPlacement config, RNG rng, IrisData data) {
|
||||
return ModuleObjectPlacement.place(object, x, y, z, placer, config, rng, null, null, data).heightOrRejected();
|
||||
}
|
||||
|
||||
private ObjectPlacementResult place(ObjectPlacement.Builder config, boolean automatic, RecordingPlacer placer, CarveResult cave) {
|
||||
if (automatic) {
|
||||
return ModuleObjectPlacement.placeAutomatic(lineObject(1), 0, 0, placer, config.build(), new RNG(2L), null, cave, data);
|
||||
}
|
||||
return place(config, ANCHOR_Y, placer, cave);
|
||||
}
|
||||
|
||||
private ObjectPlacementResult place(ObjectPlacement.Builder config, int y, RecordingPlacer placer, CarveResult cave) {
|
||||
return ModuleObjectPlacement.place(lineObject(1), 0, y, 0, placer, config.build(), new RNG(2L), null, cave, data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import org.junit.Test;
|
||||
|
||||
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.TimeoutException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class IrisObjectCopyTest {
|
||||
private static final long WAIT_SECONDS = 5;
|
||||
private static final long BLOCKED_PROBE_MILLIS = 150;
|
||||
|
||||
@Test
|
||||
public void copyWaitsForVolumeMutationToComplete() throws Exception {
|
||||
IrisObject source = new IrisObject(1, 1, 1);
|
||||
PlatformBlockState block = mock(PlatformBlockState.class);
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
source.writeLock.lock();
|
||||
Future<IrisObject> result;
|
||||
try {
|
||||
result = executor.submit(() -> {
|
||||
started.countDown();
|
||||
return source.copy();
|
||||
});
|
||||
assertTrue(started.await(WAIT_SECONDS, TimeUnit.SECONDS));
|
||||
assertThrows(TimeoutException.class, () -> result.get(BLOCKED_PROBE_MILLIS, TimeUnit.MILLISECONDS));
|
||||
source.setW(3);
|
||||
source.setCenter(new Vector3i(1, 0, 0));
|
||||
source.setUnsigned(2, 0, 0, block);
|
||||
} finally {
|
||||
source.writeLock.unlock();
|
||||
}
|
||||
|
||||
IrisObject copy = result.get(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
assertEquals(3, copy.getW());
|
||||
assertEquals(new Vector3i(1, 0, 0), copy.getCenter());
|
||||
assertSame(block, copy.getBlocks().get(new IrisBlockVector(1, 0, 0)));
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyOwnsItsCenterAndTiles() {
|
||||
IrisObject source = new IrisObject(1, 1, 1);
|
||||
PlatformBlockState block = mock(PlatformBlockState.class);
|
||||
TileData tile = new TileData("minecraft:chest", new KMap<>());
|
||||
tile.getProperties().put("name", "source");
|
||||
source.setUnsigned(0, 0, 0, block);
|
||||
source.setUnsignedTile(0, 0, 0, tile);
|
||||
|
||||
IrisObject copy = source.copy();
|
||||
IrisBlockVector position = new IrisBlockVector(0, 0, 0);
|
||||
TileData copiedTile = copy.getStates().get(position);
|
||||
assertNotSame(source.getCenter(), copy.getCenter());
|
||||
assertNotSame(tile, copiedTile);
|
||||
assertNotSame(tile.getProperties(), copiedTile.getProperties());
|
||||
copiedTile.getProperties().put("name", "copy");
|
||||
copy.getBlocks().remove(position);
|
||||
|
||||
assertEquals("source", tile.getProperties().get("name"));
|
||||
assertSame(block, source.getBlocks().get(position));
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import com.volmit.object.ScaleMethod;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Rotation drops blocks with no valid orientation and their tiles; scaling reads one snapshot of the object. */
|
||||
public class IrisObjectTransformsStabilityTest {
|
||||
private static final long WAIT_SECONDS = 5;
|
||||
private static final long PARK_MILLIS = 1;
|
||||
private static final int QUARTER_TURN_DEGREES = 90;
|
||||
private static final double SCALE = 2;
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(registries.block(anyString())).thenAnswer(call -> state(call.getArgument(0)));
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rotationOmitsUnsupportedBlocksAndTheirTiles() {
|
||||
IrisObject source = new IrisObject(3, 1, 1);
|
||||
PlatformBlockState unsupported = state("minecraft:wall_torch");
|
||||
PlatformBlockState chest = state("minecraft:chest");
|
||||
source.setUnsigned(0, 0, 0, unsupported);
|
||||
source.setUnsignedTile(0, 0, 0, tile("minecraft:wall_torch", "omitted"));
|
||||
source.setUnsigned(1, 0, 0, chest);
|
||||
source.setUnsignedTile(1, 0, 0, tile("minecraft:chest", "kept"));
|
||||
source.setUnsigned(2, 0, 0, state("minecraft:stone"));
|
||||
BlockStateRotation.StateRotator previous = BlockStateRotation.bindPlatformRotator(
|
||||
(turn, block) -> block == unsupported ? null : block);
|
||||
IrisObject rotated;
|
||||
try {
|
||||
rotated = source.rotateCopy(ObjectTurn.of(0, QUARTER_TURN_DEGREES, 0));
|
||||
} finally {
|
||||
BlockStateRotation.restorePlatformRotator(previous);
|
||||
}
|
||||
|
||||
assertEquals(2, rotated.getBlocks().size());
|
||||
assertEquals(1, rotated.getStates().size());
|
||||
rotated.getStates().forEach(entry -> {
|
||||
assertEquals(chest, rotated.getBlocks().get(entry.getKey()));
|
||||
assertEquals("kept", entry.getValue().getProperties().get("name"));
|
||||
});
|
||||
assertEquals(3, source.getBlocks().size());
|
||||
assertEquals(2, source.getStates().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalingWaitsForMatchingGeometryAndVolume() throws Exception {
|
||||
IrisObject source = new IrisObject(9, 5, 3);
|
||||
source.setUnsigned(0, 0, 0, state("minecraft:stone"));
|
||||
FutureTask<IrisObject> scaling = new FutureTask<>(() -> source.scaled(SCALE, ScaleMethod.NONE));
|
||||
Thread worker = new Thread(scaling, "object-scaling-snapshot");
|
||||
source.writeLock.lock();
|
||||
try {
|
||||
worker.start();
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(WAIT_SECONDS);
|
||||
while (worker.getState() != Thread.State.WAITING && System.nanoTime() < deadline) {
|
||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(PARK_MILLIS));
|
||||
}
|
||||
assertEquals(Thread.State.WAITING, worker.getState());
|
||||
source.setW(2);
|
||||
source.setH(2);
|
||||
source.setD(2);
|
||||
source.setCenter(new Vector3i(1, 1, 1));
|
||||
source.getBlocks().clear();
|
||||
source.setUnsigned(0, 0, 0, state("minecraft:chest"));
|
||||
} finally {
|
||||
source.writeLock.unlock();
|
||||
}
|
||||
try {
|
||||
IrisObject actual = scaling.get(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
IrisObject expected = source.scaled(SCALE, ScaleMethod.NONE);
|
||||
|
||||
assertEquals(expected.getW(), actual.getW());
|
||||
assertEquals(expected.getH(), actual.getH());
|
||||
assertEquals(expected.getD(), actual.getD());
|
||||
assertEquals(expected.getBlocks().size(), actual.getBlocks().size());
|
||||
expected.getBlocks().forEach(entry -> {
|
||||
assertNotNull(actual.getBlocks().get(entry.getKey()));
|
||||
assertEquals(entry.getValue(), actual.getBlocks().get(entry.getKey()));
|
||||
});
|
||||
} finally {
|
||||
worker.interrupt();
|
||||
worker.join(TimeUnit.SECONDS.toMillis(WAIT_SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
private static PlatformBlockState state(String key) {
|
||||
PlatformBlockState state = mock(PlatformBlockState.class);
|
||||
when(state.key()).thenReturn(key);
|
||||
when(state.materialKey()).thenReturn(key);
|
||||
when(state.isAir()).thenReturn(false);
|
||||
when(state.isSolid()).thenReturn(true);
|
||||
return state;
|
||||
}
|
||||
|
||||
private static TileData tile(String id, String name) {
|
||||
TileData tile = new TileData(id, new KMap<>());
|
||||
tile.getProperties().put("name", name);
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -190,7 +190,7 @@ public class NativeStructureObjectVetoTest {
|
||||
volumes(volume(-64, -64, -64, 64, 320, 64));
|
||||
ObjectPlacement placement = placement().toBuilder().forcePlace(true).build();
|
||||
|
||||
assertEquals(-1, placed(0, -1, placer, placement));
|
||||
assertEquals(-1, placedAutomatic(0, placer, placement));
|
||||
assertTrue(placer.written().isEmpty());
|
||||
}
|
||||
|
||||
@@ -229,7 +229,11 @@ public class NativeStructureObjectVetoTest {
|
||||
}
|
||||
|
||||
private int place(RecordingPlacer placer) {
|
||||
return placed(0, -1, placer, placement());
|
||||
return placedAutomatic(0, placer, placement());
|
||||
}
|
||||
|
||||
private int placedAutomatic(int x, RecordingPlacer placer, ObjectPlacement config) {
|
||||
return ModuleObjectPlacement.placeAutomatic(tree(), x, 0, placer, config, new RNG(1234L), null, null, data).heightOrRejected();
|
||||
}
|
||||
|
||||
private int placed(int x, int y, RecordingPlacer placer, ObjectPlacement config) {
|
||||
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
package art.arcane.iris.engine.platform;
|
||||
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.core.service.ExternalDataSVC;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.util.common.data.IrisCustomData;
|
||||
import art.arcane.iris.util.project.matter.TileWrapper;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.function.Consumer4;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class EngineBukkitOpsStaleRecordTest {
|
||||
private static final Identifier ORE = Identifier.fromString("itemsadder:forest/amber_ore");
|
||||
private static final Identifier CHAIR = Identifier.fromString("craftengine:test/chair[variant=alpha]");
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(registries.block(anyString())).thenReturn(mock(PlatformBlockState.class));
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customRecordOverFlattenedAirIsNotPlaced() {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.carrier(ORE, Material.NOTE_BLOCK);
|
||||
Block flattened = fixture.block(1, 10, 1, Material.AIR);
|
||||
MantleChunk<Matter> records = customRecords(new Placed<>(1, 10, 1, ORE));
|
||||
|
||||
fixture.materializeCustomBlocks(records);
|
||||
|
||||
verify(fixture.service, never()).processUpdate(any(), eq(flattened), any());
|
||||
verify(records).deleteSlices(Identifier.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customRecordOverReplacedBlockIsNotPlaced() {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.carrier(ORE, Material.NOTE_BLOCK);
|
||||
Block wall = fixture.block(2, 10, 2, Material.COBBLESTONE);
|
||||
MantleChunk<Matter> records = customRecords(new Placed<>(2, 10, 2, ORE));
|
||||
|
||||
fixture.materializeCustomBlocks(records);
|
||||
|
||||
verify(fixture.service, never()).processUpdate(any(), eq(wall), any());
|
||||
verify(records).deleteSlices(Identifier.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customRecordOverIntactCarrierIsPlaced() {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.carrier(ORE, Material.NOTE_BLOCK);
|
||||
Block intact = fixture.block(3, 10, 3, Material.NOTE_BLOCK);
|
||||
|
||||
fixture.materializeCustomBlocks(customRecords(new Placed<>(3, 10, 3, ORE)));
|
||||
|
||||
verify(fixture.service).processUpdate(fixture.engine, intact, ORE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void airCarrierFurnitureRecordIsPlacedWhateverTheLiveBlock() {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.carrier(CHAIR, Material.AIR);
|
||||
Block open = fixture.block(4, 10, 4, Material.AIR);
|
||||
Block covered = fixture.block(5, 10, 5, Material.COBBLESTONE);
|
||||
|
||||
fixture.materializeCustomBlocks(customRecords(
|
||||
new Placed<>(4, 10, 4, CHAIR),
|
||||
new Placed<>(5, 10, 5, CHAIR)));
|
||||
|
||||
verify(fixture.service).processUpdate(fixture.engine, open, CHAIR);
|
||||
verify(fixture.service).processUpdate(fixture.engine, covered, CHAIR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unresolvableCarrierLeavesPlacementToTheProvider() {
|
||||
Fixture fixture = new Fixture();
|
||||
when(fixture.service.getBlockData(ORE)).thenReturn(Optional.empty());
|
||||
Block block = fixture.block(6, 10, 6, Material.STONE);
|
||||
|
||||
fixture.materializeCustomBlocks(customRecords(new Placed<>(6, 10, 6, ORE)));
|
||||
|
||||
verify(fixture.service).processUpdate(fixture.engine, block, ORE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void carrierResolvesOncePerIdentifierAndStaleRecordsLogOncePerChunk() {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.carrier(ORE, Material.NOTE_BLOCK);
|
||||
fixture.block(1, 10, 1, Material.AIR);
|
||||
fixture.block(2, 10, 2, Material.COBBLESTONE);
|
||||
Block intact = fixture.block(3, 10, 3, Material.NOTE_BLOCK);
|
||||
MantleChunk<Matter> records = customRecords(
|
||||
new Placed<>(1, 10, 1, ORE),
|
||||
new Placed<>(2, 10, 2, ORE),
|
||||
new Placed<>(3, 10, 3, ORE));
|
||||
|
||||
List<String> debug = fixture.materializeCustomBlocksCapturingDebug(records);
|
||||
|
||||
verify(fixture.service, times(1)).getBlockData(ORE);
|
||||
verify(fixture.service, times(1)).processUpdate(any(), any(), any());
|
||||
verify(fixture.service).processUpdate(fixture.engine, intact, ORE);
|
||||
assertEquals(1, debug.size());
|
||||
assertTrue(debug.getFirst(), debug.getFirst().contains("2 stale"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staleTileRecordIsSkippedWithoutWarning() {
|
||||
Fixture fixture = new Fixture();
|
||||
TileData chest = chestTile();
|
||||
Block replaced = fixture.block(7, 10, 7, Material.STONE);
|
||||
BlockData stone = blockData(Material.STONE);
|
||||
when(replaced.getBlockData()).thenReturn(stone);
|
||||
|
||||
try (MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
EngineBukkitOps.materializeTiles(fixture.engine, fixture.chunk, tileRecords(new Placed<>(7, 10, 7, chest)));
|
||||
|
||||
logging.verify(() -> IrisLogging.warn(anyString(), any(Object[].class)), never());
|
||||
logging.verify(() -> IrisLogging.debug(anyString(), any(Object[].class)), times(1));
|
||||
}
|
||||
verify(chest, never()).toBukkitTry(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intactTileRecordIsApplied() {
|
||||
Fixture fixture = new Fixture();
|
||||
TileData chest = chestTile();
|
||||
Block intact = fixture.block(8, 10, 8, Material.CHEST);
|
||||
BlockData chestData = blockData(Material.CHEST);
|
||||
when(intact.getBlockData()).thenReturn(chestData);
|
||||
when(intact.getState()).thenReturn(mock(TileState.class));
|
||||
doReturn(true).when(chest).toBukkitTry(intact);
|
||||
|
||||
try (MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
EngineBukkitOps.materializeTiles(fixture.engine, fixture.chunk, tileRecords(new Placed<>(8, 10, 8, chest)));
|
||||
|
||||
logging.verify(() -> IrisLogging.warn(anyString(), any(Object[].class)), never());
|
||||
}
|
||||
verify(chest).toBukkitTry(intact);
|
||||
}
|
||||
|
||||
private static TileData chestTile() {
|
||||
TileData tile = spy(new TileData("minecraft:chest", new KMap<>()));
|
||||
doReturn(Material.CHEST).when(tile).resolveMaterial();
|
||||
return tile;
|
||||
}
|
||||
|
||||
private static BlockData blockData(Material material) {
|
||||
BlockData data = mock(BlockData.class);
|
||||
when(data.getMaterial()).thenReturn(material);
|
||||
return data;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static MantleChunk<Matter> customRecords(Placed<Identifier>... records) {
|
||||
return records(Identifier.class, records);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static MantleChunk<Matter> tileRecords(Placed<TileData>... records) {
|
||||
List<Placed<TileWrapper>> wrapped = new ArrayList<>(records.length);
|
||||
for (Placed<TileData> record : records) {
|
||||
wrapped.add(new Placed<>(record.x(), record.y(), record.z(), new TileWrapper(record.value())));
|
||||
}
|
||||
return records(TileWrapper.class, wrapped.toArray(Placed[]::new));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> MantleChunk<Matter> records(Class<T> type, Placed<T>[] records) {
|
||||
MantleChunk<Matter> chunk = mock(MantleChunk.class);
|
||||
doAnswer((InvocationOnMock invocation) -> {
|
||||
Consumer4<Integer, Integer, Integer, T> iterator = invocation.getArgument(1);
|
||||
for (Placed<T> record : records) {
|
||||
iterator.accept(record.x(), record.y(), record.z(), record.value());
|
||||
}
|
||||
return null;
|
||||
}).when(chunk).iterate(eq(type), any());
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private record Placed<T>(int x, int y, int z, T value) {
|
||||
}
|
||||
|
||||
private static final class Fixture {
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final Chunk chunk = mock(Chunk.class);
|
||||
private final ExternalDataSVC service = mock(ExternalDataSVC.class);
|
||||
|
||||
private Fixture() {
|
||||
IrisWorld irisWorld = mock(IrisWorld.class);
|
||||
when(engine.getWorld()).thenReturn(irisWorld);
|
||||
World world = mock(World.class);
|
||||
when(world.getMinHeight()).thenReturn(0);
|
||||
when(world.getMaxHeight()).thenReturn(256);
|
||||
when(world.getName()).thenReturn("example");
|
||||
when(chunk.getWorld()).thenReturn(world);
|
||||
}
|
||||
|
||||
private void carrier(Identifier identifier, Material material) {
|
||||
BlockData carrier = IrisCustomData.of(blockData(material), identifier);
|
||||
when(service.getBlockData(identifier)).thenReturn(Optional.of(carrier));
|
||||
}
|
||||
|
||||
private Block block(int x, int y, int z, Material type) {
|
||||
Block block = mock(Block.class);
|
||||
when(block.getType()).thenReturn(type);
|
||||
when(chunk.getBlock(x, y, z)).thenReturn(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
private void materializeCustomBlocks(MantleChunk<Matter> records) {
|
||||
try (MockedStatic<IrisServices> services = mockStatic(IrisServices.class)) {
|
||||
services.when(() -> IrisServices.get(ExternalDataSVC.class)).thenReturn(service);
|
||||
EngineBukkitOps.materializeCustomBlocks(engine, chunk, records);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> materializeCustomBlocksCapturingDebug(MantleChunk<Matter> records) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
try (MockedStatic<IrisServices> services = mockStatic(IrisServices.class);
|
||||
MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
services.when(() -> IrisServices.get(ExternalDataSVC.class)).thenReturn(service);
|
||||
logging.when(() -> IrisLogging.debug(anyString(), any(Object[].class))).thenAnswer((InvocationOnMock invocation) -> {
|
||||
Object[] arguments = invocation.getArguments();
|
||||
messages.add(String.format((String) arguments[0], Arrays.copyOfRange(arguments, 1, arguments.length)));
|
||||
return null;
|
||||
});
|
||||
EngineBukkitOps.materializeCustomBlocks(engine, chunk, records);
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user