Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tests if non-player entities can hold scores. Default-config Spigot fails this test.
# @s = unspecified
# at unspecified
# run from modules which require this environment check

# if there is no recent echeck result, re-run echeck
execute unless score $score_on_non_player_entity gm4.environment_check_results matches 0.. summon marker run function gm4:environment_check/score_on_non_player_entity/assign_score

# return result
return run scoreboard players get $score_on_non_player_entity gm4.environment_check_results
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Assigns a score to this marker and reads it back. Kills the marker afterwards
# @s = test marker, just summoned
# at @s
# run from gm4:environment_check/score_on_non_player_entity

# set up marker
scoreboard players set @s gm4.environment_check_results 1
scoreboard players operation $score_on_non_player_entity gm4.environment_check_results = @s gm4.environment_check_results

# clean up marker
scoreboard players reset @s gm4.environment_check_results
kill @s
1 change: 1 addition & 0 deletions base/data/gm4/function/load.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ data modify storage gm4:log queue append value {type:"text",message:'{"text":"[G

scoreboard objectives add gm4_modules dummy
scoreboard objectives add gm4_data dummy
scoreboard objectives add gm4.environment_check_results dummy
function gm4:upgrade_paths/load

# Counts the number of consecutive reloads the player has not been seen in creative
Expand Down
1 change: 1 addition & 0 deletions base/data/gm4/function/log.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ execute if data storage gm4:log log{type:"install"} run tellraw @a[tag=gm4_show_
execute if data storage gm4:log log{type:"missing"} run tellraw @a[tag=gm4_show_log] [{"nbt":"log.module","storage":"gm4:log","color":"red"},{"text":" is disabled because ","color":"red"},{"nbt":"log.require","storage":"gm4:log","color":"red"},{"text":" is not installed."}]
execute if data storage gm4:log log{type:"outdated"} run function gm4:outdated_logs/outdated_start
execute if data storage gm4:log log{type:"version_conflict"} run function gm4:conflict_logs/version_conflict_start
execute if data storage gm4:log log{type:"environment_check_failed"} run tellraw @a[tag=gm4_show_log] [{"text":"Cancelled installation of ","color":"red"},{"nbt":"log.module","storage":"gm4:log"},{"text":" as the required environment check '","color":"red"},{"nbt":"log.environment_check","storage":"gm4:log"},{"text":"' failed!","color":"red"}]

data remove storage gm4:log queue[0]
execute store result score #log_size gm4_data run data get storage gm4:log queue
Expand Down
1 change: 1 addition & 0 deletions base/data/gm4/function/post_load.mcfunction
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scoreboard players reset * gm4.environment_check_results
execute unless data storage gm4:log queue[{type:"install"}] run data modify storage gm4:log queue append value {type:"text",message:'{"text":"[GM4]: No updates found.","color":"#4AA0C7"}'}
execute if data storage gm4:log queue[{type:"install"}] run data modify storage gm4:log queue append value {type:"text",message:'{"text":"[GM4]: Updates completed.","color":"#4AA0C7"}'}

Expand Down
21 changes: 21 additions & 0 deletions gm4/plugins/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class VersionInjectionConfig(PluginOptions):
advancements: list[str] = []

class VersioningConfig(PluginOptions, extra=Extra.ignore):
environment_checks: list[str] = []
schedule_loops: list[str] = []
required: dict[str, str] = {}
extra_version_injections: VersionInjectionConfig = Field(default=VersionInjectionConfig())
Expand Down Expand Up @@ -56,6 +57,26 @@ def modules(ctx: Context, opts: VersioningConfig):
lines.append(f"execute if score {dep_id} load.status matches 1.. unless score {dep_id} load.status matches {dep_ver.major} run data modify storage gm4:log queue append value {log_data}")
lines.append(f"execute if score {dep_id} load.status matches {dep_ver.major} unless score {dep_id}_minor load.status matches {dep_ver.minor}.. run data modify storage gm4:log queue append value {log_data}")

# add required environment checks
for namespaced_environment_check in opts.environment_checks:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost think we should only run environment checks on first install, instead of every reload? Also, we only need to perform each check once. Putting them into load makes each module run the same check again. Maybe we can finally utilize pre_load for this kind of setup check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would miss the edge case of importing an existing world to a new server.

Copy link
Member Author

@Bloo-dev Bloo-dev Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting them into load makes each module run the same check again

That's why these checks leave a score behind which is only reset post load. If the check was already done this reload, it won't need to check again and just uses the last result. That result is invalidated in post load, making sure the check is run again once next reload.

base_namespace = None
match namespaced_environment_check.split(":"):
case [check]:
namespace = ctx.project_id
case ["gm4", check]:
namespace = "gm4"
base_version = Version(base_ver)
base_namespace = f"gm4-{base_version.major}.{base_version.minor}" # NOTE this is a bit sketch. Does only base need this treatment? How do I know which namespaces need to be versioned for function calls? Or for scoreboards?
case [namespace, check]:
pass
case _:
raise ValueError(f"{namespaced_environment_check} is not a valid environment check name")

lines[0] += f"if function {namespace if not base_namespace else base_namespace}:environment_check/{check} "
lines[1] += f"if function {namespace if not base_namespace else base_namespace}:environment_check/{check} "
log_data = f"{{type:\"environment_check_failed\",module:\"{ctx.project_name}\",id:\"{ctx.project_id}\",environment_check:\"{namespace}:{check}\"}}"
lines.append(f"execute if score ${check} {namespace}.environment_check_results matches 0 run data modify storage gm4:log queue append value {log_data}")

# finalize startup check
module_ver = Version(ctx.project_version)
lines[1] = lines[0] + f"run scoreboard players set {ctx.project_id}_minor load.status {module_ver.minor}"
Expand Down
1 change: 1 addition & 0 deletions gm4_animi_shamir/beet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ meta:
required:
gm4_metallurgy: 1.4.0
lib_player_death: 1.2.0
environment_checks: [gm4:score_on_non_player_entity]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was your reasoning for making this configurable? Is there any reason we wouldn't want to just check the environment in every module, especially since they all use scoreboards to initialize through lantern load.

Copy link
Member Author

@Bloo-dev Bloo-dev Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's mostly true for this check, but not for all. E.g. lib_machines needs command blocks to be enabled, but most modules don't need that. The same goes for world gen stuff.

If we prompt users to enable those features instead of opening a bug report with us (which is the point of this endeavour), we should only do so if said feature is really needed.

schedule_loops: [main]
model_data:
- reference: shamir/animi
Expand Down
Loading