Jump to content

[1.19.2] Set ranged attack damage of bows and crossbows


SoLegendary

Recommended Posts

I'm trying to modify the damage of ranged weapons (bows and crossbows) without having to enchant them.

So far I've tried this, but it only modifies the left click melee damage, not the ranged damage dealt by firing them:

ItemStack cbowStack = new ItemStack(Items.CROSSBOW);
 
AttributeModifier mod = new AttributeModifier(UUID.randomUUID().toString(), 100.0D, AttributeModifier.Operation.ADDITION);

cbowStack.addAttributeModifier(Attributes.ATTACK_DAMAGE, mod, EquipmentSlot.MAINHAND);

evt.getEntity().setItemSlot(EquipmentSlot.MAINHAND, cbowStack);

I also don't want to modify any ammo since I'm planning to give these weapons to mobs (who I assume do not use ammo).

Link to comment
Share on other sites

There is no attribute for damage with projectiles.

Look at for example at

BowItem.releaseUsing() and AbstractArrow.onHitEntity()

to understand how it works.

You can see the damage is a function of the baseDamage and the velocity (deltaMovement) of the arrow.

The baseDamage can be affected by the POWER_ARROWS (power) enchantment and the velocity is affected by whether the bow is fully charged at firing.

 

If I was going to try do what you are doing, I would create my own Attribute. You can look at ForgeMod for how to do it.

https://github.com/MinecraftForge/MinecraftForge/blob/ec3abdea1455fc8c4e0f440d77e2dc24f880a4a6/src/main/java/net/minecraftforge/common/ForgeMod.java#L150

That way it is easy to identify and doesn't conflict with whatever other random stuff other mods are doing.

 

You can use the EntityJoinLevel event to trap when an arrow gets fired (check it is a real creation and not just a load from disk).

Arrow Entity -> getOwner() -> getItemInHand() would tell you which weapon the projectile was fired from (you need to check it is not from a dispenser or something else)

Then you can do Arrow.setBaseDamage() in a similar way to how the power enchantment works.

 

Personally, I think just adding the enchantment would be easier. So I wouldn't try to do it this way. 🙂 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.