Skip to content

Commit

Permalink
feat: kill drawer entities if there is no players nearby
Browse files Browse the repository at this point in the history
  • Loading branch information
edayot committed Nov 1, 2023
1 parent 39465e2 commit dc85278
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 23 deletions.
1 change: 1 addition & 0 deletions data/simpledrawer/functions/impl/load.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ scoreboard objectives add simpledrawer.drawer.maxCount dummy
scoreboard objectives add simpledrawer.new_drawer.id dummy
scoreboard objectives add simpledrawer.new_drawer.part_id dummy
scoreboard objectives add simpledrawer.new_drawer.slot_count dummy
scoreboard objectives add simpledrawer.new_drawer.as_players_entities dummy

# Versioning block for future updates
scoreboard objectives add simpledrawer.block.major dummy
Expand Down
49 changes: 47 additions & 2 deletions data/simpledrawer/functions/impl/new_drawer/20tick.mcfunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@

execute if entity @s[tag=simpledrawer.new_drawer.to_update] if entity @a[distance=..15] run function simpledrawer:impl/new_drawer/base_display_rup
scoreboard players set #good_version simpledrawer.math 0
execute if entity @s[predicate=simpledrawer:impl/test_version] run scoreboard players set #good_version simpledrawer.math 1

execute if entity @s[predicate=!simpledrawer:impl/test_version] run function simpledrawer:impl/new_drawer/test_version
execute
if score #good_version simpledrawer.math matches 0
run function simpledrawer:impl/new_drawer/test_version


execute
if score #good_version simpledrawer.math matches 1
run function ./check_player_nearby:
scoreboard players set #player_nearby simpledrawer.math 0
execute if entity @a[distance=..16] run scoreboard players set #player_nearby simpledrawer.math 1

execute
if score #player_nearby simpledrawer.math matches 0
if score @s simpledrawer.new_drawer.as_players_entities matches 1
run function ./kill_player_entities:
scoreboard players operation #search_id simpledrawer.math = @s simpledrawer.new_drawer.id
kill @e[
tag=!simpledrawer.new_drawer.base,
tag=!simpledrawer.new_drawer.part.base_block,
tag=simpledrawer.new_drawer.part,
predicate=simpledrawer:impl/search_id_new_drawer
]
scoreboard players set @s simpledrawer.new_drawer.as_players_entities 0


execute
if score #player_nearby simpledrawer.math matches 1
if score @s simpledrawer.new_drawer.as_players_entities matches 0
run function ./resummon_player_entities:
data remove storage simpledrawer:main temp
data modify storage simpledrawer:main temp.simpledrawer set from storage simpledrawer:main ItemsNBT.new_drawer.tag.BlockEntityTag.Items[0].tag.simpledrawer
data modify storage simpledrawer:main temp.simpledrawer set from entity @s item.tag.simpledrawer
scoreboard players operation #place_id simpledrawer.math = @s simpledrawer.new_drawer.id
function simpledrawer:impl/new_drawer/place/variant
scoreboard players set @s simpledrawer.new_drawer.as_players_entities 1
function simpledrawer:impl/new_drawer/base_display_rup



execute
if score #player_nearby simpledrawer.math matches 1
if score @s simpledrawer.new_drawer.as_players_entities matches 1
if entity @s[tag=simpledrawer.new_drawer.to_update] run function simpledrawer:impl/new_drawer/base_display_rup

execute if entity @s[predicate=!simpledrawer:impl/test_version] run function simpledrawer:impl/new_drawer/test_version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
data modify storage simpledrawer:main temp.simpledrawerXX set from entity @s item.tag.simpledrawer


execute store success score #if_player_around simpledrawer.math if entity @a[distance=..15]
execute store success score #if_player_around simpledrawer.math if entity @a[distance=..16]

execute if score #if_player_around simpledrawer.math matches 0 run tag @s add simpledrawer.new_drawer.to_update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tag @s add simpledrawer.new_drawer.part.interaction
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.interaction
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.item_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.item_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tag @s add simpledrawer.new_drawer.part.maxcount
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math


tp @s ~ ~ ~ ~ ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tag @s add simpledrawer.new_drawer.part.text_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tag @s add simpledrawer.new_drawer.part.text_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.interaction
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.item_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tag @s add simpledrawer.new_drawer.part.maxcount
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math


tp @s ~ ~ ~ ~ ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tag @s add simpledrawer.new_drawer.part.text_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.hopper_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math


tp @s ~ ~ ~ ~180 ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.upgrade_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math


tp @s ~ ~ ~ ~180 ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tag @s add simpledrawer.new_drawer.base
tag @s add global.ignore
tag @s add simpledrawer.new_drawer.part
tag @s add simpledrawer.new_drawer.part.base
scoreboard players set @s simpledrawer.new_drawer.as_players_entities 1


execute if data storage simpledrawer:main temp.item.tag.simpledrawer{hopper:1b} run tag @s add simpledrawer.new_drawer.hopper
Expand All @@ -58,6 +59,7 @@ function #itemio:calls/container/init
tp @s ~ ~ ~ ~ ~


scoreboard players operation #place_id simpledrawer.math = @s simpledrawer.new_drawer.id
function simpledrawer:impl/new_drawer/place/variant

function simpledrawer:impl/new_drawer/base_display
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tag @s add simpledrawer.new_drawer.part.interaction
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tag @s add simpledrawer.new_drawer.part.item_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tag @s add simpledrawer.new_drawer.part.maxcount
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math


tp @s ~ ~ ~ ~ ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tag @s add simpledrawer.new_drawer.part.text_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.interaction
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tag @s add simpledrawer.new_drawer.part.item_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tag @s add simpledrawer.new_drawer.part.text_display
tag @s add smithed.entity
tag @s add smithed.strict

scoreboard players operation @s simpledrawer.new_drawer.id = #global simpledrawer.new_drawer.id
scoreboard players operation @s simpledrawer.new_drawer.id = #place_id simpledrawer.math
scoreboard players operation @s simpledrawer.new_drawer.part_id = #part_index simpledrawer.new_drawer.part_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ execute
scoreboard players set @s simpledrawer.block.patch 0


# 1.10.X to 1.11.0 => add score simpledrawer.as_players_entities
# all drawers have players entities in that time
execute
if score @s simpledrawer.block.major matches 1
if score @s simpledrawer.block.minor matches 10
if score @s simpledrawer.block.patch matches 0..
run function ./1.10_to_1.11:
scoreboard players set @s simpledrawer.as_players_entities 1
scoreboard players set @s simpledrawer.block.major 1
scoreboard players set @s simpledrawer.block.minor 11
scoreboard players set @s simpledrawer.block.patch 0



#copy the new version
Expand Down

0 comments on commit dc85278

Please sign in to comment.