Skip to content

Commit 45f3b49

Browse files
committed
update day picked, create a dayline
1 parent 6359286 commit 45f3b49

20 files changed

+193
-134
lines changed

gm4_timelines/data/gm4_timelines/function/init.mcfunction

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ scoreboard players set timelines gm4_modules 1
44

55
scoreboard objectives add gm4_timelines.data dummy
66

7+
scoreboard players set #8 gm4_timelines.data 8
78
scoreboard players set #24000 gm4_timelines.data 24000
89

910
gamerule advance_weather false
1011

1112
function gm4_timelines:register/days
13+
execute store result score #day.offset gm4_timelines.data run data get storage gm4_timelines:data day_data.offset
14+
execute store result score #day.duration gm4_timelines.data run data get storage gm4_timelines:data day_data.duration
15+
16+
# TODO: only run this when needed, it resets everything to day 0
17+
function gm4_timelines:reset
1218

1319
schedule function gm4_timelines:main 1t
1420

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
schedule function gm4_timelines:main 16t
1+
schedule function gm4_timelines:main 1t
22

3-
execute store result score $daytime gm4_timelines.data run time query daytime
4-
execute store result score $day gm4_timelines.data run time query day
5-
scoreboard players operation $current_time gm4_timelines.data = $day gm4_timelines.data
6-
scoreboard players operation $current_time gm4_timelines.data *= #24000 gm4_timelines.data
7-
scoreboard players operation $current_time gm4_timelines.data += $daytime gm4_timelines.data
3+
execute store result score $day.real gm4_timelines.data run time query day
4+
execute store result score $daytime.real gm4_timelines.data run time query daytime
85

9-
scoreboard players operation $time_passed gm4_timelines.data = $current_time gm4_timelines.data
10-
scoreboard players operation $time_passed gm4_timelines.data -= $previous_time gm4_timelines.data
6+
scoreboard players operation $day.current gm4_timelines.data = $day.real gm4_timelines.data
7+
scoreboard players operation $day.current gm4_timelines.data *= #24000 gm4_timelines.data
8+
scoreboard players operation $day.current gm4_timelines.data += $daytime.real gm4_timelines.data
9+
scoreboard players operation $day.current gm4_timelines.data -= #day.offset gm4_timelines.data
10+
scoreboard players operation $daytime.current gm4_timelines.data = $day.current gm4_timelines.data
11+
scoreboard players operation $day.current gm4_timelines.data /= #day.duration gm4_timelines.data
12+
scoreboard players operation $daytime.current gm4_timelines.data %= #day.duration gm4_timelines.data
1113

12-
scoreboard players operation $previous_time gm4_timelines.data = $current_time gm4_timelines.data
13-
14-
scoreboard players operation $daytime_left gm4_timelines.data -= $time_passed gm4_timelines.data
15-
16-
execute unless score $daytime_left gm4_timelines.data matches 1.. run function gm4_timelines:pick_day/run
14+
execute unless score $day.active gm4_timelines.data = $day.current gm4_timelines.data run function gm4_timelines:pick_day/run
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
$execute store result score $picked_weight gm4_timelines.data run random value 0..$(max) gm4_timelines:pick_day
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
$data modify storage gm4_timelines:temp possible_days set from storage gm4_timelines:data day_data.registry.$(moon_phase).$(in_type)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
execute store result score $this_weight gm4_timelines.data run data get storage gm4_timelines:temp count_weight[0].weight
3+
scoreboard players operation $total_weight gm4_timelines.data += $this_weight gm4_timelines.data
4+
5+
data remove storage gm4_timelines:temp count_weight[0]
6+
execute if data storage gm4_timelines:temp count_weight[0] run function gm4_timelines:pick_day/build_dayline/loop_count_weights
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
# check moon cycle
3+
scoreboard players operation $moon_cycle gm4_timelines.data = $last_build_day gm4_timelines.data
4+
scoreboard players operation $moon_cycle gm4_timelines.data %= #8 gm4_timelines.data
5+
execute if score $moon_cycle gm4_timelines.data matches 0 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"full_moon",in_type:"clear"}
6+
execute if score $moon_cycle gm4_timelines.data matches 1 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"waning_gibbous",in_type:"clear"}
7+
execute if score $moon_cycle gm4_timelines.data matches 2 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"third_quarter",in_type:"clear"}
8+
execute if score $moon_cycle gm4_timelines.data matches 3 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"waning_crescent",in_type:"clear"}
9+
execute if score $moon_cycle gm4_timelines.data matches 4 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"new_moon",in_type:"clear"}
10+
execute if score $moon_cycle gm4_timelines.data matches 5 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"waxing_crescent",in_type:"clear"}
11+
execute if score $moon_cycle gm4_timelines.data matches 6 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"first_quarter",in_type:"clear"}
12+
execute if score $moon_cycle gm4_timelines.data matches 7 run data modify storage gm4_timelines:temp looking_for set value {moon_phase:"waxing_gibbous",in_type:"clear"}
13+
# check required in_type
14+
data modify storage gm4_timelines:temp looking_for.in_type set from storage gm4_timelines:data active_day.out_type
15+
# get possible days
16+
function gm4_timelines:pick_day/build_dayline/eval_possible_days with storage gm4_timelines:temp looking_for
17+
data remove storage gm4_timelines:temp looking_for
18+
19+
# get the total weight of all entries
20+
scoreboard players set $total_weight gm4_timelines.data 0
21+
data modify storage gm4_timelines:temp count_weight set from storage gm4_timelines:temp possible_days
22+
function gm4_timelines:pick_day/build_dayline/loop_count_weights
23+
data remove storage gm4_timelines:temp count_weight
24+
25+
# get a random weight between 0 and total weight
26+
execute store result storage gm4_timelines:temp rng.max int 1 run scoreboard players get $total_weight gm4_timelines.data
27+
function gm4_timelines:pick_day/build_dayline/eval_pick_weight with storage gm4_timelines:temp rng
28+
data remove storage gm4_timelines:temp rng
29+
30+
# loop to get the picked day and add it to they dayline
31+
execute if score $picked_weight gm4_timelines.data matches 1.. run function gm4_timelines:pick_day/build_dayline/loop_to_picked_day
32+
data modify storage gm4_timelines:data dayline append from storage gm4_timelines:temp possible_days[0]
33+
data remove storage gm4_timelines:temp possible_days
34+
35+
# continue doing this until we get to the desired day
36+
scoreboard players add $last_build_day gm4_timelines.data 1
37+
scoreboard players remove $days_forward gm4_timelines.data 1
38+
execute if score $days_forward gm4_timelines.data matches 1.. run function gm4_timelines:pick_day/build_dayline/loop_run
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
execute store result score $this_weight gm4_timelines.data run data get storage gm4_timelines:temp possible_days[0].weight
3+
scoreboard players operation $picked_weight gm4_timelines.data -= $this_weight gm4_timelines.data
4+
5+
execute if score $picked_weight gm4_timelines.data matches ..0 run return 1
6+
7+
data remove storage gm4_timelines:temp possible_days[0]
8+
execute if data storage gm4_timelines:temp possible_days[0] run function gm4_timelines:pick_day/build_dayline/loop_to_picked_day
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# data modify storage gm4_timelines:data active_day set from storage gm4_timelines:data day_registry[0]
3+
tellraw @a [{text:"[GM4 Timelines] ",color:"#4AA0C7"},{text:"No valid day found!",color:"red"}]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# first get the last day in the build timeline
3+
execute store result score $last_build_day gm4_timelines.data run data get storage gm4_timelines:data dayline
4+
5+
# check how many days should be build
6+
scoreboard players operation $days_forward gm4_timelines.data = $index_change gm4_timelines.data
7+
8+
# build at most 32 days
9+
execute if score $days_forward gm4_timelines.data matches 32.. run tellraw @a [{text:"[GM4 Timelines] ",color:"#4AA0C7"},{text:"Could only move 32 days into the future",color:"red"}]
10+
execute if score $days_forward gm4_timelines.data matches 32.. run scoreboard players set $index_change gm4_timelines.data 32
11+
execute if score $days_forward gm4_timelines.data matches 32.. run scoreboard players set $days_forward gm4_timelines.data 32
12+
13+
# get data from last build day
14+
data modify storage gm4_timelines:data active_day set from storage gm4_timelines:data dayline[-1]
15+
16+
# build the amount of needed days
17+
function gm4_timelines:pick_day/build_dayline/loop_run
18+
19+
# get the last day
20+
data modify storage gm4_timelines:data active_day set from storage gm4_timelines:data dayline[-1]
21+
scoreboard players operation $day.current gm4_timelines.data = $last_build_day gm4_timelines.data

gm4_timelines/data/gm4_timelines/function/pick_day/eval_day.mcfunction

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)