ProtocolLib

3M Downloads

Entity Equipment reading and updating

Jakush opened this issue ยท 1 comments

commented

Hello, I am trying to make a listener to ENTITY_EQUIPMENT packet, where if it is head, I want to change its itemstack to mine.

API method(s) used
addPacketListener and onPacketSending in PacketAdapter

Expected behavior
I should be able to read the packet (and its itemstack)

Code
`@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
player.sendMessage("Entity Equipment packet sending");

if (statement) {
PacketContainer packet = event.getPacket();
StructureModifier<List<Pair<EnumWrappers.ItemSlot, ItemStack>>> structure = packet.getSlotStackPairLists();
List<Pair<EnumWrappers.ItemSlot, ItemStack>> list = structure.read(0);
player.sendMessage("Structure " + structure.toString());
player.sendMessage("List " + list.toString());

  ImmutableList.copyOf(list).forEach(pair -> {
	  EnumWrappers.ItemSlot itemSlot = pair.getFirst();

	  if (itemSlot != EnumWrappers.ItemSlot.HEAD)
		  return;

	  list.remove(pair);
	  list.add(new Pair<>(EnumWrappers.ItemSlot.HEAD, my itemstack));
  });
  structure.write(0, list);

}
}`

Although I end up getting exception Field index 0 is out of bounds for length 0
....
Parameters:
net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment@4bf85c2d[
a=130
b=4
c=1xitem.helmetDiamond@0
]

commented

I used for getting slot (packet.getIntegers().read(1);) and for setting itemstack (packet.getItemModifier().write(0, itemstack);)