|
| 1 | +package com.comphenix.protocol.wrappers; |
| 2 | + |
| 3 | +import com.comphenix.protocol.BukkitInitialization; |
| 4 | +import com.comphenix.protocol.PacketType; |
| 5 | +import com.comphenix.protocol.events.PacketContainer; |
| 6 | + |
| 7 | +import org.bukkit.util.Vector; |
| 8 | +import org.junit.jupiter.api.BeforeAll; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | + |
| 11 | +import static org.junit.jupiter.api.Assertions.*; |
| 12 | + |
| 13 | +public class WrappedPositionMoveRotationTest { |
| 14 | + |
| 15 | + @BeforeAll |
| 16 | + public static void beforeClass() { |
| 17 | + BukkitInitialization.initializeAll(); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + public void testCreateAndRead() { |
| 22 | + Vector position = new Vector(1.5, 64.0, -3.5); |
| 23 | + Vector delta = new Vector(0.1, -0.05, 0.2); |
| 24 | + float yRot = 45.0f; |
| 25 | + float xRot = -10.0f; |
| 26 | + |
| 27 | + WrappedPositionMoveRotation created = WrappedPositionMoveRotation.create(position, delta, yRot, xRot); |
| 28 | + |
| 29 | + assertEquals(position.getX(), created.getPosition().getX(), 1e-6); |
| 30 | + assertEquals(position.getY(), created.getPosition().getY(), 1e-6); |
| 31 | + assertEquals(position.getZ(), created.getPosition().getZ(), 1e-6); |
| 32 | + |
| 33 | + assertEquals(delta.getX(), created.getDeltaMovement().getX(), 1e-6); |
| 34 | + assertEquals(delta.getY(), created.getDeltaMovement().getY(), 1e-6); |
| 35 | + assertEquals(delta.getZ(), created.getDeltaMovement().getZ(), 1e-6); |
| 36 | + |
| 37 | + assertEquals(yRot, created.getYRot(), 1e-6f); |
| 38 | + assertEquals(xRot, created.getXRot(), 1e-6f); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testEntityPositionSyncPacket() { |
| 43 | + PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_POSITION_SYNC); |
| 44 | + |
| 45 | + Vector position = new Vector(10.0, 70.0, -5.0); |
| 46 | + Vector delta = new Vector(0.0, 0.0, 0.0); |
| 47 | + float yRot = 90.0f; |
| 48 | + float xRot = 0.0f; |
| 49 | + |
| 50 | + packet.getPositionMoveRotation().write(0, |
| 51 | + WrappedPositionMoveRotation.create(position, delta, yRot, xRot)); |
| 52 | + |
| 53 | + WrappedPositionMoveRotation result = packet.getPositionMoveRotation().read(0); |
| 54 | + |
| 55 | + assertNotNull(result); |
| 56 | + |
| 57 | + assertEquals(position.getX(), result.getPosition().getX(), 1e-6); |
| 58 | + assertEquals(position.getY(), result.getPosition().getY(), 1e-6); |
| 59 | + assertEquals(position.getZ(), result.getPosition().getZ(), 1e-6); |
| 60 | + |
| 61 | + assertEquals(delta.getX(), result.getDeltaMovement().getX(), 1e-6); |
| 62 | + assertEquals(delta.getY(), result.getDeltaMovement().getY(), 1e-6); |
| 63 | + assertEquals(delta.getZ(), result.getDeltaMovement().getZ(), 1e-6); |
| 64 | + |
| 65 | + assertEquals(yRot, result.getYRot(), 1e-6f); |
| 66 | + assertEquals(xRot, result.getXRot(), 1e-6f); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testEntityTeleportPacket() { |
| 71 | + PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT); |
| 72 | + |
| 73 | + Vector position = new Vector(-100.5, 200.0, 300.75); |
| 74 | + Vector delta = new Vector(0.0, 0.0, 0.0); |
| 75 | + float yRot = 180.0f; |
| 76 | + float xRot = 30.0f; |
| 77 | + |
| 78 | + packet.getPositionMoveRotation().write(0, |
| 79 | + WrappedPositionMoveRotation.create(position, delta, yRot, xRot)); |
| 80 | + |
| 81 | + WrappedPositionMoveRotation result = packet.getPositionMoveRotation().read(0); |
| 82 | + |
| 83 | + assertNotNull(result); |
| 84 | + |
| 85 | + assertEquals(position.getX(), result.getPosition().getX(), 1e-6); |
| 86 | + assertEquals(position.getY(), result.getPosition().getY(), 1e-6); |
| 87 | + assertEquals(position.getZ(), result.getPosition().getZ(), 1e-6); |
| 88 | + |
| 89 | + assertEquals(delta.getX(), result.getDeltaMovement().getX(), 1e-6); |
| 90 | + assertEquals(delta.getY(), result.getDeltaMovement().getY(), 1e-6); |
| 91 | + assertEquals(delta.getZ(), result.getDeltaMovement().getZ(), 1e-6); |
| 92 | + |
| 93 | + assertEquals(yRot, result.getYRot(), 1e-6f); |
| 94 | + assertEquals(xRot, result.getXRot(), 1e-6f); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testFromHandle() { |
| 99 | + Vector position = new Vector(5.0, 65.0, 5.0); |
| 100 | + Vector delta = new Vector(0.0, -0.1, 0.0); |
| 101 | + float yRot = 270.0f; |
| 102 | + float xRot = -45.0f; |
| 103 | + |
| 104 | + WrappedPositionMoveRotation original = WrappedPositionMoveRotation.create(position, delta, yRot, xRot); |
| 105 | + WrappedPositionMoveRotation fromHandle = WrappedPositionMoveRotation.fromHandle(original.getHandle()); |
| 106 | + |
| 107 | + assertEquals(original.getPosition().getX(), fromHandle.getPosition().getX(), 1e-6); |
| 108 | + assertEquals(original.getPosition().getY(), fromHandle.getPosition().getY(), 1e-6); |
| 109 | + assertEquals(original.getPosition().getZ(), fromHandle.getPosition().getZ(), 1e-6); |
| 110 | + assertEquals(original.getYRot(), fromHandle.getYRot(), 1e-6f); |
| 111 | + assertEquals(original.getXRot(), fromHandle.getXRot(), 1e-6f); |
| 112 | + } |
| 113 | +} |
0 commit comments