Search in sources :

Example 31 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class SpongeAABBTest method testContainsVector3d.

@Test
void testContainsVector3d() {
    final AABB aabb = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    Assertions.assertTrue(aabb.contains(new Vector3d(5, 3, 11)));
    Assertions.assertFalse(aabb.contains(new Vector3d(-1, 3, 11)));
    Assertions.assertFalse(aabb.contains(new Vector3d(5, 11, 11)));
    Assertions.assertFalse(aabb.contains(new Vector3d(5, 3, 14)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 32 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class SpongeAABBTest method testCenter.

@Test
void testCenter() {
    final AABB aabb = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    Assertions.assertEquals(new Vector3d(4, 6, 8), aabb.center());
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 33 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class TransformationTest method testTranslationOnly.

@ParameterizedTest
@MethodSource
void testTranslationOnly(final Vector3d original, final Vector3d expected) {
    // given this builder
    final SpongeTransformationBuilder transformationBuilder = TransformationTest.createZeroBuilder();
    // when translating by (1,1,1)
    final Transformation transformation = transformationBuilder.translate(Vector3d.ONE).build();
    // then perform the transformation
    final Vector3d result = transformation.transformPosition(original);
    Assertions.assertEquals(expected, result, "Did not get expected rotation.");
}
Also used : Transformation(org.spongepowered.api.util.transformation.Transformation) Vector3d(org.spongepowered.math.vector.Vector3d) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 34 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class TransformationTest method testMirrorInXDirection.

@ParameterizedTest
@MethodSource
void testMirrorInXDirection(final Vector3d original, final Vector3d expected) {
    // given this builder
    final SpongeTransformationBuilder transformationBuilder = TransformationTest.createZeroBuilder();
    // when rotating by 90 degrees
    final Transformation transformation = transformationBuilder.mirror(Axis.X).build();
    // then perform the transformation
    final Vector3d result = transformation.transformPosition(original);
    Assertions.assertEquals(expected, result, "Did not get expected mirroring.");
    Assertions.assertTrue(transformation.mirror(Axis.X), "Did not get X axis was mirrored.");
    Assertions.assertFalse(transformation.mirror(Axis.Z), "Did not get Z axis was not mirrored.");
}
Also used : Transformation(org.spongepowered.api.util.transformation.Transformation) Vector3d(org.spongepowered.math.vector.Vector3d) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 35 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method teleportTo.

/*
    @Inject(method = "markPlayerActive()V", at = @At("HEAD"))
    private void impl$onPlayerActive(final CallbackInfo ci) {
        ((ServerPlayNetHandlerBridge) this.connection).bridge$resendLatestResourcePackRequest();
    }
*/
/**
 * @author zidane - November 21st, 2020 - Minecraft 1.15
 * @reason Ensure that the teleport hook honors our events
 */
@Overwrite
public void teleportTo(final net.minecraft.server.level.ServerLevel world, final double x, final double y, final double z, final float yaw, final float pitch) {
    final net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer) (Object) this;
    double actualX = x;
    double actualY = y;
    double actualZ = z;
    double actualYaw = yaw;
    double actualPitch = pitch;
    final boolean hasMovementContext = PhaseTracker.getCauseStackManager().currentContext().containsKey(EventContextKeys.MOVEMENT_TYPE);
    try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
        if (!hasMovementContext) {
            frame.addContext(EventContextKeys.MOVEMENT_TYPE, MovementTypes.PLUGIN);
        }
        if (world == player.level) {
            @Nullable final Vector3d destination = this.impl$fireMoveEvent(PhaseTracker.SERVER, new Vector3d(x, y, z));
            if (destination == null) {
                return;
            }
            actualX = destination.x();
            actualY = destination.y();
            actualZ = destination.z();
            if (ShouldFire.ROTATE_ENTITY_EVENT) {
                final RotateEntityEvent rotateEvent = SpongeEventFactory.createRotateEntityEvent(frame.currentCause(), (org.spongepowered.api.entity.Entity) player, new Vector3d(actualPitch, actualYaw, 0), new Vector3d(pitch, yaw, 0));
                SpongeCommon.post(rotateEvent);
                actualYaw = rotateEvent.isCancelled() ? player.yRot : rotateEvent.toRotation().y();
                actualPitch = rotateEvent.isCancelled() ? player.xRot : rotateEvent.toRotation().x();
            }
            this.shadow$setCamera(player);
            this.shadow$stopRiding();
            if (player.isSleeping()) {
                player.stopSleepInBed(true, true);
            }
            player.connection.teleport(actualX, actualY, actualZ, (float) actualYaw, (float) actualPitch);
            player.setYHeadRot((float) actualYaw);
            final ChunkPos chunkpos = new ChunkPos(new BlockPos(actualX, actualY, actualZ));
            world.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkpos, 1, player.getId());
        } else {
            final ChangeEntityWorldEvent.Pre preEvent = PlatformHooks.INSTANCE.getEventHooks().callChangeEntityWorldEventPre(player, world);
            if (SpongeCommon.post(preEvent)) {
                return;
            }
            if (ShouldFire.MOVE_ENTITY_EVENT) {
                final MoveEntityEvent posEvent = SpongeEventFactory.createChangeEntityWorldEventReposition(frame.currentCause(), (org.spongepowered.api.entity.Entity) player, preEvent.originalWorld(), VecHelper.toVector3d(player.position()), new Vector3d(x, y, z), preEvent.originalDestinationWorld(), new Vector3d(x, y, z), preEvent.destinationWorld());
                if (SpongeCommon.post(posEvent)) {
                    return;
                }
                actualX = posEvent.destinationPosition().x();
                actualY = posEvent.destinationPosition().y();
                actualZ = posEvent.destinationPosition().z();
            }
            this.shadow$setPos(actualX, actualY, actualZ);
            if (ShouldFire.ROTATE_ENTITY_EVENT) {
                final RotateEntityEvent rotateEvent = SpongeEventFactory.createRotateEntityEvent(frame.currentCause(), (org.spongepowered.api.entity.Entity) player, new Vector3d(actualYaw, actualPitch, 0), new Vector3d(yaw, pitch, 0));
                if (!SpongeCommon.post(rotateEvent)) {
                    actualYaw = (float) rotateEvent.toRotation().x();
                    actualPitch = (float) rotateEvent.toRotation().y();
                }
            }
            this.yRot = (float) actualYaw;
            this.xRot = (float) actualPitch;
            EntityUtil.performPostChangePlayerWorldLogic(player, (net.minecraft.server.level.ServerLevel) preEvent.originalWorld(), (net.minecraft.server.level.ServerLevel) preEvent.originalDestinationWorld(), (net.minecraft.server.level.ServerLevel) preEvent.destinationWorld(), false);
        }
    }
}
Also used : MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) ChangeEntityWorldEvent(org.spongepowered.api.event.entity.ChangeEntityWorldEvent) RotateEntityEvent(org.spongepowered.api.event.entity.RotateEntityEvent) Vector3d(org.spongepowered.math.vector.Vector3d) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Identity(net.kyori.adventure.identity.Identity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

Vector3d (org.spongepowered.math.vector.Vector3d)71 Vector3i (org.spongepowered.math.vector.Vector3i)16 CauseStackManager (org.spongepowered.api.event.CauseStackManager)14 AABB (org.spongepowered.api.util.AABB)14 Test (org.junit.jupiter.api.Test)13 ServerWorld (org.spongepowered.api.world.server.ServerWorld)13 BlockPos (net.minecraft.core.BlockPos)8 ServerLevel (net.minecraft.server.level.ServerLevel)7 BlockState (org.spongepowered.api.block.BlockState)7 Transformation (org.spongepowered.api.util.transformation.Transformation)7 Function (java.util.function.Function)6 IntStream (java.util.stream.IntStream)6 Stream (java.util.stream.Stream)6 Entity (org.spongepowered.api.entity.Entity)6 MoveEntityEvent (org.spongepowered.api.event.entity.MoveEntityEvent)6 ServerLocation (org.spongepowered.api.world.server.ServerLocation)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 BlockType (org.spongepowered.api.block.BlockType)5