Setting VillagerData
lewysDavies opened this issue · 2 comments
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
How do I use the WrappedVillagerData? Nothing I am trying is actually changing the Villager, or its profession. No errors, but not working. Entity ID is correct and is working with teleport, move etc etc. Just trying to get Professions & Types :)
API method(s) used
WrappedDataWatcher, WrappedDataWatcherObject, Registry, WrappedVillagerData, PacketContainer
Expected behavior
Villager data updated
Code
I have extracted the relevant stuff to make it easier and quicker :)
// Data watcher stuff
WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
WrappedDataWatcherObject dataWatcherObj = new WrappedDataWatcherObject(17,
Registry.get(WrappedVillagerData.getNmsClass()));
// Set villager data
WrappedVillagerData villagerData = WrappedVillagerData.fromValues(type, profession, 1);
dataWatcher.setObject(dataWatcherObj, villagerData.getHandle());
// Send update packet
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
metaPacket.getIntegers().write(0, entityId);
metaPacket.getWatchableCollectionModifier().write(0, dataWatcher.getWatchableObjects());
sendServerPacket(player, metaPacket);
Additional context
Running Paper 1.15.2 (recent v350), ProtocolLib 4.5.1
It is sending the Villager Data in index 17 😨
After more debugging, the code is doing what I expect it to and the error is on the client:
Error executing task on Client
java.lang.IllegalStateException: Invalid entity data item type for field
2 on entity axw['Villager'/280, l='MpServer', x=1211.10, y=79.00, z=493.75]:
old=Optional.empty(class java.util.Optional), new=(class java.lang.String)
Do you have any idea what I am missing to be causing this?