# Mecha Custom Components
[](https://github.com/TheNuclearNexus/mecha-custom-components/actions)
[](https://pypi.org/project/mecha-custom-components/)
[](https://pypi.org/project/mecha-custom-components/)
[](https://github.com/ambv/black)
> A library to easily extend your Mecha/Bolt code with custom components
## Introduction
This package provides an easy way to create your own custom components for mcfunction, using the Beet/Mecha ecosystem.
### Features
- Extensible component registry
## Example Usage
Extracted from [here](https://github.com/TheNuclearNexus/mecha-custom-components/tree/main/examples/basic_component_with_properties)
> [Beet](https://github.com/mcbeet/beet) Plugin
```py
from beet import Context
from nbtlib import Base, Compound
from mecha_custom_components import CustomComponentRegistry
def simple_component(properties: Base, components: dict[str, Base]):
if not isinstance(properties, Compound):
raise Exception("'example:simple' expects a compound!")
custom_data = components.setdefault("minecraft:custom_data", Compound({}))
if not isinstance(custom_data, Compound):
raise Exception("Existing custom_data was not a compound!")
custom_data.merge({"foo": properties["value"]})
return components
def beet_default(ctx: Context):
registry = ctx.inject(CustomComponentRegistry)
registry.extend("example:foo", simple_component)
```
> [Bolt](https://github.com/mcbeet/bolt) code
```mcfunction
give @s stick[example:foo={value: 1}]
```
When compiled becomes:
```mcfunction
give @s stick[minecraft:custom_data={foo: 1}]
```
More examples can be found in the [examples](https://github.com/TheNuclearNexus/mecha-custom-components/tree/main/examples) folder.
## Installation
The package can be installed with `pip`.
```
$ pip install mecha-custom-components
```
Raw data
{
"_id": null,
"home_page": "https://github.com/TheNuclearNexus/mecha-custom-components",
"name": "mecha-custom-components",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "beet, mecha, bolt, minecraft-commands, mcfunction, components",
"author": "TheNuclearNexus",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/84/ca/717778842dbf6d2ad4741e99840ef908b954d343b28c799b01a124d7f772/mecha_custom_components-0.0.3.tar.gz",
"platform": null,
"description": "# Mecha Custom Components\n[](https://github.com/TheNuclearNexus/mecha-custom-components/actions)\n[](https://pypi.org/project/mecha-custom-components/)\n[](https://pypi.org/project/mecha-custom-components/)\n[](https://github.com/ambv/black)\n\n> A library to easily extend your Mecha/Bolt code with custom components\n\n## Introduction\n\nThis package provides an easy way to create your own custom components for mcfunction, using the Beet/Mecha ecosystem.\n\n### Features\n- Extensible component registry\n\n## Example Usage\nExtracted from [here](https://github.com/TheNuclearNexus/mecha-custom-components/tree/main/examples/basic_component_with_properties)\n\n> [Beet](https://github.com/mcbeet/beet) Plugin\n```py\nfrom beet import Context\nfrom nbtlib import Base, Compound\nfrom mecha_custom_components import CustomComponentRegistry\n\ndef simple_component(properties: Base, components: dict[str, Base]):\n if not isinstance(properties, Compound):\n raise Exception(\"'example:simple' expects a compound!\")\n\n custom_data = components.setdefault(\"minecraft:custom_data\", Compound({}))\n\n if not isinstance(custom_data, Compound):\n raise Exception(\"Existing custom_data was not a compound!\")\n\n\n custom_data.merge({\"foo\": properties[\"value\"]})\n\n return components\n\ndef beet_default(ctx: Context):\n registry = ctx.inject(CustomComponentRegistry)\n registry.extend(\"example:foo\", simple_component)\n```\n> [Bolt](https://github.com/mcbeet/bolt) code\n```mcfunction\ngive @s stick[example:foo={value: 1}]\n```\nWhen compiled becomes:\n```mcfunction\ngive @s stick[minecraft:custom_data={foo: 1}]\n```\n\nMore examples can be found in the [examples](https://github.com/TheNuclearNexus/mecha-custom-components/tree/main/examples) folder.\n\n## Installation\n\nThe package can be installed with `pip`.\n```\n$ pip install mecha-custom-components\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library to easily extend your Mecha/Bolt code with custom components",
"version": "0.0.3",
"project_urls": {
"Documentation": "https://github.com/TheNuclearNexus/mecha-custom-components",
"Homepage": "https://github.com/TheNuclearNexus/mecha-custom-components",
"Repository": "https://github.com/TheNuclearNexus/mecha-custom-components"
},
"split_keywords": [
"beet",
" mecha",
" bolt",
" minecraft-commands",
" mcfunction",
" components"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8e6d0b72d35ad9930634d9cfe4a82b285aafab0a385b21306dc58a08bc56cdbc",
"md5": "816291c24fb12622d8b21d5633a68330",
"sha256": "36073666759ffecb6c3781ce7304c4a7a79baf8a64e446834affef36ac0d0f6d"
},
"downloads": -1,
"filename": "mecha_custom_components-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "816291c24fb12622d8b21d5633a68330",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 3270,
"upload_time": "2025-01-28T21:00:41",
"upload_time_iso_8601": "2025-01-28T21:00:41.824840Z",
"url": "https://files.pythonhosted.org/packages/8e/6d/0b72d35ad9930634d9cfe4a82b285aafab0a385b21306dc58a08bc56cdbc/mecha_custom_components-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "84ca717778842dbf6d2ad4741e99840ef908b954d343b28c799b01a124d7f772",
"md5": "e74afa4fa535a76ec96c8b930edc74b4",
"sha256": "cb0a7010579348db5e3c08be6d1b775b8e666f91beaff05b7cf57fa7b2b8c3b1"
},
"downloads": -1,
"filename": "mecha_custom_components-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "e74afa4fa535a76ec96c8b930edc74b4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 2830,
"upload_time": "2025-01-28T21:00:43",
"upload_time_iso_8601": "2025-01-28T21:00:43.458458Z",
"url": "https://files.pythonhosted.org/packages/84/ca/717778842dbf6d2ad4741e99840ef908b954d343b28c799b01a124d7f772/mecha_custom_components-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-28 21:00:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TheNuclearNexus",
"github_project": "mecha-custom-components",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mecha-custom-components"
}