Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheThanathor committed Feb 15, 2024
2 parents cbf1c41 + 68a6e8d commit 2d06ad3
Show file tree
Hide file tree
Showing 224 changed files with 1,661 additions and 1,085 deletions.
64 changes: 60 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
env:
VERSION: '1.20'
COMMIT_MSG: ${{ github.event.head_commit.message }}
TEST_FABRIC_SERVER: https://meta.fabricmc.net/v2/versions/loader/1.20.4/0.15.3/0.11.2/server/jar
TEST_FABRIC_API: https://cdn.modrinth.com/data/P7dR8mSH/versions/JMCwDuki/fabric-api-0.92.0%2B1.20.4.jar
TEST_PACKTEST: https://cdn.modrinth.com/data/XsKUhp45/versions/18smpIeE/packtest-1.6-mc1.20.4.jar

jobs:
build:
Expand All @@ -29,8 +32,8 @@ jobs:
if: github.event_name == 'pull_request'
run: git fetch origin ${{ github.base_ref }}

- name: Set up Python 3.10
uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand All @@ -41,7 +44,7 @@ jobs:

- name: Setup cache
id: cached-poetry-dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
Expand All @@ -66,7 +69,7 @@ jobs:

- name: Upload artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: 'Modules for pull request #${{ github.event.number }}'
path: ${{ github.workspace }}/release/${{ env.VERSION }}/
Expand All @@ -87,3 +90,56 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: release
branch: release

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install Poetry
uses: snok/[email protected]
with:
virtualenvs-in-project: true

- name: Setup cache
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install

- name: Build all modules for tests
run: poetry run beet -p beet-test.yaml -l ${{ env.LOG_LEVEL }} build
env:
LOG_LEVEL: ${{ runner.debug == 1 && 'DEBUG' || 'INFO'}}

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Download server files
run: |
curl -o server.jar $TEST_FABRIC_SERVER
mkdir mods
curl -o mods/fabric-api.jar $TEST_FABRIC_API
curl -o mods/packtest.jar $TEST_PACKTEST
- name: Copy packs to world
run: |
mkdir -p world/datapacks
cp out/gm4_*.zip world/datapacks
- name: Run test server
run: |
java -Xmx2G -Dpacktest.auto -Dpacktest.auto.annotations -jar server.jar nogui
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ kill @s
### Guidebook Pages
Each Gamemode 4 module must include guidebook pages to aid in the explaination and progression of the module. Details on how to add a section to the guidebook can be found in [`gm4_guidebook/CONTRIBUTING.md`](https://github.com/Gamemode4Dev/GM4_Datapacks/blob/master/gm4_guidebook/CONTRIBUTING.md).

### Tests
Automated tests for modules should be added in the `data/gm4_module_id/tests` folder. The tests will automatically run in GitHub Actions when you submit a PR. For local development and for the full documentation, see the [PackTest](https://github.com/misode/packtest) project.

### Submitting your module
Make sure to credit all relevant people in `beet.yaml`. Most modules credit the creator (`Creator`), updaters (`Updated by`) and the icon designer (`Icon Design`), however, you may add credits for any work relevant to the module. Each credits section consists of an array of strings, which hold the names of the contributors. To add a link to your social media site of choice add an entry to `contributors.json`.

Expand Down
Binary file added base/data/gm4/structures/test_box.nbt
Binary file not shown.
Binary file added base/data/gm4/structures/test_platform.nbt
Binary file not shown.
Binary file added base/data/gm4/structures/test_tube.nbt
Binary file not shown.
2 changes: 2 additions & 0 deletions base/data/gm4/tags/blocks/waterloggable.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"values": [
"#minecraft:rails",
"#minecraft:campfires",
"#minecraft:candles",
"#minecraft:fences",
Expand Down Expand Up @@ -50,6 +51,7 @@
"minecraft:light_gray_stained_glass_pane",
"minecraft:lime_stained_glass_pane",
"minecraft:magenta_stained_glass_pane",
"minecraft:mangrove_propagule",
"minecraft:mangrove_roots",
"minecraft:medium_amethyst_bud",
"minecraft:orange_stained_glass_pane",
Expand Down
3 changes: 3 additions & 0 deletions beet-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ignore:
- gm4/skin_cache.json

pipeline:
- gm4.plugins.list_modules
- gm4.plugins.manifest.create
Expand Down
1 change: 1 addition & 0 deletions beet-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pipeline:
- gm4_guidebook.generate_guidebooks.load_page_data
- gm4_guidebook.generate_guidebooks.load_custom_recipes
pipeline:
- gm4.plugins.test.strip_tests
- gm4.plugins.manifest.write_updates
- gm4.plugins.manifest.write_credits
- require: [beet.contrib.copy_files]
Expand Down
26 changes: 26 additions & 0 deletions beet-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pipeline:
- gm4.plugins.list_modules
- gm4.plugins.manifest.create
- gm4.plugins.manifest.update_patch
- gm4.plugins.output.clear_release
- gm4.plugins.manifest.write_meta
- broadcast: 'gm4_*'
extend: 'beet.yaml'
require:
- gm4.plugins.output.test
- gm4.plugins.player_heads
- gm4_guidebook.generate_guidebooks.load_page_data
- gm4_guidebook.generate_guidebooks.load_custom_recipes
- gm4.plugins.test.load_tests
pipeline:
- gm4.plugins.manifest.write_updates
- gm4.plugins.write_mcmeta
meta:
mecha:
formatting:
layout: preserve
nbt_compact: True

meta:
autosave:
link: false
6 changes: 4 additions & 2 deletions gm4/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@click.option("-l", "--link", metavar="WORLD", help="Link the project before watching.")
@click.option("-c", "--clean", is_flag=True, help="Clean the output folder.")
@click.option("--log", default="INFO", type=str, help="Set the logger level")
def dev(ctx: click.Context, project: Project, modules: tuple[str], watch: bool, reload: bool, link: str | None, clean: bool, log: int | str):
def dev(ctx: click.Context, project: Project, modules: tuple[str, ...], watch: bool, reload: bool, link: str | None, clean: bool, log: int | str):
"""Build or watch modules for development."""

modules = tuple(m if m.startswith("gm4_") else f"gm4_{m}" for m in modules)
Expand Down Expand Up @@ -45,11 +45,13 @@ def dev(ctx: click.Context, project: Project, modules: tuple[str], watch: bool,
"gm4.plugins.player_heads",
"gm4_guidebook.generate_guidebooks.load_page_data",
"gm4_guidebook.generate_guidebooks.load_custom_recipes",
"gm4.plugins.test.load_tests"
] if reload else [
"gm4.plugins.output",
"gm4.plugins.player_heads",
"gm4_guidebook.generate_guidebooks.load_page_data",
"gm4_guidebook.generate_guidebooks.load_custom_recipes",
"gm4.plugins.test.load_tests"
],
"pipeline": [
"gm4.plugins.write_mcmeta"
Expand Down Expand Up @@ -84,7 +86,7 @@ def clean():
@click.argument("modules", nargs=-1)
@click.option("-w", "--watch", is_flag=True, help="Watch the project directory and build on file changes.")
@click.option("-c", "--clean", is_flag=True, help="Clean the output folder.")
def readme_gen(ctx: click.Context, project: Project, modules: tuple[str], watch: bool, clean: bool):
def readme_gen(ctx: click.Context, project: Project, modules: tuple[str, ...], watch: bool, clean: bool):
"""Generates all README files for manual uplaoad"""

modules = tuple(m if m.startswith("gm4_") else f"gm4_{m}" for m in modules)
Expand Down
4 changes: 2 additions & 2 deletions gm4/plugins/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from functools import cache
from pathlib import Path
from typing import Any, Optional
from pydantic import Extra, BaseModel
from pydantic.v1 import Extra, BaseModel

import yaml
from beet import Context, JsonFile, PluginOptions, TextFile, load_config, InvalidProjectConfig
Expand Down Expand Up @@ -194,7 +194,7 @@ def update_patch(ctx: Context):
logger.info(f"Feature update for {id}, setting version to {version}")
else:
version.patch = last_ver.patch + 1 # type: ignore
logger.info(f"Updating {id} patch to {version.patch}")
logger.info(f"Updating {id} patch to {version.patch}") # type: ignore

pack.version = str(version)

Expand Down
14 changes: 14 additions & 0 deletions gm4/plugins/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ def beet_default(ctx: Context):
)


def test(ctx: Context):
"""Saves the zipped datapack to the ./out folder in it's exit phase.
Should be first in pipeline to properly wrap all other plugins cleanup phases"""
out_dir = Path("out")

yield # wait for exit phase, after other plugins cleanup

ctx.data.save(
path=out_dir / ctx.project_id,
overwrite=True,
zipped=True,
)


def release(ctx: Context):
"""
Saves the zipped datapack and metadata to the ./release/{version} folder.
Expand Down
10 changes: 6 additions & 4 deletions gm4/plugins/player_heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Any, Callable, ClassVar, Generator

import requests
from beet import Context, FileDeserialize, JsonFile, PngFile
from beet import Context, FileDeserialize, JsonFile, PngFile, TextFile
from mecha import CompilationUnit, Diagnostic, Mecha, MutatingReducer, rule
from mecha.ast import (
AstChildren,
Expand Down Expand Up @@ -221,7 +221,7 @@ def process_json_files(ctx: Context):
tf = ctx.inject(SkinNbtTransformer)
mc = ctx.inject(Mecha)

def transform_snbt(snbt: str, db_entry_key: str) -> str:
def transform_snbt(snbt: str, db_entry_key: TextFile) -> str:
escaped_snbt = snbt.replace("\n", "\\\\n")
# NOTE snbt in loot-tables reacts weird to \n characters. Both \n and \\\\n produce the same ingame output (\\n).
# gm4 only has one case of \n in loot tables, so this replacement forces \n->\\\\n for the mecha parser to read it right.
Expand All @@ -239,11 +239,13 @@ def transform_snbt(snbt: str, db_entry_key: str) -> str:
for func_list in nested_get(contents, "functions"):
f: Callable[[Any], bool] = lambda e: e["function"].removeprefix('minecraft:')=="set_nbt"
for i, entry in enumerate(filter(f, func_list)):
entry["tag"] = transform_snbt(entry["tag"], db_entry_key=f"{name}_{i}")
key = TextFile(_content=f"{name}_{i}", source_path=jsonfile.source_path)
entry["tag"] = transform_snbt(entry["tag"], db_entry_key=key)

for name, jsonfile in ctx.data.advancements.items():
for i, entry in enumerate(nested_get(jsonfile.data, "icon")):
entry["nbt"] = transform_snbt(entry["nbt"], db_entry_key=f"{name}_{i}")
key = TextFile(_content=f"{name}_{i}", source_path=jsonfile.source_path)
entry["nbt"] = transform_snbt(entry["nbt"], db_entry_key=key)

# send any raised diagnostic errors to Mecha for reporting
mc.diagnostics.extend(tf.diagnostics)
Expand Down
10 changes: 5 additions & 5 deletions gm4/plugins/prefabs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from beet import Context, PluginOptions, configurable
from beet.contrib.find_replace import find_replace
from beet.contrib.rename_files import rename_files
from pydantic import Extra
import nbtlib
from pydantic.v1 import Extra
import nbtlib # type: ignore
import re


Expand Down Expand Up @@ -39,6 +39,6 @@ def structure_deep_rename(ctx: Context, find_namespace: str, repl_namespace: str

# rename structure-file references
for s in ctx.data.structures:
blocks = ctx.data.structures[s].data["blocks"].snbt()
updated_blocks_data = re.sub(f"{find_namespace}:([a-z0-9_/]+)", f"{repl_namespace}:\\1", blocks)
ctx.data.structures[s].data["blocks"] = nbtlib.parse_nbt(updated_blocks_data)
blocks = ctx.data.structures[s].data["blocks"].snbt() # type: ignore
updated_blocks_data = re.sub(f"{find_namespace}:([a-z0-9_/]+)", f"{repl_namespace}:\\1", blocks) # type: ignore
ctx.data.structures[s].data["blocks"] = nbtlib.parse_nbt(updated_blocks_data) # type: ignore
18 changes: 18 additions & 0 deletions gm4/plugins/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from beet import Context, TextFile
from typing import ClassVar, Tuple


def load_tests(ctx: Context):
ctx.data.extend_namespace += [TestFile]


class TestFile(TextFile):
"""Class representing an test function."""

scope: ClassVar[Tuple[str, ...]] = ("tests",)
extension: ClassVar[str] = ".mcfunction"


def strip_tests(ctx: Context):
for structure in ctx.data.structures.match("*:test_*"):
del ctx.data.structures[structure]
2 changes: 1 addition & 1 deletion gm4/plugins/upgrade_paths.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from beet import Context, Function, configurable, PluginOptions
from pydantic import Extra
from pydantic.v1 import Extra
from gm4.plugins.manifest import ManifestCacheModel
from gm4.utils import Version, NoneAttribute

Expand Down
2 changes: 1 addition & 1 deletion gm4/plugins/versioning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from beet import Context, Function, FunctionTag, PluginOptions, configurable
from beet.contrib.rename_files import rename_files
from beet.contrib.find_replace import find_replace
from pydantic import Field, Extra
from pydantic.v1 import Field, Extra
import warnings
from gm4.utils import Version, NoneAttribute
import gm4.plugins.manifest # for ManifestCacheModel; a runtime circular dependency
Expand Down
20 changes: 20 additions & 0 deletions gm4_animi_shamir/data/gm4_animi_shamir/tests/keep_items.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# @template gm4:test_tube
# @dummy ~1 ~1 ~1

give @s golden_leggings{gm4_metallurgy:{active_shamir:"animi"}}
give @s wooden_sword
kill @s

await entity @e[type=item,distance=..3,nbt={Item:{id:"minecraft:wooden_sword",Count:1b}}]
assert not entity @e[type=item,distance=..3,nbt={Item:{id:"minecraft:golden_leggings",Count:1b}}]

await delay 1s

kill @e[type=zombie,distance=..3]
kill @e[type=item,distance=..3]

await delay 1s

dummy @s respawn

await entity @p[nbt={Inventory:[{id:"minecraft:golden_leggings",Count:1b,tag:{gm4_metallurgy:{active_shamir:"animi"}}}]}]
11 changes: 11 additions & 0 deletions gm4_animi_shamir/data/gm4_animi_shamir/tests/smoosh.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @template gm4_metallurgy:test_smooshing

loot spawn ~1.5 ~2.5 ~1.8 loot gm4_animi_shamir:band
summon item ~1.5 ~2.5 ~1.8 {Item:{id:"minecraft:diamond_leggings",Count:1b}}

await delay 1s

setblock ~1 ~4 ~1 redstone_block

await entity @e[type=item,distance=..4,nbt={Item:{id:"minecraft:diamond_leggings",Count:1b,tag:{gm4_metallurgy:{active_shamir:"animi"}}}}]
assert entity @e[type=item,distance=..4,nbt={Item:{id:"minecraft:obsidian",Count:1b}}]

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions gm4_bat_grenades/data/gm4_bat_grenades/tests/boom.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @template gm4:test_box
# @dummy ~3 ~1 ~3
# @timeout 200

summon bat ~3 ~2 ~3 {Tags:[gm4_test_bat]}

await not entity @e[tag=gm4_test_bat,distance=..10]
Loading

0 comments on commit 2d06ad3

Please sign in to comment.