Skip to main content

Literate Minecraft data packs and resource packs.

Project description

logo

Lectern

GitHub Actions PyPI PyPI - Python Version Code style: black

Literate Minecraft data packs and resource packs.

@function tutorial:greeting

say Hello, world!

Introduction

This markdown file is interspersed with code fragments describing the content of a Minecraft data pack. Using lectern, you can turn this single file into an actual data pack that can be loaded into the game.

Features

  • Turn markdown files into data packs and resource packs
  • Merge resources from several markdown files
  • Convert data packs and resource packs into markdown snapshots
  • Can be used as a beet plugin
  • Highly extensible with custom directives

Hmmkay but why?

  • Editing data packs involves a lot of jumping around between files, for simple use-cases a single file is a lot easier to work with
  • Minecraft packs aggregate various types of files that can have complex interactions with each other, a literate style allows you to document these interactions fluently
  • Human-readable, single-file data pack and resource pack snapshots can be really useful to diff and track regressions in Minecraft-related tooling

Installation

The package can be installed with pip.

$ pip install lectern

Getting started

This is an example of a markdown file that can be turned into a data pack:

# Beginner tutorial

Let's start by creating a simple function:

`@function tutorial:greeting`

```mcfunction
say Hello, world!
```

And now we can make it run when the data pack is loaded!

`@function_tag minecraft:load`

```json
{
  "values": ["tutorial:greeting"]
}
```

You can use the lectern command-line utility to turn the markdown file into a data pack.

$ lectern tutorial.md --data-pack path/to/tutorial_data_pack

If you're using beet you can use lectern as a plugin in your pipeline.

{
  "pipeline": ["lectern"],
  "meta": {
    "lectern": {
      "load": ["*.md"]
    }
  }
}

Directives

Data pack and resource pack fragments are code blocks, links or images annotated with a special lectern directive. Directives are prefixed with the @ symbol and can be followed by zero or more arguments.

@<directive_name> <arg1> <arg2> <arg3>...

lectern provides directives for including namespaced resources inside data packs and resource packs. These built-in directives all expect a single argument specifying the fully-qualified resource name.

@function tutorial:greeting
@function_tag minecraft:load

Here is a reference of all the supported resources:

Data pack Resource pack
@advancement @blockstate
@function @model
@loot_table @font
@predicate @glyph_sizes ⚠️
@recipe @truetype_font ⚠️
@structure ⚠️ @shader_post
@block_tag @shader_program
@entity_type_tag @fragment_shader
@fluid_tag @vertex_shader
@function_tag @text
@item_tag @texture_mcmeta
@dimension_type @texture ⚠️
@dimension
@biome
@configured_carver
@configured_feature
@configured_structure_feature
@configured_surface_builder
@noise_settings
@processor_list
@template_pool

⚠️ Binary resources are supported but aren't compatible with code block fragments.

There are two additional built-in directives that can be used to include files using a path relative to the root of the data pack or the resource pack.

@data_pack pack.mcmeta
@resource_pack pack.png
@resource_pack assets/minecraft/textures/block/kelp_plant.png.mcmeta

This is useful for adding files that aren't part of any particular namespace.

Code block fragments

You can include the content of a code block in a data pack or a resource pack by preceding it with a directive surrounded by backticks.

@function tutorial:greeting

say Hello, world!

You can put the directive in an html comment to make it invisible.

{
  "values": ["tutorial:greeting"]
}

The directive can also be embedded directly inside the code block. You can insert a directive preceded by either # or // and the following lines will be included in the specified file.

# @function tutorial:obtained_dead_bush
say You obtained a dead bush!

Embedded directives are striped from the output. You can use multiple directives in a single code block.

// @loot_table minecraft:blocks/diamond_ore
{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:dead_bush"
        }
      ]
    }
  ]
}
// @advancement tutorial:obtained_dead_bush
{
  "criteria": {
    "dead_bush": {
      "trigger": "minecraft:inventory_changed",
      "conditions": {
        "items": [
          {
            "item": "minecraft:dead_bush"
          }
        ]
      }
    }
  },
  "requirements": [
    [
      "dead_bush"
    ]
  ],
  "rewards": {
    "function": "tutorial:obtained_dead_bush"
  }
}

Link fragments

TODO

Image fragments

TODO

Operators

TODO

Command-line utility

$ lectern --help

You can extract data packs from markdown files with the -d/--data-pack option. If the name ends with .zip the generated data pack will be zipped. Multiple markdown files can be merged together into a single data pack.

$ lectern demo.md --data-pack demo_data_pack
$ lectern demo.md -d demo_data_pack
$ lectern demo.md -d demo_data_pack.zip
$ lectern foo.md bar.md -d demo_data_pack

The -r/--resource-pack option lets you do exactly the same thing but with resource packs. The two options can be combined to extract a data packs and a resource pack at the same time.

$ lectern demo.md --resource-pack demo_resource_pack
$ lectern demo.md -r demo_resource_pack
$ lectern demo.md -d demo_data_pack -r demo_resource_pack

You can also convert a combination of data packs and resource packs into a single markdown file.

$ lectern demo_data_pack demo.md
$ lectern demo_data_pack.zip demo.md
$ lectern demo_data_pack demo_resource_pack demo.md
$ lectern foo_data_pack bar_data_pack demo.md

The last argument is the name of the generated markdown file. By default, the lectern utility won't save the files that can't be directly defined inside the markdown file. You can use the -o/--output-files option to dump the files in the specified directory.

$ lectern demo_data_pack demo.md --output-files files
$ lectern demo_data_pack demo.md -o files
$ lectern demo_data_pack demo.md -o .

Beet plugin

TODO

Contributing

Contributions are welcome. Make sure to first open an issue discussing the problem or the new feature before creating a pull request. The project uses poetry.

$ poetry install

You can run the tests with poetry run pytest.

$ poetry run pytest

The project must type-check with pyright. If you're using VSCode the pylance extension should report diagnostics automatically. You can also install the type-checker locally with npm install and run it from the command-line.

$ npm run watch
$ npm run check

The code follows the black code style. Import statements are sorted with isort.

$ poetry run isort lectern tests
$ poetry run black lectern tests
$ poetry run black --check lectern tests

License - MIT

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lectern-0.1.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lectern-0.1.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file lectern-0.1.0.tar.gz.

File metadata

  • Download URL: lectern-0.1.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

File hashes

Hashes for lectern-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed0382458e057c9eeb71c46784a60e297fea9e62f75f0ae1326ca70ef5c3db01
MD5 52943cb20d9b1d9a96e7b2f4e74d8209
BLAKE2b-256 988348498bc2a7e009b5d7439c2ca70f99b3d9dbf1bd32fea28325aaf6009815

See more details on using hashes here.

File details

Details for the file lectern-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lectern-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1

File hashes

Hashes for lectern-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c51d0ac2e08b3a312b93a484b18d76189ecaea0efdce5ed4dc9c47699f40172c
MD5 ba11a20ca7af49d1933178a8343ac1f5
BLAKE2b-256 37d4008607596cb5160762c923ed163987e6c97cb035ef3ad3887c71e81e78fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page