ProtocolLib

3M Downloads

How to set the entity pose

moritzruth opened this issue · 2 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

Describe the question
I want to set the pose field (index 6) of the entity metadata of a fake player to 2 (SLEEPING). This is how I'm setting the metadata (I'm using Kotlin and PacketWrapper):

val wrapper = WrapperPlayServerEntityMetadata()
wrapper.entityID = ...

wrapper.metadata = listOf(
                WrappedWatchableObject(WrappedDataWatcher.WrappedDataWatcherObject(
                        6,
                        WrappedDataWatcher.Registry.get(Int::class.javaObjectType)
                ), 2)
        )

The Minecraft client throws this exception:

java.lang.IllegalStateException: Invalid entity data item type for field 6 on entity dqc[''/87, l='MpServer', x=31.00, y=69.00, z=53.00]: old=STANDING(class alj), new=2(class java.lang.Integer)
	at se.a(SourceFile:241) ~[minecraft-1.15.2-client.jar:?]
	at se.a(SourceFile:228) ~[minecraft-1.15.2-client.jar:?]
	at dnp.a(SourceFile:552) ~[minecraft-1.15.2-client.jar:?]
	at ok.a(SourceFile:42) ~[minecraft-1.15.2-client.jar:?]
	at ok.a(SourceFile:11) ~[minecraft-1.15.2-client.jar:?]
	at lv.a(SourceFile:21) ~[minecraft-1.15.2-client.jar:?]
	at ais.c(SourceFile:144) [minecraft-1.15.2-client.jar:?]
	at aiw.c(SourceFile:23) [minecraft-1.15.2-client.jar:?]
	at ais.w(SourceFile:118) [minecraft-1.15.2-client.jar:?]
	at ais.bk(SourceFile:103) [minecraft-1.15.2-client.jar:?]
	at dbn.d(SourceFile:956) [minecraft-1.15.2-client.jar:?]
	at dbn.d(SourceFile:619) [minecraft-1.15.2-client.jar:?]
	at net.minecraft.client.main.Main.main(SourceFile:204) [minecraft-1.15.2-client.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_191]
	at org.multimc.onesix.OneSixLauncher.launchWithMainClass(OneSixLauncher.java:196) [NewLaunch.jar:?]
	at org.multimc.onesix.OneSixLauncher.launch(OneSixLauncher.java:231) [NewLaunch.jar:?]
	at org.multimc.EntryPoint.listen(EntryPoint.java:143) [NewLaunch.jar:?]
	at org.multimc.EntryPoint.main(EntryPoint.java:34) [NewLaunch.jar:?]

It seems like it receives the VarInt value 2 as Integer. So how can I make it a VarInt?

Expected behavior
Let the fake player appear sleeping

Additional context
I'm using Spigot for 1.15.2

commented

It expects a Pose, not an int/varint (that's wire format, not what the packet class uses). I dont know how packet wrapper wraps enums, but you can't just write an int and expect it to work.

commented

I am no Protocol Lib expert, and I have no idea how to put it into Protocol Lib itself, However I have achieved this using:

public class WrapperEntityPose {
	private static final Class<?> POSE_ENUM = MinecraftReflection.getMinecraftClass("EntityPose");

	public static enum EntityPose {
		STANDING, FALL_FLYING, SLEEPING, SWIMMING, SPIN_ATTACK, CROUCHING, DYING;

		/**
		 * @return NMS Pose Enum
		 */
		public Object getHandle() {
			return POSE_ENUM.getEnumConstants()[this.ordinal()];
		}
	}
}
private final WrappedDataWatcherObject poseData = new WrappedDataWatcherObject(6, 
			Registry.get(MinecraftReflection.getMinecraftClass("EntityPose")));

private EntityPose pose = EntityPose.SLEEPING;
this.dataWatcher.setObject(this.poseData, this.pose.getHandle());

PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);

metaPacket.getIntegers().write(0, this.getEntityId());
metaPacket.getWatchableCollectionModifier().write(0, this.dataWatcher.getWatchableObjects());
try {
	protocol.sendServerPacket(player, metaPacket);
} catch (Exception e) {
		e.printStackTrace();
}

Results in:
image

Note: This is just the relevant snippit :P
Maybe @dmulloy2 could add a Pose enum wrapper?