-
-
Notifications
You must be signed in to change notification settings - Fork 58
Environment Checks #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bloo-dev
wants to merge
7
commits into
Gamemode4Dev:master
Choose a base branch
from
Bloo-dev:environment-checks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+205
−0
Open
Environment Checks #1093
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fa4d298
Start Environment Check Framework
Bloo-dev c5d1627
Place gm4: EnvChecks in Folder & Leave Structure for Custom EnvChecks…
Bloo-dev 94b38a6
Use Storage Instead of Score
Bloo-dev da96da3
Move Test Check
Bloo-dev 7cb5406
Fix Typos
Bloo-dev 747eeaa
Add More Documentation
Bloo-dev 9087712
Even More Documentation
Bloo-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
base/data/gm4/function/environment_check/score_on_non_player_entity.mcfunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 data storage gm4:environment_checks result.score_on_non_player_entity summon marker run function gm4:environment_check/score_on_non_player_entity/assign_score | ||
|
||
# return result | ||
return run data get storage gm4:environment_checks result.score_on_non_player_entity.passed |
17 changes: 17 additions & 0 deletions
17
base/data/gm4/function/environment_check/score_on_non_player_entity/assign_score.mcfunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 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 & run test | ||
scoreboard players set @s gm4_data 1 | ||
|
||
# if the score is present, mark the check as passed | ||
execute if score @s gm4_data matches 1 run data modify storage gm4:environment_checks result set value {score_on_non_player_entity: {passed: 1b}} | ||
|
||
# (optional) if no score is present, provide a probable cause message to the user | ||
execute unless score @s gm4_data matches 1 run data modify storage gm4:environment_checks result set value {score_on_non_player_entity: {probable_cause: "This may be caused by the Paper/Spigot setting 'scoreboards.allow-non-player-entities-on-scoreboards=false'."}} | ||
|
||
# clean up marker | ||
scoreboard players reset @s gm4_data | ||
kill @s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# Utilities | ||
Chances are, the tough problem you are trying to tackle has been solved by someone else working on Gamemode 4 long before you did. | ||
This document will give you an overview of utilities and tools that have been developed over the years and which may help you when making a module. | ||
|
||
## Table of contents | ||
* [Common Tags](#common-tags) | ||
* [Blocks Tags](#block-tags) | ||
* [Entity Tags](#entity-tags) | ||
* [Environment Checks]() | ||
* [Base Checks]() | ||
* [Other Notable Checks]() | ||
* [Creating New Checks]() | ||
* [Upgrade Paths]() | ||
|
||
## Common Tags | ||
Selecting blocks or entities with common properties is an error prone task, and subsequent updates often miss module-specific, hardcoded tags. | ||
As such, `base` provides various tags that are maintained through updates and which should be prioritized over module-specific solutions. | ||
|
||
### Block Tags | ||
Gamemode 4's default block tags are located at `base/data/gm4/tags/block/`. | ||
|
||
| Tag Name | Source | Description | | ||
|---------------------|---------------------|------------------------------------------------------------------------------------------------------| | ||
| #gm4:air | air.json | All air types. | | ||
| #gm4:foliage | foliage.json | Naturally generating decoration on surfaces, which are easily broken, i.e. are washed away by water. | | ||
| #gm4:full_collision | full_collision.json | All blocks that have a full-block collision box. | | ||
| #gm4:no_collision | no_collision.json | All blocks without any collision, including air. | | ||
| #gm4:replaceable | replaceable.json | Blocks that can be replaced by placing another block inside it, including air. | | ||
| #gm4:water | water.json | Blocks that act as a water source. | | ||
| #gm4:waterloggable | waterloggable.json | Blocks which can be water-logged. | | ||
|
||
### Entity Tags | ||
Gamemode 4's default entity tags are located at `base/data/gm4/tags/block/`. | ||
|
||
| Tag Name | Source | Description | | ||
|----------------------|----------------------|--------------------------------------------------------------------------------------------------------------------------------------| | ||
| #gm4:boats | boats.json | All boat variations, including rafts. | | ||
| #gm4:boss | boss.json | Bosses, namely the Ender Dragon and the Wither. | | ||
| #gm4:chest_boats | chest_boats.json | All boat variations with a chest. | | ||
| #gm4:hostile | hostile.json | Living entities that are hostile towards player by default. | | ||
| #gm4:minecarts | minecarts.json | All minecart variations. | | ||
| #gm4:neutral_hostile | neutral_hostile.json | Hostile living entities that may be, given the right conditions, neutral towards the player by default but turn hostile if provoked. | | ||
| #gm4:neutral_passive | neutral_passive.json | Entities that are normally neutral, but turn hostile if provoked. | | ||
| #gm4:neutral | neutral.json | Entities that may be neutral given the right conditions. | | ||
| #gm4:non-living | non-living.json | Entities that are not considered living. | | ||
| #gm4:passive | passive.json | Entities that are normally friendly and do not turn hostile, even if provoked. | | ||
|
||
## Environment Checks | ||
The environment a data pack is installed into can affect its performance. | ||
Servers may have command blocks disabled, or mods may change the way the game reacts to changes made by commands. | ||
Not all users are aware of this, which can lead to rather frustrating debugging experiences. | ||
To counteract this, modules can include environment checks which warn the user and block installation of the data pack if certain conditions are not met. | ||
|
||
Environment checks are included by specifying them by name (including namespace) inside a module's `beet.yaml`, e.g. | ||
```yaml | ||
id: gm4_double_doors | ||
name: Double Doors | ||
version: 1.2.X | ||
|
||
data_pack: | ||
load: . | ||
|
||
require: | ||
- bolt | ||
|
||
pipeline: | ||
- gm4_double_doors.generate | ||
- gm4.plugins.extend.module | ||
|
||
meta: | ||
gm4: | ||
versioning: | ||
schedule_loops: [] | ||
|
||
# List of environment checks to include | ||
environment_checks: [gm4:score_on_non_player_entity] | ||
website: | ||
description: Tired of clicking twice to open a double door? Annoyed by the fact that doors are only two blocks tall? This data pack automatically opens adjacent doors, making double doors fully functional! Additionally, bottom trapdoors of matching wood type placed above a door are opened alongside the door when it is opened by a player. | ||
recommended: [] | ||
notes: [] | ||
modrinth: | ||
project_id: Vx4zJ1Np | ||
smithed: | ||
pack_id: gm4_double_doors | ||
video: null | ||
wiki: https://wiki.gm4.co/wiki/Double_Doors | ||
credits: | ||
Creator: | ||
- Bloo | ||
Icon Design: | ||
- venomousbirds | ||
``` | ||
|
||
Multiple checks may be included and are executed in-order: | ||
```yaml | ||
environment_checks: [gm4:score_on_non_player_entity, gm4_double_doors:bloo_is_not_online, lib_forceload:command_blocks_enabled] | ||
``` | ||
|
||
As shown above, environment checks are namespaced. If the namespace is omitted, the namespace of the parent module is used. | ||
|
||
Environment checks are run on every reload, with each check only running once per reload even if multiple modules require it. | ||
For testing purposes, environment checks may be bypassed by setting a positive test result before reloading data packs. | ||
To do this run | ||
```mcfunction | ||
/data modify storage {namespace}:environment_checks result.{check name}.passed set value 1b | ||
``` | ||
and run `/reload`. | ||
This has to be repeated before each reload. | ||
|
||
### Base Environment Checks | ||
`base` comes with some fundamental environment checks that can be referenced by the `gm4:` namespace. | ||
|
||
| Check Name | Description | | ||
|--------------------------------|--------------------------------------------------------------------------------------------------------------------------| | ||
| gm4:score_on_non_player_entity | Checks if non-player entities can be added to a scoreboard. Fails if a test marker's score can not be set and read back. | | ||
|
||
### Other Notable Environment Checks | ||
Some libraries also implement checks, which are inherited by all modules requiring said libraries, as a failed library install will prevent the dependent module from installing. | ||
Hence, you probably don't need to add these checks to your module if you already depend on the library. | ||
|
||
| Library | Check Name | Description | | ||
|---------------|----------------------------|---------------------------------------------------------------------------------------------------------------------| | ||
| lib_forceload | gm4:command_blocks_enabled | Checks if command blocks are enabled. Fails if the command block in the forceloaded chunk can not execute commands. | | ||
|
||
### Creating New Environment Checks | ||
Modules may also introduce their own environment checks. | ||
Any functions contained directly within the `function/environment_check/` folder of a module are treated as environment checks and may be mentioned within 'beet.yaml`. | ||
Functions in subfolders within `function/environment_check/` are ignored and can therefore be used as helper functions. | ||
|
||
To indicate a successful environment check include | ||
```mcfunction | ||
data modify storage <namespace>:environment_checks result set value {<check name>: {passed: 1b}} | ||
``` | ||
within your check, replacing `<namespace>` and `<check name>` with the module's namespace and the new check's name (identical to the file name without the `.mcfunction` suffix) respectively. | ||
Optionally, a failed environment check can display a message to the user by including | ||
```mcfunction | ||
data modify storage <namespace>:environment_checks result set value {<check name>: {probable_cause: "This may be caused by the programmer not expecting you to run this on a potato."}} | ||
``` | ||
within your check, once again replacing the `<namespace>` and `<check name>` with the module's and the new check's name respectively, as well as adding a more adequate message. | ||
|
||
Multiple modules may require the same environment check during a single reload. | ||
To cut down on lag, you should ensure your environment check tries to use a previous test result -- from the same `/reload` period -- before deciding to re-run the test. | ||
This can be done using | ||
```mcfunction | ||
execute unless data storage <namespace>:environment_checks result.<check name> | ||
``` | ||
You **must also clear all check results** in post-load. | ||
|
||
For a textbook example of an environment check, inspect `gm4:score_on_non_player_entity` in `base`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.