Skip to content

Commit

Permalink
feat: rework power arrows system!
Browse files Browse the repository at this point in the history
  • Loading branch information
chuangcaleb committed Jan 27, 2024
1 parent 6f3470c commit f4a901c
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 125 deletions.
74 changes: 14 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,70 +34,24 @@ This data pack was designed to work alongside my other data pack, [Cycle Offhand
The vanilla Bow enchantment to always get is Power. Just like Sharpness, it's a flat simple damage increase, who doesn't want that? That's BORING. Power also makes combat boring once you start two-shotting every 10-heart mob.

WIth this data pack, Power works differently; **a Power bow now makes your arrows fly faster.**
WIth this data pack, Power works differently; **a Power bow now makes your arrows fly *faster*.**

This opens up a very different playstyle compared to Crossbows, or even vanilla Bows. The difference is most noticeable on partially-charged shots; a Power V Bow on minimal charge flies as fast as a fully-charged Power I Bow!
This opens up a very different playstyle compared to Crossbows, or even vanilla Bows. The difference is most noticeable on partially-charged shots; a floppy Power V Bow on weakest charge flies as fast as a fully-charged Power I Bow!

And, with a similar damage output, people may opt for the Crossbow now! All without completely scraping the Power enchantment, but instead recontextualizing it.

Yet, I recognize that increased arrow damage is important because you barely take any damage in full Diamond/Netherite from Arrow from a regular-damage-unenchanted Bow.

Arrow damage is calculated as:

> Effective Damage Value = Arrow `damage` NBT Value x Velocity on Impact
<table>
<tbody>
<tr>
<td>Power Level</td>
<td>Updated `damage` NBT Value</td>
<td>Target `damage` NBT Value</td>
<td>Target Initial Effective Damage Value</td>
</tr>
<tr>
<td><center>0</center></td>
<td>1.0</td>
<td>2.0</td>
<td>2.0</td>
</tr>
<tr>
<td><center>1</center></td>
<td>1.65</td>
<td>1.4</td>
<td>2.31</td>
</tr>
<tr>
<td><center>2</center></td>
<td>1.35</td>
<td>1.8</td>
<td>2.43</td>
</tr>
<tr>
<td><center>3</center></td>
<td>1.17</td>
<td>2.2</td>
<td>2.574</td>
</tr>
<tr>
<td><center>4</center></td>
<td>1.06</td>
<td>2.6</td>
<td>2.756</td>
</tr>
<tr>
<td><center>5</center></td>
<td>1.0</td>
<td>3.0</td>
<td>3.0</td>
</tr>
</tbody>
</table>

Since we are going to crazy values of initial velocity, we have to scale down the arbitrary damage coefficient of Power V arrows.

Yet, as you can see, Power V will still do much more damage than a Power I Arrow. So, still enchant your bows with Power.

And, if you haven't noticed, there is a noticeable jump from no Power to Power I. So, getting Power I on any bow makes a huge difference!
The damage an arrow deals is calculated by the `damage` NBT as well as its velocity on impact. Since we are going to scale up the values of initial velocity, we have to scale down the `damage` NBT of Power arrows.

| power level | speed multiplier | `damage` initial/vanilla | `damage` target (w/o speed) |
| ---- | ---- | ---- | ---- |
| 0 | 1.0 | 2.0 | 2.00 |
| 1 | 1.2 | 3.0 | 2.40 |
| 2 | 1.5 | 3.5 | 2.65 |
| 3 | 1.9 | 4.0 | 2.90 |
| 4 | 2.4 | 4.5 | 3.15 |
| 5.. | 3.0 | 5.0 | 3.40 |

Yet, I recognize that increased arrow damage is important because you barely take any damage in full Diamond/Netherite from Arrow from a regular-damage-unenchanted Bow. As you can see, Power V will still do much more damage than a Power I Arrow. So, still try to get higher levels of Power. But a Power V bow isn't going to hit like a truck.

Credit: I'm copying all these amazing ideas. I saw this idea on a Data Pack on planetminecraft years ago, titled something like "Acceleration — an enchantment that makes your arrows go faster!" It was an amazing idea and I tried hard but can't find it. So I had to code it from scratch. Took me a week. Please help claim the credits if anyone finds it!

Expand Down
12 changes: 1 addition & 11 deletions data/cchesed/functions/bft/items/phantom/phantom_100t.mcfunction
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
execute if entity @p[distance=120..] run kill @s

# execute store result score @s cc.ft.dx run data get entity @s Motion[0] 1000
# execute store result score @s cc.ft.dy run data get entity @s Motion[1] 1000
# execute store result score @s cc.ft.dz run data get entity @s Motion[2] 1000

# scoreboard players operation @s cc.ft.temp = @s cc.ft.dx
# scoreboard players operation @s cc.ft.temp += @s cc.ft.dy
# scoreboard players operation @s cc.ft.temp += @s cc.ft.dz

# scoreboard players reset @s cc.ft.temp
execute if entity @p[distance=120..] run kill @s
3 changes: 2 additions & 1 deletion data/cchesed/functions/bft/items/process_arrow.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ execute if entity @s[nbt={Color: 16765762}] run function cchesed:bft/items/flami

execute unless entity @s[nbt={PierceLevel: 0b}] run function cchesed:bft/misc/pierce/init

execute unless entity @s[nbt={damage: 2.0d}] run function cchesed:bft/misc/power/init
function cchesed:bft/misc/power/init
scoreboard players reset @s cc.ft.power

tag @s add cc.ft.proccesed_arrow
11 changes: 11 additions & 0 deletions data/cchesed/functions/bft/misc/power/1.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
execute store result entity @s Motion[0] double 0.0000012 run data get entity @s Motion[0] 1000000
execute store result entity @s Motion[1] double 0.0000012 run data get entity @s Motion[1] 1000000
execute store result entity @s Motion[2] double 0.0000012 run data get entity @s Motion[2] 1000000

# Final Multiplier = Target Damage / Initial Damage / Speed Multiplier
# Target Damage: 2.4
# Power I → Damage: 3.0
# Speed Multiplier: 1.2
# Final Multiplier: 0.6666666667

execute store result entity @s damage double 0.000000006666666667 run data get entity @s damage 100000000
10 changes: 10 additions & 0 deletions data/cchesed/functions/bft/misc/power/2.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
execute store result entity @s Motion[0] double 0.0000015 run data get entity @s Motion[0] 1000000
execute store result entity @s Motion[1] double 0.0000015 run data get entity @s Motion[1] 1000000
execute store result entity @s Motion[2] double 0.0000015 run data get entity @s Motion[2] 1000000

# Target Damage: 2.65
# Power II → Damage: 3.5
# Speed Multiplier: 1.5
# Final Multiplier: 0.5047619048

execute store result entity @s damage double 0.000000005047619048 run data get entity @s damage 100000000
10 changes: 10 additions & 0 deletions data/cchesed/functions/bft/misc/power/3.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
execute store result entity @s Motion[0] double 0.0000019 run data get entity @s Motion[0] 1000000
execute store result entity @s Motion[1] double 0.0000019 run data get entity @s Motion[1] 1000000
execute store result entity @s Motion[2] double 0.0000019 run data get entity @s Motion[2] 1000000

# Target Damage: 2.9
# Power III → Damage: 4.0
# Speed Multiplier: 1.9
# Final Multiplier: 0.3815789474

execute store result entity @s damage double 0.000000003815789474 run data get entity @s damage 100000000
10 changes: 10 additions & 0 deletions data/cchesed/functions/bft/misc/power/4.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
execute store result entity @s Motion[0] double 0.0000024 run data get entity @s Motion[0] 1000000
execute store result entity @s Motion[1] double 0.0000024 run data get entity @s Motion[1] 1000000
execute store result entity @s Motion[2] double 0.0000024 run data get entity @s Motion[2] 1000000

# Target Damage: 3.15
# Power IV → Damage: 4.5
# Speed Multiplier: 2.4
# Final Multiplier: 0.28

execute store result entity @s damage double 0.000000002916666667 run data get entity @s damage 100000000
10 changes: 10 additions & 0 deletions data/cchesed/functions/bft/misc/power/5.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
execute store result entity @s Motion[0] double 0.000003 run data get entity @s Motion[0] 1000000
execute store result entity @s Motion[1] double 0.000003 run data get entity @s Motion[1] 1000000
execute store result entity @s Motion[2] double 0.000003 run data get entity @s Motion[2] 1000000

# Target Damage: 3.4
# Power V → Damage: 5.0
# Speed Multiplier: 3
# Final Multiplier: 0.2266666667

execute store result entity @s damage double 0.000000002266666667 run data get entity @s damage 100000000
65 changes: 12 additions & 53 deletions data/cchesed/functions/bft/misc/power/init.mcfunction
Original file line number Diff line number Diff line change
@@ -1,57 +1,16 @@
# Get power level
execute store result score @s cc.ft.power run data get entity @s damage 10

# Get actual power value
scoreboard players operation @s cc.ft.power -= .25 cc.const
scoreboard players operation @s cc.ft.power /= .5 cc.const

# Cap at Power V
execute if score @s cc.ft.power matches 6.. run scoreboard players set @s cc.ft.power 5


# # Add bonus damage mult from power level
scoreboard players operation .bonus cc.ft.power = @s cc.ft.power
scoreboard players operation .bonus cc.ft.power *= .5 cc.const

# ------------------------------ Get multiplier ------------------------------ #

scoreboard players operation @s cc.ft.power *= .4 cc.const
# At least have 10, because that's the store result offset
scoreboard players operation @s cc.ft.power += .10 cc.const


# -------------------------- init damage/power value ------------------------ #
# Set base power of 2.0
scoreboard players operation .damage cc.ft.power = .2250 cc.const
scoreboard players operation .damage cc.ft.power /= @s cc.ft.power

scoreboard players operation .damage cc.ft.power += .bonus cc.ft.power

# data modify entity @s damage set value 1.0
execute store result entity @s damage double .01 run scoreboard players get .damage cc.ft.power

# --------------------------- apply score to motion -------------------------- #

# Transfer scores
execute store result score @s cc.ft.dx run data get entity @s Motion[0] 1000000
execute store result score @s cc.ft.dy run data get entity @s Motion[1] 1000000
execute store result score @s cc.ft.dz run data get entity @s Motion[2] 1000000

scoreboard players operation @s cc.ft.dx *= @s cc.ft.power
scoreboard players operation @s cc.ft.dy *= @s cc.ft.power
scoreboard players operation @s cc.ft.dz *= @s cc.ft.power
# Early return on non-player arrows
execute on origin if entity @s[type=!player] run return fail

# # Get power level
execute store result score @s cc.ft.power run data get entity @s damage 10

# Cap maximum
# execute if score @s cc.ft.dx matches 2147483647.. run scoreboard players set @s cc.ft.dx 2147483647
# execute if score @s cc.ft.dy matches 2147483647.. run scoreboard players set @s cc.ft.dy 2147483647
# execute if score @s cc.ft.dz matches 2147483647.. run scoreboard players set @s cc.ft.dz 2147483647
# Default arrow damage
execute if score @s cc.ft.power matches 20 run return fail

# execute if score @s cc.ft.dx matches -2147483648 run scoreboard players set @s cc.ft.dx -2147483648
# execute if score @s cc.ft.dy matches -2147483648 run scoreboard players set @s cc.ft.dy -2147483648
# execute if score @s cc.ft.dz matches -2147483648 run scoreboard players set @s cc.ft.dz -2147483648
# Tweak Power bows
execute if score @s cc.ft.power matches 30 run return run function cchesed:bft/misc/power/1
execute if score @s cc.ft.power matches 35 run return run function cchesed:bft/misc/power/2
execute if score @s cc.ft.power matches 40 run return run function cchesed:bft/misc/power/3
execute if score @s cc.ft.power matches 45 run return run function cchesed:bft/misc/power/4
execute if score @s cc.ft.power matches 50.. run return run function cchesed:bft/misc/power/5

# store motion
execute store result entity @s Motion[0] double .0000001 run scoreboard players get @s cc.ft.dx
execute store result entity @s Motion[1] double .0000001 run scoreboard players get @s cc.ft.dy
execute store result entity @s Motion[2] double .0000001 run scoreboard players get @s cc.ft.dz

0 comments on commit f4a901c

Please sign in to comment.