Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions PlayerMotion/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 BigPapi13, MulverineX

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions PlayerMotion/data/minecraft/tags/functions/load.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values" : [
"player_motion:internal/technical/load"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#> player_motion:api/launch_looking
#
# Launches the player in the input direction
#
# @api

execute if entity @s[type=!player] run return fail
execute on vehicle run return fail

scoreboard players set $function_called PlayerMotion.Internal.Dummy 1
tag @s add PlayerMotion.Launch

execute store result storage player_motion:math strength double 0.0001 run scoreboard players get $strength PlayerMotion.Api.Launch
execute as 0-0-0-0-0 in minecraft:overworld positioned 0.0 0.0 0.0 run function player_motion:internal/math/looking_to_xyz with storage player_motion:math

execute store result score $out PlayerMotion.Internal.Motion.X run data get storage player_motion:math motion[0] 10000
execute store result score $out PlayerMotion.Internal.Motion.Y run data get storage player_motion:math motion[1] 10000
execute store result score $out PlayerMotion.Internal.Motion.Z run data get storage player_motion:math motion[2] 10000

scoreboard players operation @s PlayerMotion.Internal.Motion.X += $out PlayerMotion.Internal.Motion.X
scoreboard players operation @s PlayerMotion.Internal.Motion.Y += $out PlayerMotion.Internal.Motion.Y
scoreboard players operation @s PlayerMotion.Internal.Motion.Z += $out PlayerMotion.Internal.Motion.Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#> player_motion:api/launch_xyz
#
# Launches the player in the input direction
#
# @api

execute if entity @s[type=!player] run return fail
execute on vehicle run return fail

scoreboard players set $function_called PlayerMotion.Internal.Dummy 1
tag @s add PlayerMotion.Launch

scoreboard players operation @s PlayerMotion.Internal.Motion.X += $x PlayerMotion.Api.Launch
scoreboard players operation @s PlayerMotion.Internal.Motion.Y += $y PlayerMotion.Api.Launch
scoreboard players operation @s PlayerMotion.Internal.Motion.Z += $z PlayerMotion.Api.Launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#> player_motion:internal/launch/exp_pos
# @private

$tp 0-0-0-0-0 ^ ^ ^$(d)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#> player_motion:internal/launch/gamemode/get
# @within function player_motion:internal/launch/main

execute if entity @s[gamemode=survival] run return run scoreboard players set $mode PlayerMotion.Internal.Gamemode 0
execute if entity @s[gamemode=creative] run return run scoreboard players set $mode PlayerMotion.Internal.Gamemode 1
execute if entity @s[gamemode=adventure] run return run scoreboard players set $mode PlayerMotion.Internal.Gamemode 2
execute if entity @s[gamemode=spectator] run scoreboard players set $mode PlayerMotion.Internal.Gamemode 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#> player_motion:internal/launch/gamemode/restore
# @within function player_motion:internal/launch/main

execute if score $mode PlayerMotion.Internal.Gamemode matches 0 run return run gamemode survival @s
execute if score $mode PlayerMotion.Internal.Gamemode matches 1 run return run gamemode creative @s
execute if score $mode PlayerMotion.Internal.Gamemode matches 2 run return run gamemode adventure @s
execute if score $mode PlayerMotion.Internal.Gamemode matches 3 run gamemode spectator @s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#> player_motion:internal/launch/main
#
# Launches players in the input direction
#
# @within function player_motion:internal/technical/tick

execute store result storage player_motion:math motion[0] double 0.0001 store result storage player_motion:math motion_x double 0.0001 run scoreboard players operation $motion_x PlayerMotion.Internal.Math = @s PlayerMotion.Internal.Motion.X
execute store result storage player_motion:math motion[1] double 0.0001 store result storage player_motion:math motion_y double 0.0001 run scoreboard players operation $motion_y PlayerMotion.Internal.Math = @s PlayerMotion.Internal.Motion.Y
execute store result storage player_motion:math motion[2] double 0.0001 store result storage player_motion:math motion_z double 0.0001 run scoreboard players operation $motion_z PlayerMotion.Internal.Math = @s PlayerMotion.Internal.Motion.Z

execute in minecraft:overworld run function player_motion:internal/math/main
# attribute @s explosion_knockback_resistance modifier add player_motion:disable_knockback_resistance -1 add_multiplied_total
function player_motion:internal/launch/gamemode/get
gamemode creative
tp ~ ~10000 ~
execute rotated as @s positioned ~ ~10000 ~ run function player_motion:internal/summon/main with storage player_motion:math
tp ~ ~ ~
Comment thread
haiiro2gou marked this conversation as resolved.
function player_motion:internal/launch/gamemode/restore
# attribute @s explosion_knockback_resistance modifier remove player_motion:disable_knockback_resistance

scoreboard players set $function_called PlayerMotion.Internal.Dummy 0
tag @s remove PlayerMotion.Launch

# Reset scoreboards
scoreboard players reset @s PlayerMotion.Internal.Motion.X
scoreboard players reset @s PlayerMotion.Internal.Motion.Y
scoreboard players reset @s PlayerMotion.Internal.Motion.Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#> player_motion:internal/math/eyelevel
# @within function player_motion:internal/math/main

# eyelevel=y(eyes)-y(player)
execute anchored eyes positioned ^ ^ ^ if entity @s[distance=...41] run return run scoreboard players set $eyelevel PlayerMotion.Internal.Math 40
Comment thread
haiiro2gou marked this conversation as resolved.

execute anchored eyes positioned ^ ^ ^ if entity @s[distance=..1.27] run return run scoreboard players set $eyelevel PlayerMotion.Internal.Math 127

scoreboard players set $eyelevel PlayerMotion.Internal.Math 162
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#> player_motion:internal/math/full_power/sine
# @within function player_motion:internal/math/full_power/trig

$execute store result score $n_full_exp PlayerMotion.Internal.Math run data get storage player_motion:trig arr[$(angle)]
scoreboard players operation $n_full_exp PlayerMotion.Internal.Math *= $motion_y PlayerMotion.Internal.Math
execute store result score $sub_power PlayerMotion.Internal.Math run scoreboard players operation $n_full_exp PlayerMotion.Internal.Math /= $1000 Const
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#> player_motion:internal/math/full_power/tp
# @within function player_motion:internal/math/full_power/trig

execute store result storage player_motion:math pos[0] double 0.1 run scoreboard players get $motion_x PlayerMotion.Internal.Math
execute store result storage player_motion:math pos[1] double 0.1 run scoreboard players get $motion_y PlayerMotion.Internal.Math
execute store result storage player_motion:math pos[2] double 0.1 run scoreboard players get $motion_z PlayerMotion.Internal.Math
data modify entity @s Pos set from storage player_motion:math pos
execute at @s facing 0.0 0.0 0.0 run tp @s 0 0 0 0 ~
function api:data_get/rotation
execute store result storage player_motion:math magnitude.angle int 1 run data get storage api: Rotation[1] 100
Comment thread
haiiro2gou marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#> player_motion:internal/math/full_power/trig
# @within function player_motion:internal/math/main

execute as 0-0-0-0-0 run function player_motion:internal/math/full_power/tp
function player_motion:internal/math/full_power/sine with storage player_motion:math magnitude
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#> player_motion:internal/math/looking_to_xyz
# @within function player_motion:api/launch_looking

$tp @s ^ ^ ^$(strength)
data modify storage player_motion:math motion set from entity @s Pos
tp @s 0.0 0.0 0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#> player_motion:internal/math/main
# @within function player_motion:internal/launch/main

# full_power=sqrt(motion_x²+motion_y²+motion_z²)
# Save sign of $motion_y
execute store success score $negative_sine PlayerMotion.Internal.Math if score $motion_y PlayerMotion.Internal.Math matches ..-1

# Normalize
execute if score $motion_x PlayerMotion.Internal.Math matches ..-1 run scoreboard players operation $motion_x PlayerMotion.Internal.Math *= $-1 Const

execute if score $motion_y PlayerMotion.Internal.Math matches ..-1 run scoreboard players operation $motion_y PlayerMotion.Internal.Math *= $-1 Const

execute if score $motion_z PlayerMotion.Internal.Math matches ..-1 run scoreboard players operation $motion_z PlayerMotion.Internal.Math *= $-1 Const

# Sets angle before exchange
scoreboard players set $angle PlayerMotion.Internal.Math 0

execute if score $motion_y PlayerMotion.Internal.Math matches 0 run scoreboard players set $angle PlayerMotion.Internal.Math 1

# SuperSwordTW's method. Credit: https://github.com/SuperSwordTW/Distance-Trig-Calc-3d
execute if score $motion_y PlayerMotion.Internal.Math matches 0 run scoreboard players operation $motion_y PlayerMotion.Internal.Math >< $motion_x PlayerMotion.Internal.Math

execute if score $motion_y PlayerMotion.Internal.Math matches 0 run scoreboard players operation $motion_y PlayerMotion.Internal.Math >< $motion_z PlayerMotion.Internal.Math

function player_motion:internal/math/full_power/trig

# n_full_exp=floor(full_power/0.865)
scoreboard players operation $n_full_exp PlayerMotion.Internal.Math /= $8000 Const

# Change back the angle
execute if score $angle PlayerMotion.Internal.Math matches 1 run data modify storage player_motion:math magnitude.angle set value 0

# eyelevel=y(eyes)-y(player)
function player_motion:internal/math/eyelevel

# sub power operations
# sub_power=floor(full_power%0.8)
scoreboard players operation $sub_power PlayerMotion.Internal.Math %= $8000 Const

# d12=1-sub_power
scoreboard players set $d12 PlayerMotion.Internal.Math 10000
scoreboard players operation $d12 PlayerMotion.Internal.Math -= $sub_power PlayerMotion.Internal.Math

# Formula d=-(eyelevel*sinα + d12*12 * cos(arcsin(cosα*eyelevel/(d12*12))))

# d12 = d12*12
scoreboard players operation $d12 PlayerMotion.Internal.Math *= $12 Const

# Obtain sinα and cosα
function player_motion:internal/math/trig/sine with storage player_motion:math magnitude

# cosα *= eyelevel, record cosα for later use
scoreboard players operation $cosine PlayerMotion.Internal.Math *= $eyelevel PlayerMotion.Internal.Math
scoreboard players operation $cosine1 PlayerMotion.Internal.Math = $cosine PlayerMotion.Internal.Math

# cosα /= d12 = cosα*eyelevel / (d12*12)
scoreboard players operation $cosine PlayerMotion.Internal.Math *= $10 Const

scoreboard players operation $cosine PlayerMotion.Internal.Math /= $d12 PlayerMotion.Internal.Math

# obtain cos(arcsin(cosα*eyelevel/(d12*12))))
execute store result storage player_motion:math magnitude.quotient int 1 run scoreboard players get $cosine PlayerMotion.Internal.Math

function player_motion:internal/math/trig/arcsine with storage player_motion:math magnitude

# cos(arcsin(cosα*eyelevel/(d12)))) *= d12
scoreboard players operation $d PlayerMotion.Internal.Math *= $d12 PlayerMotion.Internal.Math

scoreboard players operation $d PlayerMotion.Internal.Math /= $1000 Const

# sinα *= eyelevel, record sine for later use
scoreboard players operation $sine PlayerMotion.Internal.Math *= $eyelevel PlayerMotion.Internal.Math

scoreboard players operation $sine PlayerMotion.Internal.Math /= $10 Const

scoreboard players operation $sine1 PlayerMotion.Internal.Math = $sine PlayerMotion.Internal.Math

# d += sine
execute store result storage player_motion:math d double -0.0001 run scoreboard players operation $d PlayerMotion.Internal.Math += $sine PlayerMotion.Internal.Math


# full power operations
# d12=1-fpc(0.8) = 0.2
scoreboard players set $d12 PlayerMotion.Internal.Math 2000

#full_d = -(eyelevel*sinα + (d12*12)*cos(arcsin(cosα*eyelevel/(d12*12))))

# d12 = d12*12
scoreboard players operation $d12 PlayerMotion.Internal.Math *= $12 Const

# cosine1 = cosα*eyelevel, cosine1 /= d12
scoreboard players operation $cosine1 PlayerMotion.Internal.Math *= $10 Const

scoreboard players operation $cosine1 PlayerMotion.Internal.Math /= $d12 PlayerMotion.Internal.Math

# Obtain cos(arcsin(cosine1))
execute store result storage player_motion:math magnitude.quotient int 1 run scoreboard players get $cosine1 PlayerMotion.Internal.Math

function player_motion:internal/math/trig/arcsine with storage player_motion:math magnitude

# cos(arcsin(cosα*eyelevel/(d12)))) *= d12
scoreboard players operation $d PlayerMotion.Internal.Math *= $d12 PlayerMotion.Internal.Math
scoreboard players operation $d PlayerMotion.Internal.Math /= $1000 Const

# d += sine1
execute store result storage player_motion:math full_d double -0.0001 run scoreboard players operation $d PlayerMotion.Internal.Math += $sine1 PlayerMotion.Internal.Math
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#> player_motion:internal/math/trig/arcsine
# @within function player_motion:internal/math/main

$execute store result score $d PlayerMotion.Internal.Math run data get storage player_motion:arcsine arr[$(quotient)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#> player_motion:internal/math/trig/sine
# @within function player_motion:internal/math/main

$execute store result score $sine PlayerMotion.Internal.Math run data get storage player_motion:sine arr[$(angle)]
execute if score $negative_sine PlayerMotion.Internal.Math matches 1 run scoreboard players operation $sine PlayerMotion.Internal.Math *= $-1 Const
$execute store result score $cosine PlayerMotion.Internal.Math run data get storage player_motion:cosine arr[$(angle)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#> player_motion:internal/summon/crystal
# @within function player_motion:internal/summon/main

$execute if score $n_full_exp PlayerMotion.Internal.Math matches 1.. anchored eyes positioned ^ ^ ^$(full_d) run function player_motion:internal/summon/loop
$execute anchored eyes positioned ^ ^ ^$(d) summon end_crystal run damage @s 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#> player_motion:internal/summon/loop
# @within function
# player_motion:internal/summon/crystal
# player_motion:internal/summon/loop

scoreboard players remove $n_full_exp PlayerMotion.Internal.Math 1
execute summon end_crystal run damage @s 0
execute if score $n_full_exp PlayerMotion.Internal.Math matches 1.. run function player_motion:internal/summon/loop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#> player_motion:internal/summon/main

$execute facing ~$(motion_x) ~$(motion_y) ~$(motion_z) run function player_motion:internal/summon/crystal with storage player_motion:math
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#> player_motion:internal/technical/load
# @within tag/function minecraft:load

#> STORAGE
# @public
#declare storage player_motion:math
data modify storage player_motion:math unitvector set value [0.0d,0.0d,0.0d]
data modify storage player_motion:math motion set value [0.0d,0.0d,0.0d]
data modify storage player_motion:math pos set value [0.0d,0.0d,0.0d]

# TICK FUNCTION
schedule function player_motion:internal/technical/tick 1t append
Comment thread
haiiro2gou marked this conversation as resolved.

#> OBJECTIVE

#> Launch Api
# @api
scoreboard objectives add PlayerMotion.Api.Launch dummy

#> Internal
# @within function player_motion:**
scoreboard objectives add PlayerMotion.Internal.Dummy dummy
scoreboard objectives add PlayerMotion.Internal.Math dummy
scoreboard objectives add PlayerMotion.Internal.Math.Sqrt dummy
scoreboard objectives add PlayerMotion.Internal.Motion.X dummy
scoreboard objectives add PlayerMotion.Internal.Motion.Y dummy
scoreboard objectives add PlayerMotion.Internal.Motion.Z dummy
scoreboard objectives add PlayerMotion.Internal.Gamemode dummy

#> TAG
# @within function
# player_motion:api/**
# player_motion:internal/launch/main
# player_motion:internal/technical/tick
#declare tag PlayerMotion.Launch

# FORCELOAD
# forceload add 0 0

# MARKER
# kill d4bd74a7-4e82-4a07-8850-dfc4d89f9e2f
# summon marker 0.0 0.0 0.0 {UUID:[I; -725781337, 1317161479, -2007965756, -660627921], Tags:["smithed.strict", "smithed.entity"]}


# TRIG LOOKUP TABLE:
function player_motion:internal/technical/trig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#> player_motion:internal/technical/tick
# @within function
# player_motion:internal/technical/load
# player_motion:internal/technical/tick

# TICK FUNCTION
schedule function player_motion:internal/technical/tick 1t append
Comment thread
haiiro2gou marked this conversation as resolved.

# LAUNCH PLAYERS
execute if score $function_called PlayerMotion.Internal.Dummy matches 1 as @a[tag=PlayerMotion.Launch] at @s run function player_motion:internal/launch/main

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions PlayerMotion/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 26,
"description": "player_motion datapack - 1.20.4 fork"
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
このリポジトリでは、以下のディレクトリを除いて[CC0-1.0 License](LICENSE)が適用されます。
* [NaturalMergeSort](NaturalMergeSort)ディレクトリ ([MIT License](NaturalMergeSort/LICENSE) / Copyright by 赤石愛)
* [OhMyDat](OhMyDat)ディレクトリ ([MIT License](OhMyDat/LICENSE) / Copyright by 赤石愛)
* [PlayerMotion](PlayerMotion)ディレクトリ ([MIT License](PlayerMotion/LICENSE) / Copyright by BigPapi13 & MulverineX)
* [ScoreToHealth](ScoreToHealth)ディレクトリ ([Apache-2.0 License](ScoreToHealth/LICENSE) / Copyright by 赤石愛)
* [TheSkyBlessing/data/rom](TheSkyBlessing/data/rom/functions/)ディレクトリ ([MIT License](OhMyDat/LICENSE) / Copyright by 赤石愛)

Expand All @@ -31,5 +32,8 @@
* [ScoreToHealth](https://github.com/Ai-Akaishi/ScoreToHealth)
* [ScoreToMove](https://github.com/Ai-Akaishi/ScoreToMove)

#### [BigPapi13](https://github.com/BigPapi13)氏 & [MulverineX](https://github.com/MulverineX)氏
* [player_motion](https://github.com/MulverineX/player_motion)

## コラボレーター以外によるプルリクエストについて
コラボレーター以外によるプルリクエストは、最適化, バグ修正に限り歓迎しています。
Loading