Skip to content

Commit

Permalink
Update z_sleep for 1.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredNeil committed Sep 23, 2019
1 parent 49091b8 commit 5b55708
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions z_sleep/data/z_sleep/functions/main.mcfunction
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Reset
scoreboard players set #players_sleeping z_sleep 0
scoreboard players set z_players_sleeping z_sleep 0
scoreboard players set #players_slept z_sleep 0
scoreboard players set #percent_sleeping z_sleep 0
scoreboard players set #percent_slept z_sleep 0
tag @a remove z_sleep_sleeping

# Count players
execute as @a if data entity @s SleepingY run tag @s add z_sleep_sleeping
execute as @a store result score @s z_sleep run data get entity @s SleepTimer
execute as @a[nbt={Sleeping:1b}] run scoreboard players add #players_sleeping z_sleep 1
execute as @a[nbt={Sleeping:1b}] run scoreboard players add #percent_sleeping z_sleep 100
execute as @a[nbt={Sleeping:1b}] if score @s z_sleep matches 100.. run scoreboard players add #players_slept z_sleep 1
execute as @a[nbt={Sleeping:1b}] if score @s z_sleep matches 100.. run scoreboard players add #percent_slept z_sleep 100
execute as @a[tag=z_sleep_sleeping] run scoreboard players add z_players_sleeping z_sleep 1
execute as @a[tag=z_sleep_sleeping] run scoreboard players add #percent_sleeping z_sleep 100
execute as @a[tag=z_sleep_sleeping] if score @s z_sleep matches 100.. run scoreboard players add #players_slept z_sleep 1
execute as @a[tag=z_sleep_sleeping] if score @s z_sleep matches 100.. run scoreboard players add #percent_slept z_sleep 100

# Calculate percent sleeping/slept
scoreboard players operation #percent_sleeping z_sleep /= #players_overworld z_sleep
scoreboard players operation #percent_slept z_sleep /= #players_overworld z_sleep

# Send chat message every time someone starts sleeping
execute if entity @a[nbt={Sleeping:1b,SleepTimer:0s}] run function z_sleep:notify_sleep
execute if entity @a[tag=z_sleep_sleeping,nbt={SleepTimer:0s}] run function z_sleep:notify_sleep

# Wake players if someone clicked the trigger
execute as @a if score @s z_sleep_wake matches 1 run function z_sleep:wake_players
Expand Down
4 changes: 2 additions & 2 deletions z_sleep/data/z_sleep/functions/notify_sleep.mcfunction
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
execute if score #threshold_type z_sleep matches 0 run tellraw @a ["",{"score":{"name":"#players_sleeping","objective":"z_sleep"},"color":"gold"}," players (",{"selector":"@a[nbt={Sleeping:1b}]","color":"aqua"},") are now sleeping.\n",{"score":{"name":"#threshold_count","objective":"z_sleep"},"color":"gold"},{"text":" are required to pass the night."}]
execute if score #threshold_type z_sleep matches 0 run tellraw @a ["",{"score":{"name":"z_players_sleeping","objective":"z_sleep"},"color":"gold"}," players (",{"selector":"@a[tag=z_sleep_sleeping]","color":"aqua"},") are now sleeping.\n",{"score":{"name":"#threshold_count","objective":"z_sleep"},"color":"gold"},{"text":" are required to pass the night."}]

execute if score #threshold_type z_sleep matches 1 run tellraw @a ["",{"score":{"name":"#percent_sleeping","objective":"z_sleep"},"color":"gold"},{"text":"%","color":"gold"}," of overworld players (",{"selector":"@a[nbt={Sleeping:1b}]","color":"aqua"},") are now sleeping.\n",{"score":{"name":"#threshold_percent","objective":"z_sleep"},"color":"gold"},{"text":"%","color":"gold"},{"text":" are required to pass the night."}]
execute if score #threshold_type z_sleep matches 1 run tellraw @a ["",{"score":{"name":"#percent_sleeping","objective":"z_sleep"},"color":"gold"},{"text":"%","color":"gold"}," of overworld players (",{"selector":"@a[tag=z_sleep_sleeping]","color":"aqua"},") are now sleeping.\n",{"score":{"name":"#threshold_percent","objective":"z_sleep"},"color":"gold"},{"text":"%","color":"gold"},{"text":" are required to pass the night."}]

scoreboard players enable @a z_sleep_wake
tellraw @a ["Click ",{"text":"[here]","color":"blue","clickEvent":{"action":"run_command","value":"/trigger z_sleep_wake set 1"}}," to wake them from sleep."]
2 changes: 1 addition & 1 deletion z_sleep/data/z_sleep/functions/wake_players.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
execute at @a[nbt={Sleeping:1b}] run summon minecraft:snowball ~ ~0.6 ~ {Motion:[0.0,-1.0,0.0]}
execute as @a[tag=z_sleep_sleeping] run tp @s @s
tellraw @a ["",{"selector":"@s","color":"aqua"},{"text":" has stopped everyone from sleeping."}]
scoreboard players reset @a z_sleep_wake

0 comments on commit 5b55708

Please sign in to comment.