Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheThanathor committed Nov 14, 2023
2 parents 4e61c67 + 18ee74e commit 9484d91
Show file tree
Hide file tree
Showing 51 changed files with 1,132 additions and 68 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check and build modules
name: Build modules

on:
push:
Expand All @@ -11,19 +11,7 @@ env:
COMMIT_MSG: ${{ github.event.head_commit.message }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: mcbeet/check-commands@v1
with:
minecraft: '1.19' # temp manual assignment. mecha does not support 1.19.4 as valid version. ${{ env.VERSION }}
source: base gm4_* lib_*
version: '0.67.0'

build:
needs: test
runs-on: ubuntu-latest
concurrency:
group: ${{ github.event_name != 'pull_request' && 'release' || format('pr-{0}', github.event.number) }}
Expand Down
11 changes: 11 additions & 0 deletions gm4_bookshelf_inspector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Bookshelf Inspector<!--$headerTitle--><!--$pmc:delete-->

See what's in your Chiseled Bookshelves without having to take all the books out! <!--$pmc:headerSize-->

<img src="images/bookshelf_inspector.png" alt="Enchanted Books show Enchantments!" height="350"/> <!--$localAssetToURL--> <!--$modrinth:replaceWithVideo--> <!--$pmc:delete-->

### Features
- Stand still and look at a book in a Chiseled Bookshelf to see its name.
- Shows the enchantments on Enchanted Books.
- Shows the author for Written Books.
- Works in any language and supports custom formatting for the name!
23 changes: 23 additions & 0 deletions gm4_bookshelf_inspector/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
id: gm4_bookshelf_inspector
name: Bookshelf Inspector
version: 1.0.X

data_pack:
load: .

pipeline:
- gm4.plugins.extend.module

meta:
gm4:
versioning:
schedule_loops: [main]
website:
description: See what's in your Chiseled Bookshelves without having to take all the books out!
recommended: []
notes: []
video: null
wiki: https://wiki.gm4.co/wiki/Bookshelf_Inspector
credits:
Creator:
- Thanathor
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# use item_display transformation to calculate distance to point in 3D space
# @s = item_display
# at unspecified
# run from evaluate/position

# this method was made by 'Triton365' on the Minecraft Commands discord

# it works by setting the x,y,z co-ordinates of a point into the transformation of a display_entity
# This will force the scale[0] of that entity to = (x^2 + y^2 + z^2)^1/2
# This equals the distance in blocks between that point and 0,0,0
$data modify entity @s transformation set value [$(x)f,0f,0f,0f,$(y)f,0f,0f,0f,$(z)f,0f,0f,0f,0f,0f,0f,1f]

# this distance can then be stored in a scoreboard to check later
execute store result score $distance gm4_bookshelf_inspector_data run data get entity @s transformation.scale[0] 100

# cleanup
kill @s
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# spawn marker to get player position and rotation
# @s = marker
# at unspecified
# run from evaluate/position

tp @s @p[tag=gm4_bookshelf_inspector_target]
data modify storage gm4_bookshelf_inspector:temp entity_data set from entity @s
data modify storage gm4_bookshelf_inspector:temp Pos set from storage gm4_bookshelf_inspector:temp entity_data.Pos
data modify storage gm4_bookshelf_inspector:temp Rotation set from storage gm4_bookshelf_inspector:temp entity_data.Rotation
data remove storage gm4_bookshelf_inspector:temp entity_data
kill @s
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# check player motion
# @s = player not in spectator mode
# at unspecified
# run from evaluate/run

# store player position and rotation using a marker to avoid reading player NBT
tag @s add gm4_bookshelf_inspector_target
execute summon marker run function gm4_bookshelf_inspector:evaluate/get_pos
tag @s remove gm4_bookshelf_inspector_target

# calculate how far player has moved since last check
# first, get the players current position from storage
execute store result score $pos_x gm4_bookshelf_inspector_data run data get storage gm4_bookshelf_inspector:temp Pos[0] 1000
execute store result score $pos_y gm4_bookshelf_inspector_data run data get storage gm4_bookshelf_inspector:temp Pos[1] 1000
execute store result score $pos_z gm4_bookshelf_inspector_data run data get storage gm4_bookshelf_inspector:temp Pos[2] 1000
# store the distance between that and the position last tick in a float value
scoreboard players operation $distance_x gm4_bookshelf_inspector_data = $pos_x gm4_bookshelf_inspector_data
scoreboard players operation $distance_y gm4_bookshelf_inspector_data = $pos_y gm4_bookshelf_inspector_data
scoreboard players operation $distance_z gm4_bookshelf_inspector_data = $pos_z gm4_bookshelf_inspector_data
execute store result storage gm4_bookshelf_inspector:temp distance_calc.x float 0.001 run scoreboard players operation $distance_x gm4_bookshelf_inspector_data -= @s gm4_bookshelf_inspector_last_pos_x
execute store result storage gm4_bookshelf_inspector:temp distance_calc.y float 0.001 run scoreboard players operation $distance_y gm4_bookshelf_inspector_data -= @s gm4_bookshelf_inspector_last_pos_y
execute store result storage gm4_bookshelf_inspector:temp distance_calc.z float 0.001 run scoreboard players operation $distance_z gm4_bookshelf_inspector_data -= @s gm4_bookshelf_inspector_last_pos_z
# use item_display transformation to calculate the distance
execute summon item_display run function gm4_bookshelf_inspector:evaluate/calc_distance with storage gm4_bookshelf_inspector:temp distance_calc
# store the current position for the next tick
scoreboard players operation @s gm4_bookshelf_inspector_last_pos_x = $pos_x gm4_bookshelf_inspector_data
scoreboard players operation @s gm4_bookshelf_inspector_last_pos_y = $pos_y gm4_bookshelf_inspector_data
scoreboard players operation @s gm4_bookshelf_inspector_last_pos_z = $pos_z gm4_bookshelf_inspector_data

# if motion was detected set a full cooldown on displaying nametags
# if the player was looking at a bookshelf and the motion was subtle ignore it (to avoid small nudges removing the display)
execute unless score @s gm4_bookshelf_inspector_standing_still matches 8.. if score $distance gm4_bookshelf_inspector_data matches 1.. run scoreboard players set $evaluate gm4_bookshelf_inspector_data -1
execute if score @s gm4_bookshelf_inspector_standing_still matches 8.. if score $distance gm4_bookshelf_inspector_data matches 16.. run scoreboard players set $evaluate gm4_bookshelf_inspector_data -1

# cleanup
data remove storage gm4_bookshelf_inspector:temp Pos

# if player had no motion check rotation
execute if score $evaluate gm4_bookshelf_inspector_data matches 1 run function gm4_bookshelf_inspector:evaluate/rotation
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# check player rotation
# @s = player not in spectator mode
# at unspecified
# run from evaluate/position

# read player rotation into scores from storage
execute store result score $yaw gm4_bookshelf_inspector_data run data get storage gm4_bookshelf_inspector:temp Rotation[0]
execute store result score $pitch gm4_bookshelf_inspector_data run data get storage gm4_bookshelf_inspector:temp Rotation[1]
data remove storage gm4_bookshelf_inspector:temp Rotation

# check if pitch and yaw have stayed the same since last check
execute store success score $evaluate gm4_bookshelf_inspector_data if score $pitch gm4_bookshelf_inspector_data = @s gm4_bookshelf_inspector_pitch
execute if score $evaluate gm4_bookshelf_inspector_data matches 1 store success score $evaluate gm4_bookshelf_inspector_data if score $yaw gm4_bookshelf_inspector_data = @s gm4_bookshelf_inspector_yaw

# store player rotation in scores for future checks
scoreboard players operation @s gm4_bookshelf_inspector_pitch = $pitch gm4_bookshelf_inspector_data
scoreboard players operation @s gm4_bookshelf_inspector_yaw = $yaw gm4_bookshelf_inspector_data

# if player had no rotation add to their standing_still score
execute if score $evaluate gm4_bookshelf_inspector_data matches 1 run scoreboard players add @s gm4_bookshelf_inspector_standing_still 1

# if player has not moved for 0.5s and not rotated for 0.1s check for chiseled bookshelves
# evaluation is not checked here, this means that if you don't move rotation will not reset the 0.1s as long as you keep looking
# at a chiseled bookshelf, making scanning shelves nicer
execute if score @s gm4_bookshelf_inspector_standing_still matches 10.. run function gm4_bookshelf_inspector:find_book/prep
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# run evaluation to see if player is not moving
# @s = player not in spectator mode
# at unspecified
# run from main

scoreboard players set $evaluate gm4_bookshelf_inspector_data 1

# check often used transportation methods for movement to skip costly nbt checks
# if player was standing still don't let walking (being nudged) fail the evaluation
execute if score @s gm4_bookshelf_inspector_walk matches 1.. unless score @s gm4_bookshelf_inspector_standing_still matches 8.. run scoreboard players set $evaluate gm4_bookshelf_inspector_data -1
execute if score @s gm4_bookshelf_inspector_sprint matches 1.. run scoreboard players set $evaluate gm4_bookshelf_inspector_data -1
execute if score @s gm4_bookshelf_inspector_fall matches 1.. run scoreboard players set $evaluate gm4_bookshelf_inspector_data -1

# check if player has motion
execute if score $evaluate gm4_bookshelf_inspector_data matches 1 run function gm4_bookshelf_inspector:evaluate/position

# if evaluation failed set player standing_still score to 8 if no movement happened, or to 0 if movement happened
execute if score $evaluate gm4_bookshelf_inspector_data matches 0 run scoreboard players set @s[scores={gm4_bookshelf_inspector_standing_still=9..}] gm4_bookshelf_inspector_standing_still 8
execute if score $evaluate gm4_bookshelf_inspector_data matches -1 run scoreboard players reset @s gm4_bookshelf_inspector_standing_still

# cleanup scores
scoreboard players reset @s gm4_bookshelf_inspector_walk
scoreboard players reset @s gm4_bookshelf_inspector_sprint
scoreboard players reset @s gm4_bookshelf_inspector_fall
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# collect data on the looked at book
# @s = player not in spectator mode
# positioned ^ ^ ^-0.05 before chiseled bookshelf
# run from find_book/raycast

# stop the raycast
scoreboard players set $raycast gm4_bookshelf_inspector_data 0

# set evaluate to 1 in case rotation changed but this still ran
scoreboard players set $evaluate gm4_bookshelf_inspector_data 1

# get the slot being looked at
execute summon marker run function gm4_bookshelf_inspector:find_book/get_book_slot

# if evaluation failed stop the function
execute if score $evaluate gm4_bookshelf_inspector_data matches 0 run return 0

# store book data in storage
# NOTE: should this use macro's? It doesn't seem worth it here but not sure how efficient they are
execute if score $rotation gm4_bookshelf_inspector_data matches 1 run data modify storage gm4_bookshelf_inspector:temp book_data set from block ~ ~ ~-1 Items
execute if score $rotation gm4_bookshelf_inspector_data matches 2 run data modify storage gm4_bookshelf_inspector:temp book_data set from block ~ ~ ~1 Items
execute if score $rotation gm4_bookshelf_inspector_data matches 3 run data modify storage gm4_bookshelf_inspector:temp book_data set from block ~-1 ~ ~ Items
execute if score $rotation gm4_bookshelf_inspector_data matches 4 run data modify storage gm4_bookshelf_inspector:temp book_data set from block ~1 ~ ~ Items
execute if score $book_slot gm4_bookshelf_inspector_data matches 0 run data modify storage gm4_bookshelf_inspector:temp book_data set from storage gm4_bookshelf_inspector:temp book_data[{Slot:0b}]
execute if score $book_slot gm4_bookshelf_inspector_data matches 1 run data modify storage gm4_bookshelf_inspector:temp book_data set from storage gm4_bookshelf_inspector:temp book_data[{Slot:1b}]
execute if score $book_slot gm4_bookshelf_inspector_data matches 2 run data modify storage gm4_bookshelf_inspector:temp book_data set from storage gm4_bookshelf_inspector:temp book_data[{Slot:2b}]
execute if score $book_slot gm4_bookshelf_inspector_data matches 3 run data modify storage gm4_bookshelf_inspector:temp book_data set from storage gm4_bookshelf_inspector:temp book_data[{Slot:3b}]
execute if score $book_slot gm4_bookshelf_inspector_data matches 4 run data modify storage gm4_bookshelf_inspector:temp book_data set from storage gm4_bookshelf_inspector:temp book_data[{Slot:4b}]
execute if score $book_slot gm4_bookshelf_inspector_data matches 5 run data modify storage gm4_bookshelf_inspector:temp book_data set from storage gm4_bookshelf_inspector:temp book_data[{Slot:5b}]

# check if slot actually has a book, otherwise stop the function
# this does not fail evaluation, so there is no delay in case the player is scanning over a half-filled bookshelf
execute unless data storage gm4_bookshelf_inspector:temp book_data.id run return 0

# find top-left location of this chiseled bookshelf
# 1=north / 2=south / 3=west / 4=east (this is facing direction, so you look against the opposite side of the block)
execute if score $rotation gm4_bookshelf_inspector_data matches 1 positioned ~ ~ ~-1 align xyz positioned ~0.1875 ~0.5625 ~1.001 rotated 0 0 run function gm4_bookshelf_inspector:process_display/locate_slot
execute if score $rotation gm4_bookshelf_inspector_data matches 2 positioned ~ ~ ~1 align xyz positioned ~0.8125 ~0.5625 ~-0.001 rotated 180 0 run function gm4_bookshelf_inspector:process_display/locate_slot
execute if score $rotation gm4_bookshelf_inspector_data matches 3 positioned ~-1 ~ ~ align xyz positioned ~1.001 ~0.5625 ~0.8125 rotated -90 0 run function gm4_bookshelf_inspector:process_display/locate_slot
execute if score $rotation gm4_bookshelf_inspector_data matches 4 positioned ~1 ~ ~ align xyz positioned ~-0.001 ~0.5625 ~0.1875 rotated 90 0 run function gm4_bookshelf_inspector:process_display/locate_slot

# cleanup storage
data remove storage gm4_bookshelf_inspector:temp book_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# check which book slot is being looked at
# @s = marker
# at chiseled bookshelf
# run from find_book/find_book

# get y position relative to the block
execute store result score $y gm4_bookshelf_inspector_data run data get entity @s Pos[1] 100
scoreboard players operation $y gm4_bookshelf_inspector_data %= #100 gm4_bookshelf_inspector_data

# check rotation from stored player yaw and transform it into a score
# 1=north / 2=south / 3=west / 4=east
scoreboard players operation $rotation gm4_bookshelf_inspector_data = $yaw gm4_bookshelf_inspector_data
execute if score $rotation gm4_bookshelf_inspector_data matches -45..44 run scoreboard players set $rotation gm4_bookshelf_inspector_data 2
execute if score $rotation gm4_bookshelf_inspector_data matches -135..-45 run scoreboard players set $rotation gm4_bookshelf_inspector_data 4
execute if score $rotation gm4_bookshelf_inspector_data matches 45..135 run scoreboard players set $rotation gm4_bookshelf_inspector_data 3
execute unless score $rotation gm4_bookshelf_inspector_data matches 2..4 run scoreboard players set $rotation gm4_bookshelf_inspector_data 1

# check if bookshelf is rotated correctly
execute if score $rotation gm4_bookshelf_inspector_data matches 1 unless block ~ ~ ~-1 chiseled_bookshelf[facing=south] run scoreboard players set $evaluate gm4_bookshelf_inspector_data 0
execute if score $rotation gm4_bookshelf_inspector_data matches 2 unless block ~ ~ ~1 chiseled_bookshelf[facing=north] run scoreboard players set $evaluate gm4_bookshelf_inspector_data 0
execute if score $rotation gm4_bookshelf_inspector_data matches 3 unless block ~-1 ~ ~ chiseled_bookshelf[facing=east] run scoreboard players set $evaluate gm4_bookshelf_inspector_data 0
execute if score $rotation gm4_bookshelf_inspector_data matches 4 unless block ~1 ~ ~ chiseled_bookshelf[facing=west] run scoreboard players set $evaluate gm4_bookshelf_inspector_data 0
# stop if evaluation failed
execute if score $evaluate gm4_bookshelf_inspector_data matches 0 run kill @s
execute if score $evaluate gm4_bookshelf_inspector_data matches 0 run return 0

# check if the marker is located on the front face of the bookshelf
execute if score $rotation gm4_bookshelf_inspector_data matches 1..2 store result score $face_check gm4_bookshelf_inspector_data run data get entity @s Pos[2] 100
execute if score $rotation gm4_bookshelf_inspector_data matches 3..4 store result score $face_check gm4_bookshelf_inspector_data run data get entity @s Pos[0] 100
scoreboard players operation $face_check gm4_bookshelf_inspector_data %= #100 gm4_bookshelf_inspector_data
execute unless score $face_check gm4_bookshelf_inspector_data matches 0..5 unless score $face_check gm4_bookshelf_inspector_data matches 94..99 run scoreboard players set $evaluate gm4_bookshelf_inspector_data 0
# stop if evaluation failed
execute if score $evaluate gm4_bookshelf_inspector_data matches 0 run kill @s
execute if score $evaluate gm4_bookshelf_inspector_data matches 0 run return 0

# store either the x or z coord depending on player facing
execute if score $rotation gm4_bookshelf_inspector_data matches 1..2 store result score $xz gm4_bookshelf_inspector_data run data get entity @s Pos[0] 100
execute if score $rotation gm4_bookshelf_inspector_data matches 3..4 store result score $xz gm4_bookshelf_inspector_data run data get entity @s Pos[2] 100
scoreboard players operation $xz gm4_bookshelf_inspector_data %= #100 gm4_bookshelf_inspector_data

# book slots:
# 0 1 2
# 3 4 5
scoreboard players set $book_slot gm4_bookshelf_inspector_data 0
execute if score $xz gm4_bookshelf_inspector_data matches 33.. unless score $rotation gm4_bookshelf_inspector_data matches 2..3 run scoreboard players add $book_slot gm4_bookshelf_inspector_data 1
execute if score $xz gm4_bookshelf_inspector_data matches 66.. unless score $rotation gm4_bookshelf_inspector_data matches 2..3 run scoreboard players add $book_slot gm4_bookshelf_inspector_data 1
execute if score $xz gm4_bookshelf_inspector_data matches ..33 if score $rotation gm4_bookshelf_inspector_data matches 2..3 run scoreboard players add $book_slot gm4_bookshelf_inspector_data 1
execute if score $xz gm4_bookshelf_inspector_data matches ..66 if score $rotation gm4_bookshelf_inspector_data matches 2..3 run scoreboard players add $book_slot gm4_bookshelf_inspector_data 1
execute if score $y gm4_bookshelf_inspector_data matches ..50 run scoreboard players add $book_slot gm4_bookshelf_inspector_data 3

# remove marker
kill @s
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# prep looking for a looked at book
# @s = player not in spectator mode
# at unspecified
# run from evaluate/rotation

scoreboard players set $raycast gm4_bookshelf_inspector_data 50
execute at @s anchored eyes positioned ^ ^ ^1 run function gm4_bookshelf_inspector:find_book/raycast
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# raycast for a chiseled bookshelf
# @s = player not in spectator mode
# at @s anchored eyes, positioned ^ ^ ^1 + 0.05x (x = 0..50)
# run from find_book/prep
# run from here

scoreboard players remove $raycast gm4_bookshelf_inspector_data 1

# check for bookshelf slightly up ahead
execute if block ^ ^ ^0.0501 chiseled_bookshelf run function gm4_bookshelf_inspector:find_book/find_book

# if a block is hit stop the raycast
execute unless block ~ ~ ~ #gm4:no_collision run scoreboard players set $raycast gm4_bookshelf_inspector_data 0

execute if score $raycast gm4_bookshelf_inspector_data matches 1.. positioned ^ ^ ^0.05 run function gm4_bookshelf_inspector:find_book/raycast
Loading

0 comments on commit 9484d91

Please sign in to comment.