#Making arrows faster

1 messages · Page 1 of 1 (latest)

tiny oak
#

I have a custom enchantment for crossbows named Shotgun that slows charge time and increases damage. I want to make it so the arrows travel faster can anyone help me?

loud ridge
#

Afaik enchantment definition natively can't do it so we'll have to use the run_function entity effect,
The below method works(I tested it out)
Use the an enchantment definition similar to below:

{
    "anvil_cost": 2,
    "description": "Shotgun",
    "effects": {
        "minecraft:projectile_spawned": [
            {
                "effect": {
                    "type": "minecraft:run_function",
                    "function": "tg:shotgun/scale_arrow_motion"
                }
            }
        ]
    },
    "max_cost": {
        "base": 50,
        "per_level_above_first": 0
    },
    "max_level": 3,
    "min_cost": {
        "base": 12,
        "per_level_above_first": 20
    },
    "slots": [
        "mainhand",
        "offhand"
    ],
    "supported_items": "#minecraft:enchantable/crossbow",
    "weight": 5
}

And in function tg:shotgun/scale_arrow_motion:

execute store result score @s tg.shotgun.arrowMotion_x run data get entity @s Motion[0] 10000
execute store result score @s tg.shotgun.arrowMotion_y run data get entity @s Motion[1] 10000
execute store result score @s tg.shotgun.arrowMotion_z run data get entity @s Motion[2] 10000
scoreboard players set @s tg.shotgun.motionScale 2

scoreboard players operation @s tg.shotgun.arrowMotion_x *= @s tg.shotgun.motionScale
scoreboard players operation @s tg.shotgun.arrowMotion_y *= @s tg.shotgun.motionScale
scoreboard players operation @s tg.shotgun.arrowMotion_z *= @s tg.shotgun.motionScale

execute store result entity @s Motion[0] double 0.0001 run scoreboard players get @s tg.shotgun.arrowMotion_x
execute store result entity @s Motion[1] double 0.0001 run scoreboard players get @s tg.shotgun.arrowMotion_y
execute store result entity @s Motion[2] double 0.0001 run scoreboard players get @s tg.shotgun.arrowMotion_z
Minecraft Wiki

Enchantments are stored as JSON files within a data pack in the path data/<namespace>/enchantment.

#

minecraft:projectile_spawned will be triggered when a player shoots an arrow via a crossbow with shotgun enchantment, and the run_function will run tg:shotgun/scale_arrow_motion as the arrow shot.

Minecraft Wiki

Enchantments are stored as JSON files within a data pack in the path data/<namespace>/enchantment.

#

And tg:shotgun/scale_arrow_motion will multiply the executing entity's motion on all three axis by 2.

loud ridge
#

Another thing to note is that it seems the trail of the arrow is spawn on shot and will not match the trajectory of the actual arrow shot with a crossbow consists of this enchantment.
If you want to work around it you can create a resource pack and replace the arrow trail particle to empty texture, add a new particle that is the exact same as arrow trail, mimic the spawning arrow trail particle in vanilla, and change the generation of the arrow trail on this particular enchantment.

But its too much hassle

#

...Or maybe it does match and I'm dumb
Anyways the motion part is correct, I tested the distance arrows traveled with and w/o the enchantment

#

Yep it doesn't match

tiny oak
#

not functions sorry, scoreboard

#

ok thanks

loud ridge
tiny oak
#

thank you!

tiny oak
#

like it just goes behind me or above me

loud ridge
#

Try and increase the accuracy of the operation above (*1000000 in the data get and *0.000001 when getting the scoreboard)
Also multiply less when changing the motion, you can't exactly*= 1.5 in scoreboard but you can rely on the math library others created such as https://github.com/gibbsly/gm/

GitHub

A utility datapack for doing math operations. Contribute to gibbsly/gm development by creating an account on GitHub.

#

Also it might be the arrow's trail particles that's inaccurate that makes you think it is inaccurate, in my tests the arrows actually lines up with the not enchanted ones if keep the crosshair the same and shoot at the same target in a short distance(the non enchanted one will fall off in long distance)