Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Improve the bs.hitbox module #252

Merged
merged 5 commits into from
Oct 9, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion datapacks/Bookshelf/data/bs.block/loot_table/get/get.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"version": "1.20.3"
},
"updated": {
"date": "2024/03/30",
"version": "1.20.4"
"date": "2024/09/28",
"version": "1.21"
}
},
{
Expand All @@ -25,8 +25,38 @@
"version": "1.20.3"
},
"updated": {
"date": "2024/03/30",
"version": "1.20.4"
"date": "2024/09/28",
"version": "1.21"
}
},
{
"name": "is_entity_in_block",
"documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/hitbox.html#is-inside",
"authors": [
"Aksiome"
],
"created": {
"date": "2024/09/28",
"version": "1.21"
},
"updated": {
"date": "2024/09/28",
"version": "1.21"
}
},
{
"name": "is_entity_in_blocks",
"documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/hitbox.html#is-inside",
"authors": [
"Aksiome"
],
"created": {
"date": "2024/09/28",
"version": "1.21"
},
"updated": {
"date": "2024/09/28",
"version": "1.21"
}
},
{
Expand All @@ -40,8 +70,8 @@
"version": "1.20.3"
},
"updated": {
"date": "2024/03/30",
"version": "1.20.4"
"date": "2024/09/28",
"version": "1.21"
}
},
{
Expand All @@ -55,8 +85,8 @@
"version": "1.20.3"
},
"updated": {
"date": "2024/03/30",
"version": "1.20.4"
"date": "2024/09/28",
"version": "1.21"
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"features": [
"bs.hitbox:get_block",
"bs.hitbox:get_entity",
"bs.hitbox:is_entity_in_block",
"bs.hitbox:is_entity_in_blocks",
"bs.hitbox:is_in_block",
"bs.hitbox:is_in_entity"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
# ------------------------------------------------------------------------------------------------------------

forceload add -30000000 1600
setblock -30000000 0 1606 minecraft:decorated_pot
execute unless entity B5-0-0-0-1 run summon minecraft:marker -30000000 0 1600 {UUID:[I;181,0,0,1],Tags:["bs.entity","bs.persistent"]}

scoreboard objectives add bs.out dummy [{"text":"BS ","color":"dark_gray"},{"text":"Output","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.out dummy [{"text":"BS ","color":"dark_gray"},{"text":"Output","color":"aqua"}]

scoreboard players set 2 bs.const 2
scoreboard players set 11 bs.const 11
Expand All @@ -29,6 +30,7 @@ scoreboard players set 255 bs.const 255
scoreboard players set 1000 bs.const 1000
scoreboard players set 65536 bs.const 65536
scoreboard players set 3129871 bs.const 3129871
scoreboard players set 1000000 bs.const 1000000
scoreboard players set 10000000 bs.const 10000000
scoreboard players set 16777216 bs.const 16777216
scoreboard players set 42317861 bs.const 42317861
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
# ------------------------------------------------------------------------------------------------------------

kill B5-0-0-0-1
setblock -30000000 0 1606 minecraft:air
forceload remove -30000000 1600

scoreboard objectives remove bs.out
scoreboard objectives remove bs.data
scoreboard objectives remove bs.const
scoreboard objectives remove bs.ctx
scoreboard objectives remove bs.out

data remove storage bs:out hitbox
data remove storage bs:data hitbox
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@
# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/hitbox.html#get
# ------------------------------------------------------------------------------------------------------------

scoreboard players set #hitbox.id bs.data 0
execute if block ~ ~ ~ #bs.hitbox:shape/group_1 run scoreboard players add #hitbox.id bs.data 1
execute if block ~ ~ ~ #bs.hitbox:shape/group_2 run scoreboard players add #hitbox.id bs.data 2
execute if block ~ ~ ~ #bs.hitbox:shape/group_4 run scoreboard players add #hitbox.id bs.data 4
execute if block ~ ~ ~ #bs.hitbox:shape/group_8 run scoreboard players add #hitbox.id bs.data 8
execute if block ~ ~ ~ #bs.hitbox:shape/group_16 run scoreboard players add #hitbox.id bs.data 16
execute if block ~ ~ ~ #bs.hitbox:shape/group_32 run scoreboard players add #hitbox.id bs.data 32
execute if block ~ ~ ~ #bs.hitbox:shape/group_64 run scoreboard players add #hitbox.id bs.data 64
execute unless block ~ ~ ~ #bs.hitbox:is_composite run \
return run data modify storage bs:out hitbox set value {shape:[[0.0,0.0,0.0,16.0,16.0,16.0]]}

data modify storage bs:out hitbox set value {shape:[],offset:{x:0d,z:0d}}
execute store result storage bs:ctx y short 1 run scoreboard players get #hitbox.id bs.data
function bs.hitbox:get_block/dispatch with storage bs:ctx
loot replace block -30000000 0 1606 container.0 loot bs.hitbox:get_block/get
data modify storage bs:out hitbox set from block -30000000 0 1606 item.components."minecraft:custom_data"
execute if block ~ ~ ~ #bs.hitbox:has_offset as B5-0-0-0-1 run function bs.hitbox:get_block/offset/get
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ------------------------------------------------------------------------------------------------------------
# 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.
# ------------------------------------------------------------------------------------------------------------

execute store result score #u bs.ctx run data get storage bs:out hitbox.offset.x 10000000
execute store result score #v bs.const run data get storage bs:out hitbox.offset.z 10000000

$execute if score #u bs.ctx matches ..$(min) run scoreboard players set #u bs.ctx $(min)
$execute if score #v bs.ctx matches ..$(min) run scoreboard players set #v bs.ctx $(min)
$execute if score #u bs.ctx matches $(max).. run scoreboard players set #u bs.ctx $(max)
$execute if score #v bs.ctx matches $(max).. run scoreboard players set #v bs.ctx $(max)

execute store result storage bs:out hitbox.offset.x double .0000001 run scoreboard players get #u bs.ctx
execute store result storage bs:out hitbox.offset.z double .0000001 run scoreboard players get #v bs.ctx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

# compute the offset since we only care about bits 16 to 24, overflow of the scoreboard is not an issue
data modify storage bs:data hitbox.offsets append value {x:0,z:0,k:[0,0]}
execute store result storage bs:data hitbox.offsets[-1].k[0] int 1 run scoreboard players get #hitbox.offset.x bs.data
execute store result storage bs:data hitbox.offsets[-1].k[1] int 1 run scoreboard players get #hitbox.offset.z bs.data
execute store result storage bs:data hitbox.offsets[-1].k[0] int 1 run scoreboard players get #u bs.ctx
execute store result storage bs:data hitbox.offsets[-1].k[1] int 1 run scoreboard players get #v bs.ctx

# compute i = (x * 3129871) ^ (z * 116129781) - [Triton365 fast bitwise xor (using floating-point errors)]
execute store result entity @s Pos[1] double .000000007450580596923828125 run scoreboard players operation #hitbox.offset.x bs.data *= 3129871 bs.const
execute store result entity @s Pos[2] double .000000007450580596923828125 run scoreboard players operation #hitbox.offset.z bs.data *= 116129781 bs.const
execute store result entity @s Pos[1] double .000000007450580596923828125 run scoreboard players operation #u bs.ctx *= 3129871 bs.const
execute store result entity @s Pos[2] double .000000007450580596923828125 run scoreboard players operation #v bs.ctx *= 116129781 bs.const
execute at @s \
positioned -.00000000186264514923095703125 ~33554496 ~33554496 facing ~ ~-.0000000037252902984619140625 ~-.0000000037252902984619140625 positioned ^ ^ ^-.00000000186264514923095703125 \
positioned ~ ~33554431.9999999962747097015380859375 ~33554431.9999999962747097015380859375 facing ~ ~-.000000007450580596923828125 ~-.000000007450580596923828125 positioned ^ ^ ^-.0000000037252902984619140625 \
Expand Down Expand Up @@ -54,37 +54,37 @@ execute at @s \
positioned ~ ~9007199254740991 ~9007199254740991 facing ~ ~-2 ~-2 positioned ^ ^ ^-1 \
positioned ~ ~18014398509481982 ~18014398509481982 facing ~ ~-4 ~-4 positioned ^ ^ ^2 \
run tp @s ~ 0 0.
execute store result score #hitbox.offset.i bs.data run data get entity @s Pos[0] 1073741824
scoreboard players operation #hitbox.offset.i bs.data -= #hitbox.offset.x bs.data
execute store result score #hitbox.offset.i2 bs.data run scoreboard players operation #hitbox.offset.i bs.data -= #hitbox.offset.z bs.data
execute store result score #i bs.ctx run data get entity @s Pos[0] 1073741824
scoreboard players operation #i bs.ctx -= #u bs.ctx
execute store result score #j bs.ctx run scoreboard players operation #i bs.ctx -= #v bs.ctx

# compute i = (i * i * 42317861) + (i * 11)
scoreboard players operation #hitbox.offset.i2 bs.data *= #hitbox.offset.i2 bs.data
scoreboard players operation #hitbox.offset.i2 bs.data *= 42317861 bs.const
scoreboard players operation #hitbox.offset.i bs.data *= 11 bs.const
execute store result score #hitbox.offset.x bs.data store result score #hitbox.offset.z bs.data run scoreboard players operation #hitbox.offset.i bs.data += #hitbox.offset.i2 bs.data
scoreboard players operation #j bs.ctx *= #j bs.ctx
scoreboard players operation #j bs.ctx *= 42317861 bs.const
scoreboard players operation #i bs.ctx *= 11 bs.const
execute store result score #u bs.ctx store result score #v bs.ctx run scoreboard players operation #i bs.ctx += #j bs.ctx

# compute offset x = (((i >> 16 & 15) / 15.0) - 0.5) * 0.5
scoreboard players operation #hitbox.offset.x bs.data /= 65536 bs.const
scoreboard players operation #hitbox.offset.x bs.data *= 268435456 bs.const
scoreboard players operation #hitbox.offset.x bs.data /= 268435456 bs.const
execute if score #hitbox.offset.x bs.data matches ..-1 run scoreboard players add #hitbox.offset.x bs.data 16
scoreboard players operation #hitbox.offset.x bs.data *= 10000000 bs.const
scoreboard players operation #hitbox.offset.x bs.data /= 15 bs.const
scoreboard players remove #hitbox.offset.x bs.data 5000000
scoreboard players operation #hitbox.offset.x bs.data /= 2 bs.const
scoreboard players operation #u bs.ctx /= 65536 bs.const
scoreboard players operation #u bs.ctx *= 268435456 bs.const
scoreboard players operation #u bs.ctx /= 268435456 bs.const
execute if score #u bs.ctx matches ..-1 run scoreboard players add #u bs.ctx 16
scoreboard players operation #u bs.ctx *= 10000000 bs.const
scoreboard players operation #u bs.ctx /= 15 bs.const
scoreboard players remove #u bs.ctx 5000000
scoreboard players operation #u bs.ctx /= 2 bs.const

# compute offset z = (((i >> 24 & 15) / 15.0) - 0.5) * 0.5
scoreboard players operation #hitbox.offset.z bs.data /= 16777216 bs.const
scoreboard players operation #hitbox.offset.z bs.data *= 268435456 bs.const
scoreboard players operation #hitbox.offset.z bs.data /= 268435456 bs.const
execute if score #hitbox.offset.z bs.data matches ..-1 run scoreboard players add #hitbox.offset.z bs.data 16
scoreboard players operation #hitbox.offset.z bs.data *= 10000000 bs.const
scoreboard players operation #hitbox.offset.z bs.data /= 15 bs.const
scoreboard players remove #hitbox.offset.z bs.data 5000000
scoreboard players operation #hitbox.offset.z bs.data /= 2 bs.const
scoreboard players operation #v bs.ctx /= 16777216 bs.const
scoreboard players operation #v bs.ctx *= 268435456 bs.const
scoreboard players operation #v bs.ctx /= 268435456 bs.const
execute if score #v bs.ctx matches ..-1 run scoreboard players add #v bs.ctx 16
scoreboard players operation #v bs.ctx *= 10000000 bs.const
scoreboard players operation #v bs.ctx /= 15 bs.const
scoreboard players remove #v bs.ctx 5000000
scoreboard players operation #v bs.ctx /= 2 bs.const

# cache the result for better performance in future calls
execute store result storage bs:out hitbox.offset.x double .0000001 run scoreboard players get #hitbox.offset.x bs.data
execute store result storage bs:out hitbox.offset.z double .0000001 run scoreboard players get #hitbox.offset.z bs.data
execute store result storage bs:out hitbox.offset.x double .0000001 run scoreboard players get #u bs.ctx
execute store result storage bs:out hitbox.offset.z double .0000001 run scoreboard players get #v bs.ctx
data modify storage bs:data hitbox.offsets[-1] merge from storage bs:out hitbox.offset
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
# For more details, refer to the MPL v2.0.
# ------------------------------------------------------------------------------------------------------------

$execute store success score #success bs.data run data modify storage bs:out hitbox.offset set from storage bs:data hitbox.offsets[{k:[$(x),$(z)]}]
execute if score #success bs.data matches 0 run return fail
$execute store success score #s bs.ctx run data modify storage bs:out hitbox.offset set from storage bs:data hitbox.offsets[{k:[$(x),$(z)]}]
data remove storage bs:out hitbox.offset.k
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
# ------------------------------------------------------------------------------------------------------------

tp @s ~ ~ ~
execute store result score #hitbox.offset.x bs.data store result storage bs:ctx x int 1 run data get entity @s Pos[0]
execute store result score #hitbox.offset.z bs.data store result storage bs:ctx z int 1 run data get entity @s Pos[2]
execute store result score #u bs.ctx store result storage bs:ctx x int 1 run data get entity @s Pos[0]
execute store result score #v bs.ctx store result storage bs:ctx z int 1 run data get entity @s Pos[2]

execute store success score #success bs.data run function bs.hitbox:get_block/offset/fetch with storage bs:ctx
execute if score #success bs.data matches 0 run function bs.hitbox:get_block/offset/compute
function bs.hitbox:get_block/offset/fetch with storage bs:ctx
execute if score #s bs.ctx matches 0 run function bs.hitbox:get_block/offset/compute
execute in minecraft:overworld run tp @s -30000000 0 1600

execute if block ~ ~ ~ minecraft:pointed_dripstone run function bs.hitbox:get_block/offset/clamp {min:-1250000,max:1250000}

This file was deleted.

This file was deleted.

Loading
Loading