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)));
}
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());
}
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.");
}
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.");
}
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);
}
}
}
Aggregations