diff --git a/datapacks/Bookshelf/data/bs.move/function/__load__.mcfunction b/datapacks/Bookshelf/data/bs.move/function/__load__.mcfunction index da7c87a5a6..173f86eaa8 100644 --- a/datapacks/Bookshelf/data/bs.move/function/__load__.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/__load__.mcfunction @@ -21,6 +21,7 @@ execute unless entity B5-0-0-0-1 run summon minecraft:marker -30000000 0 1600 {U scoreboard objectives add bs.in dummy [{"text":"BS ","color":"dark_gray"},{"text":"Input","color":"aqua"}] scoreboard objectives add bs.data dummy [{"text":"BS ","color":"dark_gray"},{"text":"Data","color":"aqua"}] scoreboard objectives add bs.const dummy [{"text":"BS ","color":"dark_gray"},{"text":"Constants","color":"aqua"}] +scoreboard objectives add bs.ctx dummy [{"text":"BS ","color":"dark_gray"},{"text":"Context","color":"aqua"}] scoreboard objectives add bs.vel.x dummy [{"text":"BS ","color":"dark_gray"},{"text":"Velocity X","color":"aqua"}] scoreboard objectives add bs.vel.y dummy [{"text":"BS ","color":"dark_gray"},{"text":"Velocity Y","color":"aqua"}] scoreboard objectives add bs.vel.z dummy [{"text":"BS ","color":"dark_gray"},{"text":"Velocity Z","color":"aqua"}] diff --git a/datapacks/Bookshelf/data/bs.move/function/__unload__.mcfunction b/datapacks/Bookshelf/data/bs.move/function/__unload__.mcfunction index 7941855c5e..7ed52cf9f2 100644 --- a/datapacks/Bookshelf/data/bs.move/function/__unload__.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/__unload__.mcfunction @@ -21,6 +21,7 @@ forceload remove -30000000 1600 scoreboard objectives remove bs.in scoreboard objectives remove bs.data scoreboard objectives remove bs.const +scoreboard objectives remove bs.ctx scoreboard objectives remove bs.vel.x scoreboard objectives remove bs.vel.y scoreboard objectives remove bs.vel.z diff --git a/datapacks/Bookshelf/data/bs.move/function/collision/handle.mcfunction b/datapacks/Bookshelf/data/bs.move/function/collision/handle.mcfunction index e6d3bac3d9..4c4a48636a 100644 --- a/datapacks/Bookshelf/data/bs.move/function/collision/handle.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/collision/handle.mcfunction @@ -54,5 +54,5 @@ execute if score #move.e bs.data matches 1 if data storage bs:data move{entities execute if score #move.vx bs.data matches 0.. at B5-0-0-0-1 align xyz run function bs.move:collision/recurse/x_pos execute if score #move.vx bs.data matches ..-1 at B5-0-0-0-1 align xyz run function bs.move:collision/recurse/x_neg tag @e[tag=bs.move.omit] remove bs.move.omit -execute if score #move.ctime bs.data matches 0..999 run function bs.move:collision/resolution/resolve with storage bs:data move +$execute if score #move.ctime bs.data matches 0..999 run function bs.move:collision/resolution/resolve {type:$(type)} execute in minecraft:overworld run tp B5-0-0-0-1 -30000000 0 1600 diff --git a/datapacks/Bookshelf/data/bs.move/function/collision/hitbox.mcfunction b/datapacks/Bookshelf/data/bs.move/function/collision/hitbox.mcfunction index b9cf366672..9bfa76b140 100644 --- a/datapacks/Bookshelf/data/bs.move/function/collision/hitbox.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/collision/hitbox.mcfunction @@ -16,17 +16,17 @@ # compute a bounding box that encompasses all passengers function #bs.hitbox:get_entity -execute store result score #move._h bs.data run data get storage bs:out hitbox.height 1000 -execute store result score #move._w bs.data run data get storage bs:out hitbox.width 500 -execute store result score #move._s bs.data run data get storage bs:out hitbox.scale 1000 -execute store result score #move._y bs.data run data get entity @s Pos[1] 1000 +execute store result score #h bs.ctx run data get storage bs:out hitbox.height 1000 +execute store result score #w bs.ctx run data get storage bs:out hitbox.width 500 +execute store result score #s bs.ctx run data get storage bs:out hitbox.scale 1000 +execute store result score #y bs.ctx run data get entity @s Pos[1] 1000 -scoreboard players operation #move._h bs.data *= #move._s bs.data -scoreboard players operation #move._w bs.data *= #move._s bs.data -scoreboard players operation #move._y bs.data -= #move.y bs.data -scoreboard players operation #move._y bs.data *= 1000 bs.const -scoreboard players operation #move._h bs.data += #move._y bs.data -execute store result score #move.sh bs.data run scoreboard players operation #move.h bs.data > #move._h bs.data -execute store result score #move.sw bs.data run scoreboard players operation #move.w bs.data > #move._w bs.data +scoreboard players operation #h bs.ctx *= #s bs.ctx +scoreboard players operation #w bs.ctx *= #s bs.ctx +scoreboard players operation #y bs.ctx -= #move.y bs.data +scoreboard players operation #y bs.ctx *= 1000 bs.const +scoreboard players operation #h bs.ctx += #y bs.ctx +execute store result score #move.sh bs.data run scoreboard players operation #move.h bs.data > #h bs.ctx +execute store result score #move.sw bs.data run scoreboard players operation #move.w bs.data > #w bs.ctx execute on passengers run function bs.move:collision/hitbox diff --git a/datapacks/Bookshelf/data/bs.move/function/collision/resolution/callback/canonical.mcfunction b/datapacks/Bookshelf/data/bs.move/function/collision/resolution/callback/canonical.mcfunction new file mode 100644 index 0000000000..e85b04d9de --- /dev/null +++ b/datapacks/Bookshelf/data/bs.move/function/collision/resolution/callback/canonical.mcfunction @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +# resolve collision using the on_collision callback +$function $(on_collision) +execute store result storage bs:ctx x double .001 run scoreboard players get $move.vel_remaining.x bs.data +execute store result storage bs:ctx y double .001 run scoreboard players get $move.vel_remaining.y bs.data +execute store result storage bs:ctx z double .001 run scoreboard players get $move.vel_remaining.z bs.data +execute unless data storage bs:ctx {x:0d,y:0d,z:0d} at @s run function bs.move:teleport/canonical/run with storage bs:ctx diff --git a/datapacks/Bookshelf/data/bs.move/function/collision/resolution/callback/local.mcfunction b/datapacks/Bookshelf/data/bs.move/function/collision/resolution/callback/local.mcfunction new file mode 100644 index 0000000000..73a587503c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.move/function/collision/resolution/callback/local.mcfunction @@ -0,0 +1,23 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +# resolve collision using the on_collision callback (ensure the velocity vector is in canonical space for simpler transformation) +execute rotated as @s run function #bs.move:local_to_canonical +$function $(on_collision) +execute store result storage bs:ctx x double .001 run scoreboard players get $move.vel_remaining.x bs.data +execute store result storage bs:ctx y double .001 run scoreboard players get $move.vel_remaining.y bs.data +execute store result storage bs:ctx z double .001 run scoreboard players get $move.vel_remaining.z bs.data +execute unless data storage bs:ctx {x:0d,y:0d,z:0d} at @s run function bs.move:teleport/canonical/run with storage bs:ctx +execute rotated as @s run function #bs.move:canonical_to_local diff --git a/datapacks/Bookshelf/data/bs.move/function/collision/resolution/resolve.mcfunction b/datapacks/Bookshelf/data/bs.move/function/collision/resolution/resolve.mcfunction index 1ad5223b10..43918cf7bb 100644 --- a/datapacks/Bookshelf/data/bs.move/function/collision/resolution/resolve.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/collision/resolution/resolve.mcfunction @@ -39,11 +39,4 @@ scoreboard players operation $move.vel_remaining.x bs.data += #move.vx bs.data scoreboard players operation $move.vel_remaining.y bs.data += #move.vy bs.data scoreboard players operation $move.vel_remaining.z bs.data += #move.vz bs.data -# resolve collision using the on_collision callback (ensure the velocity vector is in canonical space for simpler transformation) -execute if score #move.is_local bs.data matches 1 rotated as @s run function #bs.move:local_to_canonical -$function $(on_collision) -execute store result storage bs:ctx x double .001 run scoreboard players get $move.vel_remaining.x bs.data -execute store result storage bs:ctx y double .001 run scoreboard players get $move.vel_remaining.y bs.data -execute store result storage bs:ctx z double .001 run scoreboard players get $move.vel_remaining.z bs.data -execute unless data storage bs:ctx {x:0d,y:0d,z:0d} at @s run function bs.move:teleport/canonical/run with storage bs:ctx -execute if score #move.is_local bs.data matches 1 rotated as @s run function #bs.move:canonical_to_local +$function bs.move:collision/resolution/callback/$(type) with storage bs:data move diff --git a/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/canonical_to_local.mcfunction b/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/canonical_to_local.mcfunction index 04e9e572dc..d43fec4a6a 100644 --- a/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/canonical_to_local.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/canonical_to_local.mcfunction @@ -19,33 +19,33 @@ execute as B5-0-0-0-1 run function bs.move:convert/canonical_to_local/sincos # X' = Z * sin(h) + X * cos(h) -scoreboard players operation #move.canonical_to_local.x bs.data = @s bs.vel.z -scoreboard players operation #move.canonical_to_local.x bs.data *= #move.canonical_to_local.sin.h bs.data -scoreboard players operation #move.canonical_to_local bs.data = @s bs.vel.x -scoreboard players operation #move.canonical_to_local bs.data *= #move.canonical_to_local.cos.h bs.data -scoreboard players operation #move.canonical_to_local.x bs.data += #move.canonical_to_local bs.data -scoreboard players operation #move.canonical_to_local.x bs.data /= 1000 bs.const +scoreboard players operation #x bs.ctx = @s bs.vel.z +scoreboard players operation #x bs.ctx *= #j bs.ctx +scoreboard players operation #t bs.ctx = @s bs.vel.x +scoreboard players operation #t bs.ctx *= #i bs.ctx +scoreboard players operation #x bs.ctx += #t bs.ctx +scoreboard players operation #x bs.ctx /= 1000 bs.const # Y' = (z * cos(h) - x * sin(h)) * sin(v) + y * cos(v) -scoreboard players operation #move.canonical_to_local.y bs.data = @s bs.vel.z -scoreboard players operation #move.canonical_to_local.y bs.data *= #move.canonical_to_local.cos.h bs.data -scoreboard players operation #move.canonical_to_local bs.data = @s bs.vel.x -scoreboard players operation #move.canonical_to_local bs.data *= #move.canonical_to_local.sin.h bs.data -scoreboard players operation #move.canonical_to_local.y bs.data -= #move.canonical_to_local bs.data -execute store result score #move.canonical_to_local.z bs.data run scoreboard players operation #move.canonical_to_local.y bs.data /= 1000 bs.const -scoreboard players operation #move.canonical_to_local.y bs.data *= #move.canonical_to_local.sin.v bs.data -scoreboard players operation #move.canonical_to_local bs.data = @s bs.vel.y -scoreboard players operation #move.canonical_to_local bs.data *= #move.canonical_to_local.cos.v bs.data -scoreboard players operation #move.canonical_to_local.y bs.data += #move.canonical_to_local bs.data -scoreboard players operation #move.canonical_to_local.y bs.data /= 1000 bs.const +scoreboard players operation #y bs.ctx = @s bs.vel.z +scoreboard players operation #y bs.ctx *= #i bs.ctx +scoreboard players operation #t bs.ctx = @s bs.vel.x +scoreboard players operation #t bs.ctx *= #j bs.ctx +scoreboard players operation #y bs.ctx -= #t bs.ctx +execute store result score #z bs.ctx run scoreboard players operation #y bs.ctx /= 1000 bs.const +scoreboard players operation #y bs.ctx *= #l bs.ctx +scoreboard players operation #t bs.ctx = @s bs.vel.y +scoreboard players operation #t bs.ctx *= #k bs.ctx +scoreboard players operation #y bs.ctx += #t bs.ctx +scoreboard players operation #y bs.ctx /= 1000 bs.const # Z' = (z * cos(h) - x * sin(h)) * cos(v) - y * sin(v) -scoreboard players operation #move.canonical_to_local.z bs.data *= #move.canonical_to_local.cos.v bs.data -scoreboard players operation #move.canonical_to_local bs.data = @s bs.vel.y -scoreboard players operation #move.canonical_to_local bs.data *= #move.canonical_to_local.sin.v bs.data -scoreboard players operation #move.canonical_to_local.z bs.data -= #move.canonical_to_local bs.data -scoreboard players operation #move.canonical_to_local.z bs.data /= 1000 bs.const +scoreboard players operation #z bs.ctx *= #k bs.ctx +scoreboard players operation #t bs.ctx = @s bs.vel.y +scoreboard players operation #t bs.ctx *= #l bs.ctx +scoreboard players operation #z bs.ctx -= #t bs.ctx +scoreboard players operation #z bs.ctx /= 1000 bs.const -scoreboard players operation @s bs.vel.x = #move.canonical_to_local.x bs.data -scoreboard players operation @s bs.vel.y = #move.canonical_to_local.y bs.data -scoreboard players operation @s bs.vel.z = #move.canonical_to_local.z bs.data +scoreboard players operation @s bs.vel.x = #x bs.ctx +scoreboard players operation @s bs.vel.y = #y bs.ctx +scoreboard players operation @s bs.vel.z = #z bs.ctx diff --git a/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/sincos.mcfunction b/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/sincos.mcfunction index 6f7b59b6dd..1eeadfedc6 100644 --- a/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/sincos.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/convert/canonical_to_local/sincos.mcfunction @@ -14,9 +14,9 @@ # ------------------------------------------------------------------------------------------------------------ execute positioned 0.0 0.0 0.0 rotated ~ 0.0 run tp @s ^ ^ ^10.0 -execute store result score #move.canonical_to_local.cos.h bs.data run data get entity @s Pos[2] 100 -execute store result score #move.canonical_to_local.sin.h bs.data run data get entity @s Pos[0] -100 +execute store result score #i bs.ctx run data get entity @s Pos[2] 100 +execute store result score #j bs.ctx run data get entity @s Pos[0] -100 execute positioned 0.0 0.0 0.0 rotated 0.0 ~ run tp @s ^ ^ ^10.0 -execute store result score #move.canonical_to_local.cos.v bs.data run data get entity @s Pos[2] 100 -execute store result score #move.canonical_to_local.sin.v bs.data run data get entity @s Pos[1] -100 +execute store result score #k bs.ctx run data get entity @s Pos[2] 100 +execute store result score #l bs.ctx run data get entity @s Pos[1] -100 execute in minecraft:overworld run tp @s -30000000 0 1600 diff --git a/datapacks/Bookshelf/data/bs.move/function/teleport/canonical/run.mcfunction b/datapacks/Bookshelf/data/bs.move/function/teleport/canonical/run.mcfunction index baa24769dd..c07664d7ed 100644 --- a/datapacks/Bookshelf/data/bs.move/function/teleport/canonical/run.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/teleport/canonical/run.mcfunction @@ -15,5 +15,4 @@ $tp @s ~$(x) ~$(y) ~$(z) -scoreboard players set #move.is_local bs.data 0 -execute unless data storage bs:data move{blocks:0b,entities:0b} run function bs.move:collision/handle +execute unless data storage bs:data move{blocks:0b,entities:0b} run function bs.move:collision/handle {type:"canonical"} diff --git a/datapacks/Bookshelf/data/bs.move/function/teleport/local/run.mcfunction b/datapacks/Bookshelf/data/bs.move/function/teleport/local/run.mcfunction index 888f550aa5..57f1d78f3a 100644 --- a/datapacks/Bookshelf/data/bs.move/function/teleport/local/run.mcfunction +++ b/datapacks/Bookshelf/data/bs.move/function/teleport/local/run.mcfunction @@ -15,5 +15,4 @@ $tp @s ^$(x) ^$(y) ^$(z) -scoreboard players set #move.is_local bs.data 1 -execute unless data storage bs:data move{blocks:0b,entities:0b} run function bs.move:collision/handle +execute unless data storage bs:data move{blocks:0b,entities:0b} run function bs.move:collision/handle {type:"local"} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index dfd33de348..e22940ff71 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -32,6 +32,8 @@ ### 🐛 Fixes - ([243](https://github.com/Gunivers/Bookshelf/issues/243)) Fix `bs.health` and `bs.move` unload functions. - ([254](https://github.com/Gunivers/Bookshelf/issues/254)) Fix interruptions in the execution loop caused by `#bs.schedule:schedule` callbacks. + +- ([255](https://github.com/Gunivers/Bookshelf/issues/255)) Fix `bs.move` local velocity collisions. - ([254](https://github.com/Gunivers/Bookshelf/pull/262)) Fix collisions with paintings for `bs.raycast` and `bs.move`. - ([256](https://github.com/Gunivers/Bookshelf/issues/256)) Fix XP progress functions at bounds (0% and 100%).