From 76432f9d3674b1186674af0081e38d2e04a053ea Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Wed, 5 Jun 2024 22:46:20 -0500 Subject: [PATCH] Well, it works for Mojang mapped anyways --- .../com/comphenix/protocol/PacketType.java | 5 +- .../wrappers/WrappedDataWatcherTest.java | 52 +++++++++---------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/comphenix/protocol/PacketType.java b/src/main/java/com/comphenix/protocol/PacketType.java index ed4d6c0b0..e690dc971 100644 --- a/src/main/java/com/comphenix/protocol/PacketType.java +++ b/src/main/java/com/comphenix/protocol/PacketType.java @@ -26,7 +26,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Iterables; - /** * Represents the type of a packet in a specific protocol. *

@@ -478,8 +477,8 @@ public static class Client extends PacketTypeEnum { public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x35, "SignUpdate", "UpdateSign", "CPacketUpdateSign"); public static final PacketType ARM_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x36, "Swing", "ArmAnimation", "CPacketAnimation"); public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x37, "TeleportToEntity", "Spectate", "CPacketSpectate"); - public static final PacketType USE_ITEM = new PacketType(PROTOCOL, SENDER, 0x38, "UseItemOn", "CPacketPlayerTryUseItemOnBlock"); - public static final PacketType BLOCK_PLACE = new PacketType(PROTOCOL, SENDER, 0x39, "UseItem", "BlockPlace", "CPacketPlayerTryUseItem"); + public static final PacketType USE_ITEM = new PacketType(PROTOCOL, SENDER, 0x38, "UseItemOn", "UseItem", "CPacketPlayerTryUseItemOnBlock"); + public static final PacketType BLOCK_PLACE = new PacketType(PROTOCOL, SENDER, 0x39, "BlockPlace", "CPacketPlayerTryUseItem"); /** * @deprecated Removed in 1.17 diff --git a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java index 8fe68050a..4769d5ef3 100644 --- a/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java +++ b/src/test/java/com/comphenix/protocol/wrappers/WrappedDataWatcherTest.java @@ -18,9 +18,11 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; + import net.minecraft.world.entity.projectile.EntityEgg; import org.bukkit.craftbukkit.v1_20_R4.entity.CraftEgg; import org.bukkit.craftbukkit.v1_20_R4.entity.CraftEntity; +import org.bukkit.entity.Entity; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -33,46 +35,47 @@ * @author dmulloy2 */ public class WrappedDataWatcherTest { + private static Entity mockEntity; @BeforeAll public static void prepare() { BukkitInitialization.initializeAll(); + + EntityEgg nmsEgg = new EntityEgg(null, 0, 0, 0); + mockEntity = new CraftEgg(null, nmsEgg); } @Test - @Disabled // TODO -- need to fix data watchers + @Disabled // TODO -- SETTER is null public void testBytes() { - // Create a fake lightning strike and get its watcher - EntityEgg nmsEgg = new EntityEgg(null, 0, 0, 0); - CraftEntity craftEgg = new CraftEgg(null, nmsEgg); - WrappedDataWatcher wrapper = WrappedDataWatcher.getEntityWatcher(craftEgg); + WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(mockEntity); - WrappedWatchableObject watchable = wrapper.getWatchableObject(0); + WrappedWatchableObject watchable = watcher.getWatchableObject(0); WrappedDataWatcherObject object = watchable.getWatcherObject(); // Make sure the serializers work assertEquals(object.getSerializer(), Registry.get(Byte.class)); // Make sure we can set existing objects - wrapper.setObject(0, (byte) 21); - assertEquals(21, (byte) wrapper.getByte(0)); + watcher.setObject(0, (byte) 21); + assertEquals(21, (byte) watcher.getByte(0)); } @Test - @Disabled // TODO -- need to fix data watchers + @Disabled // TODO -- SETTER is null public void testStrings() { - WrappedDataWatcher wrapper = new WrappedDataWatcher(); + WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(mockEntity); // Make sure we can create watcher objects Serializer serializer = Registry.get(String.class); WrappedDataWatcherObject object = new WrappedDataWatcherObject(3, serializer); - wrapper.setObject(object, "Test"); + watcher.setObject(object, "Test"); - assertEquals(wrapper.getString(3), "Test"); + assertEquals(watcher.getString(3), "Test"); } @Test - @Disabled // TODO -- need to fix data watchers + @Disabled // TODO -- need a better example for floats public void testFloats() { WrappedDataWatcher wrapper = new WrappedDataWatcher(); @@ -85,35 +88,28 @@ public void testFloats() { } @Test - @Disabled // TODO -- need to fix data watchers public void testSerializers() { Serializer blockPos = Registry.get(net.minecraft.core.BlockPosition.class, false); Serializer optionalBlockPos = Registry.get(net.minecraft.core.BlockPosition.class, true); assertNotSame(blockPos, optionalBlockPos); - // assertNull(Registry.get(ItemStack.class, false)); + // assertNull(Registry.get(ItemStack.class, false)); // TODO assertNotNull(Registry.get(UUID.class, true)); } @Test - @Disabled // TODO -- need to fix data watchers public void testHasIndex() { - WrappedDataWatcher watcher = new WrappedDataWatcher(); - Serializer serializer = Registry.get(Integer.class); - - assertFalse(watcher.hasIndex(0)); - watcher.setObject(0, serializer, 1); - assertTrue(watcher.hasIndex(0)); + WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(mockEntity); + assertTrue(watcher.hasIndex(1)); + assertFalse(watcher.hasIndex(9999)); } @Test - @Disabled // TODO -- need to fix data watchers public void testDeepClone() { - WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, Registry.get(Integer.class), 1); - + WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(mockEntity); WrappedDataWatcher cloned = watcher.deepClone(); - assertEquals(1, cloned.asMap().size()); - assertEquals(1, (Object) cloned.getInteger(0)); + + assertEquals(watcher.size(), cloned.size()); + assertEquals(watcher.getObject(1), cloned.getObject(1)); } }