Skip to content

Commit

Permalink
Eventify item frame reparse
Browse files Browse the repository at this point in the history
- Item frame reparse now triggers when a player right-clicks on an item frame or when an item drops nearby in versions before 24w11a. Global reparse loop now only triggers every 4 seconds instead of every 8 ticks.
This should improve performance in regions with a high number of item frames while also improving responsiveness (first steps for #13)
- Added support for falling blocks and display entities in versions before 24w11a
- Updated GitHub workflow
  • Loading branch information
Tschipcraft committed Mar 31, 2024
1 parent 0932c1a commit a6ec58a
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 16 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
name: Build and publish project
steps:
- name: Checkout code
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
with:
show-progress: false
- name: Extract tag
id: tag_version
run: echo "TAG_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
Expand All @@ -39,21 +42,27 @@ jobs:
find: "${version}"
replace: ${{ github.event.inputs.tag }}
regex: false
- name: Find and replace supported mc versions
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "${mc_version}"
replace: ${{ github.event.inputs.mc_version }}
regex: false

# Check for existence of datapack, mod and/or resourcepack folders.
- name: Check for data folder
id: check_datapack_folder
uses: andstor/file-existence-action@v2
uses: andstor/file-existence-action@v3
with:
files: "data"
- name: Check for mod folders
id: check_mod_folder
uses: andstor/file-existence-action@v2
uses: andstor/file-existence-action@v3
with:
files: "META-INF, net, fabric.mod.json, assets"
- name: Check for resource pack folder
id: check_assets_folder
uses: andstor/file-existence-action@v2
uses: andstor/file-existence-action@v3
with:
files: "assets/minecraft"

Expand Down
20 changes: 20 additions & 0 deletions data/dynamiclights/advancements/interacted_with_item_frame.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"criteria": {
"player_interacted": {
"trigger": "minecraft:player_interacted_with_entity",
"conditions": {
"entity": {
"type": "#dynamiclights:reparse_interactible"
}
}
}
},
"requirements": [
[
"player_interacted"
]
],
"rewards": {
"function": "dynamiclights:internal/item_frame/interacted"
}
}
3 changes: 3 additions & 0 deletions data/dynamiclights/functions/install.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ scoreboard objectives add tvc_ignore dummy
# 17 for v1.7
scoreboard players set dynamiclights load.status 17

# Reset advancement
advancement revoke @a only dynamiclights:interacted_with_item_frame

## Schedule functions
schedule function dynamiclights:internal/main 5t
schedule function dynamiclights:internal/loop 4t
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
##by Tschipcraft
# This function triggers whenever a player interacts with an item frame. It schedules a reparse of all near item frames for changed items.

scoreboard players reset @e[type=#dynamiclights:reparse_interactible,distance=..7] ts.dl.i.type

advancement revoke @s only dynamiclights:interacted_with_item_frame
2 changes: 1 addition & 1 deletion data/dynamiclights/functions/internal/loop.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

scoreboard players reset @e[type=#dynamiclights:reparse] ts.dl.i.type

schedule function dynamiclights:internal/loop 8t
schedule function dynamiclights:internal/loop 4s
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
##by Tschipcraft

execute as @s[type=minecraft:item_display] run data modify entity c295ddee-4c15-4e5b-83ba-2fbce873a1d5 HandItems[0] set from entity @s item
execute as @s[type=minecraft:block_display] run data modify entity c295ddee-4c15-4e5b-83ba-2fbce873a1d5 HandItems[0].id set from entity @s block_state.Name
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
##by Tschipcraft
# TODO: Change behavior; killing and resummoning armor stand in the same tick could lead to UUID conflicts

summon armor_stand ~ ~ ~ {UUID:[I;-1030365714,1276464731,-2084950084,-395075115],NoGravity:1b,Silent:1b,Invulnerable:1b,Small:1b,Marker:1b,Invisible:1b,NoBasePlate:1b,Tags:["ts.dl.i.parser"],DisabledSlots:4144959}
summon armor_stand ~ ~ ~ {UUID:[I;-1030365714,1276464731,-2084950084,-395075115],NoGravity:1b,Silent:1b,Invulnerable:1b,Small:1b,Marker:1b,Invisible:1b,NoBasePlate:1b,Tags:["ts.dl.i.parser"],HandItems:[{id:"minecraft:structure_void",Count:1b},{}],DisabledSlots:4144959}

# Copy NBT data
execute as @s[type=minecraft:item] run data modify entity c295ddee-4c15-4e5b-83ba-2fbce873a1d5 HandItems[0] set from entity @s Item
execute as @s[type=minecraft:item_frame] run data modify entity c295ddee-4c15-4e5b-83ba-2fbce873a1d5 HandItems[0] set from entity @s Item
#execute as @s[type=minecraft:item_display] run data modify entity c295ddee-4c15-4e5b-83ba-2fbce873a1d5 HandItems[0] set from entity @s item
# TODO: Extra cases for block display and falling blocks (BlockState:{Name:""})
execute as @s[type=minecraft:glow_item_frame] run data modify entity c295ddee-4c15-4e5b-83ba-2fbce873a1d5 HandItems[0] set from entity @s Item
execute as @s[type=minecraft:falling_block] run data modify entity c295ddee-4c15-4e5b-83ba-2fbce873a1d5 HandItems[0].id set from entity @s BlockState.Name
# Extra case for item and block display entities
function dynamiclights:internal/sources/parse/extension_1194

execute as c295ddee-4c15-4e5b-83ba-2fbce873a1d5 run function dynamiclights:internal/sources/parse/main_exec

Expand All @@ -18,3 +19,6 @@ scoreboard players operation @s ts.dl.i.is_ameth = .global ts.dl.i.is_ameth
scoreboard players operation @s ts.dl.i.is_firea = .global ts.dl.i.is_firea
scoreboard players operation @s ts.dl.i.is_ript = .global ts.dl.i.is_ript
scoreboard players operation @s ts.dl.i.is_chann = .global ts.dl.i.is_chann

# Check for nearby item frames to reparse
execute if score @s ts.dl.i.type matches 1.. as @s[type=minecraft:item] run scoreboard players reset @e[type=#dynamiclights:reparse_interactible,distance=..2] ts.dl.i.type
3 changes: 3 additions & 0 deletions data/dynamiclights/functions/reset.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ kill @e[type=minecraft:armor_stand,tag=ts.dl.i.parser]
# Reset explosion alarm
function dynamiclights:internal/explosion_detection/reset

# Reset advancement
advancement revoke @a only dynamiclights:interacted_with_item_frame

# Reschedule functions
schedule function dynamiclights:internal/main 5t
schedule function dynamiclights:internal/loop 4t
Expand Down
8 changes: 4 additions & 4 deletions data/dynamiclights/tags/entity_types/parse.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"//comment": "These entities use a different NBT tag for storing the item and need special parsing for detection",
"//comment": "These entities use a different NBT tag for storing their item and need special parsing for detection.",
"replace": false,
"values": [
"#dynamiclights:reparse",
"minecraft:item",
"minecraft:item_frame",
"minecraft:glow_item_frame",
{"id": "minecraft:item_display", "required": false}
"minecraft:falling_block",
{"id": "minecraft:block_display", "required": false}
]
}
5 changes: 2 additions & 3 deletions data/dynamiclights/tags/entity_types/reparse.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"//comment": "These entities are dynamic item holders and may change their item over time. They will get reparsed every 8 ticks",
"//comment": "These entities need special parsing and are dynamic item holders, meaning that they may change their item over time. They will get reparsed every 4 seconds by default.",
"replace": false,
"values": [
"minecraft:item_frame",
"minecraft:glow_item_frame",
"#dynamiclights:reparse_interactible",
{"id": "minecraft:item_display", "required": false}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"//comment": "These entities need special parsing and are dynamic item holders, meaning that they may change their item over time. They are interactible by players and should listen to player interact events.",
"replace": false,
"values": [
"minecraft:item_frame",
"minecraft:glow_item_frame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"criteria": {
"player_interacted": {
"trigger": "minecraft:impossible"
}
},
"rewards": {
"function": "dynamiclights:internal/item_frame/interacted"
}
}

0 comments on commit a6ec58a

Please sign in to comment.