NeoForge icon indicating copy to clipboard operation
NeoForge copied to clipboard

ForgeHooks.getProjectile() assumes all instances of ProjectileWeaponItem use arrows as valid ammo

Open BrokenK3yboard opened this issue 1 year ago • 3 comments

Minecraft Version: 1.20.1

NeoForge Version: 47.1.64

Description of issue: ForgeHooks.getProjectile() inside of getProjectile() in Player.class naively assumes all instances of ProjectileWeaponItem use arrows as its ammo if no valid stack is found while the player is in creative mode. Returning ItemStack.EMPTY would prevent any cases where modded weapons are "finding" arrows in the player's inventory even if there is no valid itemstack.

The bow and crossbow handle this in their class level implementation so the proposed change should not affect anything else.

BrokenK3yboard avatar Jan 12 '24 02:01 BrokenK3yboard

For reference, the behavior within creative mode is from vanilla. Forge simply patches the hook to call the event while maintaining vanilla logic. Returning empty would be fine from a vanilla standpoint, but it might break mod logic if they choose to implement their own release logic. The better scenario is to allow people to specify the returned item stack on the ProjectileWeaponItem in some extension method imo.

ChampionAsh5357 avatar Jan 12 '24 03:01 ChampionAsh5357

That sounds fine, I've been using a similar approach in one of my mods with getDefaultAmmo() FirearmItem.java

BrokenK3yboard avatar Jan 14 '24 00:01 BrokenK3yboard

So if I am understanding this issue, the problem is using a modded projectile weapon in creative is being given vanilla arrows in getProjectile event right? But the weapon should be given an item that is a valid projectile for the weapon instead of the vanilla arrow as they may not accept the vanilla arrow.

Passing itemstack.EMPTY would make the event fire but say a modded weapon is firing no projectile when it is and passing that empty stack to the weapon itself.

TelepathicGrunt avatar May 17 '24 11:05 TelepathicGrunt