use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class LevelChunkMixin_API method blockEntityStream.
@Override
public VolumeStream<WorldChunk, BlockEntity> blockEntityStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
VolumeStreamUtils.validateStreamArgs(Objects.requireNonNull(min, "min"), Objects.requireNonNull(max, "max"), Objects.requireNonNull(options, "options"));
final boolean shouldCarbonCopy = options.carbonCopy();
final Vector3i size = max.sub(min).add(1, 1, 1);
@MonotonicNonNull final ObjectArrayMutableBlockEntityBuffer backingVolume;
if (shouldCarbonCopy) {
backingVolume = new ObjectArrayMutableBlockEntityBuffer(min, size);
} else {
backingVolume = null;
}
return VolumeStreamUtils.<WorldChunk, BlockEntity, net.minecraft.world.level.block.entity.BlockEntity, ChunkAccess, BlockPos>generateStream(options, // Ref
(WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
this::impl$getBlockEntitiesStream, // IdentityFunction
VolumeStreamUtils.getBlockEntityOrCloneToBackingVolume(shouldCarbonCopy, backingVolume, this.level), // Biome by block position
(key, biome) -> key, // Filtered Position Entity Accessor
(blockPos, world) -> {
final net.minecraft.world.level.block.entity.@Nullable BlockEntity tileEntity = shouldCarbonCopy ? (net.minecraft.world.level.block.entity.BlockEntity) backingVolume.blockEntity(blockPos.getX(), blockPos.getY(), blockPos.getZ()).orElse(null) : ((LevelReader) world).getBlockEntity(blockPos);
return new Tuple<>(blockPos, tileEntity);
});
}
use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class SpongeAABBTest method testOffsetVector3i.
@Test
void testOffsetVector3i() {
final AABB aabb1 = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
final AABB aabb2 = new SpongeAABB(new Vector3d(11, 0, 4), new Vector3d(17, 8, 14));
Assertions.assertEquals(aabb2, aabb1.offset(new Vector3i(10, -2, 1)));
}
use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class SpongeAABBTest method testContainsVector3i.
@Test
void testContainsVector3i() {
final AABB aabb = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
Assertions.assertTrue(aabb.contains(new Vector3i(5, 3, 11)));
Assertions.assertFalse(aabb.contains(new Vector3i(-1, 3, 11)));
Assertions.assertFalse(aabb.contains(new Vector3i(5, 11, 11)));
Assertions.assertFalse(aabb.contains(new Vector3i(5, 3, 14)));
}
use of org.spongepowered.math.vector.Vector3i in project SpongeCommon by SpongePowered.
the class AbstractReferentArchetypeVolumeTest method testSizeTransformations.
private static Stream<Arguments> testSizeTransformations() {
final Rotation rotate0 = Mockito.mock(Rotation.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
final Rotation rotate90 = Mockito.mock(Rotation.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
Mockito.when(rotate0.angle()).thenReturn(Angle.fromDegrees(0));
Mockito.when(rotate90.angle()).thenReturn(Angle.fromDegrees(90));
return Stream.of(Arguments.of(new Vector3i(0, 0, 0), new Vector3i(1, 1, 1), new Vector3i(0, 0, 0), new Vector3i(1, 1, 1), new SpongeTransformationBuilder().rotate(rotate0).origin(new Vector3d(1, 0, 1)).build()), Arguments.of(new Vector3i(0, 0, 0), new Vector3i(1, 1, 1), new Vector3i(1, 0, 0), new Vector3i(0, 1, 1), new SpongeTransformationBuilder().rotate(rotate90).origin(new Vector3d(1, 1, 1)).build()), Arguments.of(new Vector3i(1, 1, 1), new Vector3i(2, 2, 2), new Vector3i(2, 1, 1), new Vector3i(1, 2, 2), new SpongeTransformationBuilder().rotate(rotate90).origin(new Vector3d(2, 2, 2)).build()), Arguments.of(new Vector3i(1, 1, 1), new Vector3i(5, 5, 5), new Vector3i(5, 1, 1), new Vector3i(1, 5, 5), new SpongeTransformationBuilder().rotate(rotate90).origin(new Vector3d(3.5, 3.5, 3.5)).build()));
}
Aggregations