Check native structures against the real transformed object bounds

The native-structure veto used a square envelope of half the largest object side, so rotated or off-centre objects reaching past it were never checked. It now uses the prepared transformed bounds, with Y widened by the warp margin. IrisObject.copy() now reads under the read lock instead of the object monitor.

Upstream: d55c77572
This commit is contained in:
piexel committed 2026-11-10 01:00:40 +01:00
1 parent a81a3abb9f
commit 8e0e6d7d45
4 files changed
+140 -25

No files matched your search

@@ -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;
@@ -585,6 +586,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);
@@ -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));
}
}