[Discussion] Shoot hook rework proposal/ideas
See original GitHub issueDescription
This issue is related to ModPlayer.Shoot
and ModItem/GlobalItem.Shoot
and their behavior. Ill outline some of the issues of its current implementation and some proposed fixes.
Application Scope
Currently, both hooks are called in
else if (PlayerHooks.Shoot(this, item, ref vector, ref num70, ref num71, ref shoot, ref Damage, ref KnockBack)
&& ItemLoader.Shoot(item, this, ref vector, ref num70, ref num71, ref shoot, ref Damage, ref KnockBack)) {
which is at the very end of the chain relevant for all projectile spawning from item use. A big number of valid shooting items (I would say about 50%, other modders agree with this number) won’t ever enter this part of the code, making the hook useless if you want to detect projectiles being shot from items in a guaranteed manner. (Vanilla code is still inconsistent as to where it spawns projectiles sometimes, so it won’t be able to cover 100% of items anyway, but even 80% is better than 50%)
Possible fix would be to add another hook with no return value that simply executes when an item was used to shoot a projectile (Possible overlap with UseItem (which is also a bit inconsistent because of item.useStyle logic, but that’s another topic)).
General Use
The hooks return value (bool) indicates if the game should proceed spawning the projectile with the given parameters or not.
Modders use this hook to change the way projectiles are spawned, or just spawn new ones entirely. In combination with how the hooks are called (ModPlayer ones being split from the Item ones), this can cause shortcircuiting due to the &&
.
Possible fix would be to split up the logic into CanShoot
and Shoot
hooks. As for the shortcircuiting, change it to &
or combine it into one Loader
method.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Seems like the best solution to me.
but I bet someone wants to add custom firing logic, or extra projectiles, or something.
That’s very common (example: shotgun)What happens when someone wants to cancel vanilla logic, because they're handling it themselves, but some mods haven't had a chance to modify the the damage values?
I guess that’d need to become a diff hook