Search in sources :

Example 56 with Vector3i

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);
    });
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Vector3i(org.spongepowered.math.vector.Vector3i) BlockPos(net.minecraft.core.BlockPos) ObjectArrayMutableBlockEntityBuffer(org.spongepowered.common.world.volume.buffer.blockentity.ObjectArrayMutableBlockEntityBuffer) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Tuple(net.minecraft.util.Tuple) BlockEntity(org.spongepowered.api.block.entity.BlockEntity)

Example 57 with Vector3i

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)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 58 with Vector3i

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)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 59 with Vector3i

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()));
}
Also used : SpongeTransformationBuilder(org.spongepowered.common.util.transformation.SpongeTransformationBuilder) Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) Rotation(org.spongepowered.api.util.rotation.Rotation)

Aggregations

Vector3i (org.spongepowered.math.vector.Vector3i)59 Vector3d (org.spongepowered.math.vector.Vector3d)22 Nullable (org.checkerframework.checker.nullness.qual.Nullable)15 BlockPos (net.minecraft.core.BlockPos)14 BlockState (org.spongepowered.api.block.BlockState)14 Stream (java.util.stream.Stream)13 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)12 StreamOptions (org.spongepowered.api.world.volume.stream.StreamOptions)12 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)11 VolumeElement (org.spongepowered.api.world.volume.stream.VolumeElement)11 Tuple (net.minecraft.util.Tuple)10 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)10 VolumeStream (org.spongepowered.api.world.volume.stream.VolumeStream)10 Function (java.util.function.Function)9 Biome (org.spongepowered.api.world.biome.Biome)9 Collection (java.util.Collection)8 Objects (java.util.Objects)8 Optional (java.util.Optional)8 UUID (java.util.UUID)8 Entity (org.spongepowered.api.entity.Entity)8