Skip to content
Sirawit Thaya edited this page Jun 22, 2021 · 3 revisions

Using bow and arrow is not as straight forward to implement as other items you use. This is because using the bow covers a whole sequence of packets, ultimately ending up with firing an arrow.

Bow

The sequence start with the client selecting a bow and using it. However, the UseItem message it will give you a face value of 255 instead of the usual 0-6. This is the same for all throwable items (snowball, egg, etc). At this point the server does not actually use the item, but rather juts sends the SetEntityData message to the client to start a bow animation.

When the bow fires, it will send a PlayerAction message to the server with an Action ID of 5. At this point, the server creates a new arrow entity and spawns it. It also sends another SetEntityData to complete the bow animation.

The datavalues for the SetEntityData to start the bow animation is metadata[0] = new MetadataByte(16). And to stop the animation it sends metadata[0] = new MetadataByte(0). Note that for the metadata at position 0, this also indicates other animations, like if the player is on fire, so take that in account when closing the bow animation.

Arrow

Arrow is a normal entity with a ballistic trajectory. It has three modes of force that can be applied. Low, medium and hard. These needs to be calculated based on the difference in time between receive of the initial bow use item and receive of the player action to end the sequence. This is well documented in the minecraft wiki.

The bounding box for arrow works best if height is set to 0. The bounding box also needs to be compensated in size to account for the speed of the arrow (otherwise it may miss targets on the way). This issue is most likely why it can be difficult to ignite an arrow when shooting through lava (glitch). Also notice that igniting an arrow in multiplayer does not play the fire-animation. That only seem to work for the local client where the arrow is shot.