Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by dolaking, Feb 13, 2019 at 7:45 PM.
How do you use different ammo for a bow? For example a certain bow uses tnt instead of arrows.
You must spawn the entity(TNT, etc.) and set velocity to entity.
I assume, you'd have to cancel everything regarding the arrow shoot, then spawn an arrow with the same velocity of the arrow you previously canceled. Then, you'd just have to remove 1 tnt from the inventory if any. An alternative would be to allow the consuption of the arrow but a tick later, add an arrow in the inventory but remove 1 tnt. That's what I came up with right now.
But that way the player would have to have arrows on him to no?
Ah indeed. Ignore what I said. Didn't think of it well enough.
Easiest way would probably to create a "TNT Arrow" sort of item stack and then detecting if a player has that type of arrow in their inventory when they shoot it.
If you don't want to rerquire the player to have an arrow, what you might be able to do is when the player right clicks with a bow, add an arrow to their inventory to make it so they can pull it back, and then when they shoot modify the arrow as needed.
To bandage the bow, you can check if the player is hold clicking with the bow and if he have a tnt in his inventory then, create a cooldown and add 1 durability to the bow. Then shoot the tnt when the player stop clicking like @Shin1gamiX said
Thanks for all the ideas guys, got it working
Well then, in that case, if they don't have any arrows you could check if they have the required ammo, for example tnt; if they have tnt:
- add an arrow to the users inventory to allow the pull of the bow (if they have no free space could probably just cache a substitution of an item in their inventory since this whole process will probably take less than 250ms)
- cancel the shooting, in EntityShootBowEvent, call #getForce() and combine the direction of the shooter, then force shoot off an alternative tnt projectile.
- then finally if applicable put the substituted item back in the inventory.