Send item pickup animation
iGabyTM 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
I want do play the item pickup animation to the player. I have checked the minecraft code (net.minecraft.network.protocol.game.ServerboundPickItemPacket
) and there's only one field for the slot where the item will go but on wiki there are 3 fields which makes sense because you would have to specify all these information, right?
API method(s) used
List what API method(s) you're using
Expected behavior
Send the animation with the given item and amount.
Code
final PacketContainer packet = new PacketContainer(PacketType.Play.Client.PICK_ITEM);
packet.getIntegers()
.write(0, itemToPickup.getEntityId())
.write(1, player.getEntityId())
.write(2, amountLeft);
Additional context
com.comphenix.protocol.reflect.FieldAccessException: Field index out of bounds. (Index: 1, Size: 1)
Looks like I was looking at the wrong packet, I should have compared the packet ids instead of guess it by name.
This is the code that I had to use.
final PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getIntegerArrays().write(0, new int[] {itemToPickup.getEntityId(), player.getEntityId(), amountLeft});
try {
protocol.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Now I have a weird issue, after playing the packed I can't do anything unless I rejoin, any idea why? Looks like the item glitches somehow between my inventory and the ground.