mcanvil-kit 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcanvil_kit-0.1.1/LICENSE +21 -0
- mcanvil_kit-0.1.1/PKG-INFO +76 -0
- mcanvil_kit-0.1.1/README.md +51 -0
- mcanvil_kit-0.1.1/pyproject.toml +44 -0
- mcanvil_kit-0.1.1/setup.cfg +4 -0
- mcanvil_kit-0.1.1/src/anvil_kit/__init__.py +8 -0
- mcanvil_kit-0.1.1/src/anvil_kit/__version__.py +1 -0
- mcanvil_kit-0.1.1/src/anvil_kit/actors/__init__.py +0 -0
- mcanvil_kit-0.1.1/src/anvil_kit/actors/materials.py +60 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/__init__.py +0 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/__init__.py +393 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/__init__.py +17 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/boat.py +154 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/button.py +197 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/chest_boat.py +150 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/door.py +235 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/fence.py +196 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/fence_gate.py +196 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/hanging_sign.py +198 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/leaves.py +180 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/log.py +149 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/log_stripped.py +143 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/planks.py +131 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/pressure_plate.py +190 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/sapling.py +119 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/sign.py +196 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/slab.py +178 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/stairs.py +232 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/trapdoor.py +213 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/wood.py +153 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/blocks/wood_stripped.py +147 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/components.py +196 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/models/wood_set.bbmodel +1 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/models/wood_set_boat.bbmodel +1 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/boat.ts +102 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/constants.ts +92 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/door.ts +29 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/index.ts.template +12 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/interactable.ts +17 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/leaves.ts +84 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/redstone-consumer.ts +39 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/sapling.ts +57 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/sign.ts +432 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/slab.ts +110 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/strippable.ts +41 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/support.ts +68 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript/togglable.ts +44 -0
- mcanvil_kit-0.1.1/src/anvil_kit/blocks/wood_set/typescript.py +122 -0
- mcanvil_kit-0.1.1/src/anvil_kit/world/__init__.py +0 -0
- mcanvil_kit-0.1.1/src/anvil_kit/world/ldtk.py +320 -0
- mcanvil_kit-0.1.1/src/anvil_kit/world/potions.py +449 -0
- mcanvil_kit-0.1.1/src/mcanvil_kit.egg-info/PKG-INFO +76 -0
- mcanvil_kit-0.1.1/src/mcanvil_kit.egg-info/SOURCES.txt +58 -0
- mcanvil_kit-0.1.1/src/mcanvil_kit.egg-info/dependency_links.txt +1 -0
- mcanvil_kit-0.1.1/src/mcanvil_kit.egg-info/requires.txt +10 -0
- mcanvil_kit-0.1.1/src/mcanvil_kit.egg-info/top_level.txt +1 -0
- mcanvil_kit-0.1.1/tests/test_ldtk.py +346 -0
- mcanvil_kit-0.1.1/tests/test_materials.py +35 -0
- mcanvil_kit-0.1.1/tests/test_wood_set_leaves.py +122 -0
- mcanvil_kit-0.1.1/tests/test_wood_set_tree.py +61 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 StarkTMA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcanvil-kit
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Ready-made content for Anvil, the Minecraft Bedrock content development framework.
|
|
5
|
+
Author: Yasser A. Benfoughal
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Github, https://github.com/StarkTMA/anvil-kit
|
|
8
|
+
Project-URL: Website, https://anvil.starktma.net
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
13
|
+
Requires-Python: >=3.15
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: mcanvil<1.3,>=1.1
|
|
17
|
+
Requires-Dist: click
|
|
18
|
+
Requires-Dist: orjson
|
|
19
|
+
Provides-Extra: ldtk
|
|
20
|
+
Requires-Dist: amulet-core; extra == "ldtk"
|
|
21
|
+
Provides-Extra: test
|
|
22
|
+
Requires-Dist: pytest; extra == "test"
|
|
23
|
+
Requires-Dist: jsonschema; extra == "test"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# Anvil Kit
|
|
27
|
+
|
|
28
|
+
Ready-made content for [Anvil](https://github.com/StarkTMA/Anvil), the Python framework for Minecraft Bedrock add-ons: call one function, get a working feature.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install mcanvil-kit
|
|
32
|
+
pip install mcanvil-kit[ldtk] # for anvil_kit.world.ldtk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from anvil_kit.blocks.wood_set import WoodBlock, create_wood_set
|
|
37
|
+
|
|
38
|
+
create_wood_set("maple", WoodBlock.SAPLING)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Kits
|
|
42
|
+
|
|
43
|
+
| Kit | What it makes |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `anvil_kit.blocks.wood_set` | A complete wood set: planks, logs, slabs, stairs, fences, doors, signs, boats, leaves, saplings, with recipes and scripts. |
|
|
46
|
+
| `anvil_kit.world.potions` | Potion variants (drinkable, splash, lingering) and brewing recipes. |
|
|
47
|
+
| `anvil_kit.world.ldtk` | A Minecraft world from an [LDtk](https://ldtk.io) map. Needs the `ldtk` extra. |
|
|
48
|
+
| `anvil_kit.actors.materials` | Entity outline materials. |
|
|
49
|
+
|
|
50
|
+
The kit is opinionated and may change between minor versions. `anvil.api` is the stable layer.
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
Complete Anvil projects you can build as is, in [`examples/`](examples/):
|
|
55
|
+
|
|
56
|
+
| Example | What it shows |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| [Wood Set](examples/wood_set/) | Two custom woods from `anvil_kit.blocks.wood_set`: maple from one call, and willow with its own tree and leaves that drop sticks. |
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
cd examples/wood_set
|
|
62
|
+
npm install
|
|
63
|
+
anvil build
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install -e ../anvil # a local Anvil checkout
|
|
70
|
+
pip install -e .[test]
|
|
71
|
+
pytest
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT ([LICENSE](LICENSE)), for the kit and everything in `examples/`, code and assets: use it in your own add-ons, free or paid.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Anvil Kit
|
|
2
|
+
|
|
3
|
+
Ready-made content for [Anvil](https://github.com/StarkTMA/Anvil), the Python framework for Minecraft Bedrock add-ons: call one function, get a working feature.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install mcanvil-kit
|
|
7
|
+
pip install mcanvil-kit[ldtk] # for anvil_kit.world.ldtk
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from anvil_kit.blocks.wood_set import WoodBlock, create_wood_set
|
|
12
|
+
|
|
13
|
+
create_wood_set("maple", WoodBlock.SAPLING)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Kits
|
|
17
|
+
|
|
18
|
+
| Kit | What it makes |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| `anvil_kit.blocks.wood_set` | A complete wood set: planks, logs, slabs, stairs, fences, doors, signs, boats, leaves, saplings, with recipes and scripts. |
|
|
21
|
+
| `anvil_kit.world.potions` | Potion variants (drinkable, splash, lingering) and brewing recipes. |
|
|
22
|
+
| `anvil_kit.world.ldtk` | A Minecraft world from an [LDtk](https://ldtk.io) map. Needs the `ldtk` extra. |
|
|
23
|
+
| `anvil_kit.actors.materials` | Entity outline materials. |
|
|
24
|
+
|
|
25
|
+
The kit is opinionated and may change between minor versions. `anvil.api` is the stable layer.
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
Complete Anvil projects you can build as is, in [`examples/`](examples/):
|
|
30
|
+
|
|
31
|
+
| Example | What it shows |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| [Wood Set](examples/wood_set/) | Two custom woods from `anvil_kit.blocks.wood_set`: maple from one call, and willow with its own tree and leaves that drop sticks. |
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
cd examples/wood_set
|
|
37
|
+
npm install
|
|
38
|
+
anvil build
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Development
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install -e ../anvil # a local Anvil checkout
|
|
45
|
+
pip install -e .[test]
|
|
46
|
+
pytest
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT ([LICENSE](LICENSE)), for the kit and everything in `examples/`, code and assets: use it in your own add-ons, free or paid.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mcanvil-kit"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Ready-made content for Anvil, the Minecraft Bedrock content development framework."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Yasser A. Benfoughal" }]
|
|
13
|
+
requires-python = ">=3.15"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"mcanvil>=1.1,<1.3",
|
|
16
|
+
"click",
|
|
17
|
+
"orjson",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3.15",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
ldtk = ["amulet-core"]
|
|
28
|
+
test = ["pytest", "jsonschema"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Github = "https://github.com/StarkTMA/anvil-kit"
|
|
32
|
+
Website = "https://anvil.starktma.net"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.dynamic]
|
|
35
|
+
version = { attr = "anvil_kit.__version__.__version__" }
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
where = ["src"]
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.package-data]
|
|
41
|
+
anvil_kit = [
|
|
42
|
+
"blocks/wood_set/typescript/*",
|
|
43
|
+
"blocks/wood_set/models/*",
|
|
44
|
+
]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Ready-made content built on `anvil.api`: call one function, get a working feature.
|
|
2
|
+
|
|
3
|
+
The kit is opinionated and may change between minor versions of Anvil (names, parameters
|
|
4
|
+
and generated content). `anvil.api` is the stable layer; build on it directly when you need
|
|
5
|
+
full control or long-term stability.
|
|
6
|
+
|
|
7
|
+
Some kits need an extra, e.g. `pip install mcanvil-kit[ldtk]` for `anvil_kit.world.ldtk`.
|
|
8
|
+
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.1"
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from anvil.api.actors.materials import Material
|
|
4
|
+
from anvil.lib.jsonmodel.enums import (
|
|
5
|
+
MaterialDefinitions,
|
|
6
|
+
MaterialFunc,
|
|
7
|
+
MaterialOperation,
|
|
8
|
+
MaterialStates,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def add_entity_outline(xray_mode: bool = False):
|
|
13
|
+
"""Adds a material for entity outlines.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
Materials: A dataclass containing the base and outline materials.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class Materials:
|
|
21
|
+
base_material: Material
|
|
22
|
+
outline_material: Material
|
|
23
|
+
|
|
24
|
+
def queue(self):
|
|
25
|
+
self.base_material.queue()
|
|
26
|
+
self.outline_material.queue()
|
|
27
|
+
|
|
28
|
+
entity_outline_base = Material("entity_outline_base", "entity_alphatest")
|
|
29
|
+
entity_outline_base.add_states(
|
|
30
|
+
MaterialStates.EnableStencilTest, MaterialStates.StencilWrite
|
|
31
|
+
)
|
|
32
|
+
entity_outline_base.set_frontFace(
|
|
33
|
+
stencilFunc=MaterialFunc.Always,
|
|
34
|
+
stencilFailOp=MaterialOperation.Replace,
|
|
35
|
+
stencilDepthFailOp=MaterialOperation.Replace,
|
|
36
|
+
stencilPassOp=MaterialOperation.Replace,
|
|
37
|
+
)
|
|
38
|
+
entity_outline_base.set_backFace(
|
|
39
|
+
stencilFunc=MaterialFunc.Always,
|
|
40
|
+
stencilFailOp=MaterialOperation.Replace,
|
|
41
|
+
stencilDepthFailOp=MaterialOperation.Replace,
|
|
42
|
+
stencilPassOp=MaterialOperation.Replace,
|
|
43
|
+
)
|
|
44
|
+
entity_outline_base.set_stencilRef(3)
|
|
45
|
+
|
|
46
|
+
entity_outline = Material("entity_outline", "entity_alphatest")
|
|
47
|
+
entity_outline.add_states(
|
|
48
|
+
MaterialStates.EnableStencilTest, MaterialStates.InvertCulling
|
|
49
|
+
)
|
|
50
|
+
entity_outline.add_defines(
|
|
51
|
+
MaterialDefinitions.MULTI_COLOR_TINT, MaterialDefinitions.USE_OVERLAY
|
|
52
|
+
)
|
|
53
|
+
entity_outline.remove_states(MaterialStates.DisableCulling)
|
|
54
|
+
entity_outline.remove_defines(MaterialDefinitions.FANCY)
|
|
55
|
+
entity_outline.set_frontFace(MaterialFunc.NotEqual)
|
|
56
|
+
entity_outline.set_stencilRef(3)
|
|
57
|
+
entity_outline.set_depthFunc(
|
|
58
|
+
MaterialFunc.Always if xray_mode else MaterialFunc.LessEqual
|
|
59
|
+
)
|
|
60
|
+
return Materials(entity_outline_base, entity_outline)
|
|
File without changes
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"""A complete wood set from one call: `create_wood_set("rotten")`.
|
|
2
|
+
|
|
3
|
+
WoodSet("rotten").tree(my_tree).leaf_drop(coconut, 0.02).build() # tree and drops
|
|
4
|
+
WoodSet("rotten").map_color("#5C4A32").build() # the color on maps
|
|
5
|
+
WoodSet("rotten", [WoodBlock.DOOR, WoodBlock.BOAT]).tree(my_tree).build() # all but these
|
|
6
|
+
WoodSet("rotten", WoodBlock.SAPLING | WoodBlock.DOOR).build() # no saplings: no tree
|
|
7
|
+
create_wood_set("rotten", tree=my_tree) # a one-call shortcut
|
|
8
|
+
|
|
9
|
+
Every block and boat is its own file in `blocks/`: its `create(wood, selected)` builds it,
|
|
10
|
+
names it, queues it and registers the recipes that make it. The custom components the
|
|
11
|
+
blocks share their scripts through are in `components.py`. The TypeScript the
|
|
12
|
+
blocks use is then written to `scripts/javascript/blocks/wood_set`; register it from
|
|
13
|
+
`main.ts` with `registerWoodSet(init)`. The signs' script uses `@minecraft/server-ui`,
|
|
14
|
+
so it needs `scriptui` enabled in `anvilconfig.json`.
|
|
15
|
+
|
|
16
|
+
Expected textures: `<name>_planks`, `<name>_log`, `<name>_log_top`, `<name>_log_stripped`,
|
|
17
|
+
`<name>_log_stripped_top`, `<name>_door_bottom`, `<name>_door_top`, `<name>_trapdoor`,
|
|
18
|
+
`<name>_hanging_sign`, `<name>_standing_sign`, `<name>_boat`, `<name>_leaves`,
|
|
19
|
+
`<name>_sapling`, and the item icons `<name>_sign`,
|
|
20
|
+
`<name>_hanging_sign`, `<name>_boat` and `<name>_chest_boat` in `assets/textures/items/`.
|
|
21
|
+
|
|
22
|
+
Every wood set shares the same two blockbench models, so only the names differ between
|
|
23
|
+
sets. Each model holds the textures of every set, named as above:
|
|
24
|
+
|
|
25
|
+
- `wood_set` (`assets/bbmodels/wood_set.bbmodel`): the block collections. `hanging_sign`
|
|
26
|
+
has a `top_bit` bone (on a wall) and a `top_chain` bone (under a block).
|
|
27
|
+
It also needs a `sapling` collection (a crossed pair of planes) for the saplings.
|
|
28
|
+
- `wood_set_boat` (`assets/bbmodels/wood_set_boat.bbmodel`): both boats, facing north,
|
|
29
|
+
with a `chest` bone and the `paddle`, `paddle_left`, `paddle_right` and `shake`
|
|
30
|
+
animations.
|
|
31
|
+
|
|
32
|
+
Their names are `MODEL` and `BOAT_MODEL` in `blocks/__init__.py`. When one is missing
|
|
33
|
+
from `assets/bbmodels`, building a set copies Anvil's base model there (the files in
|
|
34
|
+
`models/`), and never overwrites an existing one.
|
|
35
|
+
|
|
36
|
+
Leaves and saplings: a leaves block's `natural` state is off for leaves a player placed,
|
|
37
|
+
which stay forever. Whatever generates leaves sets it on, and they then decay when no log of
|
|
38
|
+
the set is within `leaf_distance` blocks through leaves. A sapling grows into the `tree`
|
|
39
|
+
feature, which `/place feature` builds at its position. See docs/kit for the details.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
import shutil
|
|
43
|
+
from collections.abc import Callable, Iterable
|
|
44
|
+
from enum import Flag, auto
|
|
45
|
+
from pathlib import Path
|
|
46
|
+
from typing import NamedTuple
|
|
47
|
+
|
|
48
|
+
import click
|
|
49
|
+
|
|
50
|
+
from anvil.api.actors.entity import Entity
|
|
51
|
+
from anvil.api.blocks.blocks import Block
|
|
52
|
+
from anvil.api.features import Feature
|
|
53
|
+
from anvil.api.items.crafting import CraftingItemCatalog
|
|
54
|
+
from anvil.api.items.items import Item
|
|
55
|
+
from anvil.lib.jsonmodel.enums import BlockSoundGroup, ItemCategory
|
|
56
|
+
from anvil.lib.jsonmodel.types import Color
|
|
57
|
+
|
|
58
|
+
from .blocks import (
|
|
59
|
+
BOAT_MODEL,
|
|
60
|
+
MAP_COLOR,
|
|
61
|
+
MODEL,
|
|
62
|
+
boat,
|
|
63
|
+
button,
|
|
64
|
+
chest_boat,
|
|
65
|
+
door,
|
|
66
|
+
fence,
|
|
67
|
+
fence_gate,
|
|
68
|
+
hanging_sign,
|
|
69
|
+
leaves,
|
|
70
|
+
log,
|
|
71
|
+
log_stripped,
|
|
72
|
+
planks,
|
|
73
|
+
pressure_plate,
|
|
74
|
+
sapling,
|
|
75
|
+
sign,
|
|
76
|
+
slab,
|
|
77
|
+
stairs,
|
|
78
|
+
trapdoor,
|
|
79
|
+
wood,
|
|
80
|
+
wood_stripped,
|
|
81
|
+
)
|
|
82
|
+
from .blocks.leaves import LeafDrop
|
|
83
|
+
from .typescript import generate_typescript
|
|
84
|
+
|
|
85
|
+
__all__ = [
|
|
86
|
+
"LeafDrop",
|
|
87
|
+
"WoodBlock",
|
|
88
|
+
"WoodSet",
|
|
89
|
+
"WoodSetPart",
|
|
90
|
+
"create_wood_set",
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class WoodBlock(Flag):
|
|
95
|
+
"""The blocks a wood set can contain. Combine them with `|` and remove them with `& ~`."""
|
|
96
|
+
|
|
97
|
+
PLANKS = auto()
|
|
98
|
+
BUTTON = auto()
|
|
99
|
+
PRESSURE_PLATE = auto()
|
|
100
|
+
FENCE = auto()
|
|
101
|
+
FENCE_GATE = auto()
|
|
102
|
+
STAIRS = auto()
|
|
103
|
+
DOOR = auto()
|
|
104
|
+
TRAPDOOR = auto()
|
|
105
|
+
SLAB = auto()
|
|
106
|
+
LOG = auto()
|
|
107
|
+
LOG_STRIPPED = auto()
|
|
108
|
+
WOOD = auto()
|
|
109
|
+
WOOD_STRIPPED = auto()
|
|
110
|
+
SIGN = auto()
|
|
111
|
+
HANGING_SIGN = auto()
|
|
112
|
+
BOAT = auto()
|
|
113
|
+
CHEST_BOAT = auto()
|
|
114
|
+
LEAVES = auto()
|
|
115
|
+
SAPLING = auto()
|
|
116
|
+
|
|
117
|
+
ALL = (
|
|
118
|
+
PLANKS
|
|
119
|
+
| BUTTON
|
|
120
|
+
| PRESSURE_PLATE
|
|
121
|
+
| FENCE
|
|
122
|
+
| FENCE_GATE
|
|
123
|
+
| STAIRS
|
|
124
|
+
| DOOR
|
|
125
|
+
| TRAPDOOR
|
|
126
|
+
| SLAB
|
|
127
|
+
| LOG
|
|
128
|
+
| LOG_STRIPPED
|
|
129
|
+
| WOOD
|
|
130
|
+
| WOOD_STRIPPED
|
|
131
|
+
| SIGN
|
|
132
|
+
| HANGING_SIGN
|
|
133
|
+
| BOAT
|
|
134
|
+
| CHEST_BOAT
|
|
135
|
+
| LEAVES
|
|
136
|
+
| SAPLING
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class WoodSetPart(NamedTuple):
|
|
141
|
+
"""A part of a wood set: what it places and the item that places it."""
|
|
142
|
+
|
|
143
|
+
block: Block | Entity
|
|
144
|
+
"""The block, or the entity for boats and chest boats."""
|
|
145
|
+
item: Item
|
|
146
|
+
"""The item in the inventory. For a block it is `block.item`."""
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class WoodSet(dict[str, WoodSetPart]):
|
|
150
|
+
"""A wood set: configure it, then `build()` it. Once built it maps each part's name (the
|
|
151
|
+
lowercase `WoodBlock` member, like "planks") to its `WoodSetPart`, and a part left out
|
|
152
|
+
with `exclude` is missing.
|
|
153
|
+
|
|
154
|
+
palm = (
|
|
155
|
+
WoodSet("palm", exclude=WoodBlock.CHEST_BOAT)
|
|
156
|
+
.tree(lambda wood: make_palm(wood["log"].block, wood["leaves"].block))
|
|
157
|
+
.leaf_drop(coconut, 0.02)
|
|
158
|
+
.map_color("#C2A56B")
|
|
159
|
+
.build()
|
|
160
|
+
)
|
|
161
|
+
block, item = palm["planks"]
|
|
162
|
+
|
|
163
|
+
The methods that configure the set return it, so they chain; all of them must come
|
|
164
|
+
before `build()`.
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
def __init__(
|
|
168
|
+
self,
|
|
169
|
+
name: str,
|
|
170
|
+
exclude: WoodBlock | Iterable[WoodBlock] = (),
|
|
171
|
+
*,
|
|
172
|
+
own_creative_group: bool = False,
|
|
173
|
+
) -> None:
|
|
174
|
+
"""
|
|
175
|
+
Args:
|
|
176
|
+
name (str): The name of the wood, which prefixes every block.
|
|
177
|
+
exclude (WoodBlock | Iterable[WoodBlock]): The parts to leave out. Blocks that depend
|
|
178
|
+
on an excluded one lose that part (a sign without planks has no recipe).
|
|
179
|
+
own_creative_group (bool): Put the whole set in one "<Name> Wood" group under
|
|
180
|
+
Construction, instead of next to the vanilla counterparts of each block.
|
|
181
|
+
"""
|
|
182
|
+
super().__init__()
|
|
183
|
+
self.name = name
|
|
184
|
+
self.own_creative_group = own_creative_group
|
|
185
|
+
self._tree = None
|
|
186
|
+
self.tree_feature: Feature | str | None = None
|
|
187
|
+
"""The feature the saplings grow into, once the set is built."""
|
|
188
|
+
self._drops: list[LeafDrop] = []
|
|
189
|
+
self._leaf_distance = 4
|
|
190
|
+
self._map_color: Color = MAP_COLOR
|
|
191
|
+
self._options: list[tuple[WoodBlock, dict]] = []
|
|
192
|
+
self._soil = list(sapling.DEFAULT_SOIL)
|
|
193
|
+
self._built = False
|
|
194
|
+
|
|
195
|
+
excluded = WoodBlock(0)
|
|
196
|
+
for kind in [exclude] if isinstance(exclude, WoodBlock) else exclude:
|
|
197
|
+
excluded |= kind
|
|
198
|
+
self.blocks = WoodBlock.ALL & ~excluded
|
|
199
|
+
|
|
200
|
+
def tree(
|
|
201
|
+
self, tree: Feature | str | Callable[["WoodSet"], Feature | str]
|
|
202
|
+
) -> "WoodSet":
|
|
203
|
+
"""Sets the feature the saplings grow into: a `Feature`, its identifier, or a function
|
|
204
|
+
that builds it from the set once its blocks exist (so the tree can use them). The
|
|
205
|
+
caller queues the feature. It is required unless `WoodBlock.SAPLING` is excluded.
|
|
206
|
+
"""
|
|
207
|
+
self._tree = tree
|
|
208
|
+
return self
|
|
209
|
+
|
|
210
|
+
def leaf_drop(
|
|
211
|
+
self, item: Item | str, chance: float, count: int | tuple[int, int] = 1
|
|
212
|
+
) -> "WoodSet":
|
|
213
|
+
"""Adds an item the leaves drop by chance, like the apple of oak (`LeafDrop`)."""
|
|
214
|
+
self._drops.append(LeafDrop(item, chance, count))
|
|
215
|
+
return self
|
|
216
|
+
|
|
217
|
+
def sapling_on(self, blocks: Iterable[str | object]) -> "WoodSet":
|
|
218
|
+
"""Sets the blocks the sapling can be planted on (by default dirt, grass, sand...).
|
|
219
|
+
Accepts identifiers and block descriptors like `MinecraftBlockTypes.Sand()`."""
|
|
220
|
+
self._soil = [str(block) for block in blocks]
|
|
221
|
+
return self
|
|
222
|
+
|
|
223
|
+
def leaf_distance(self, blocks: int) -> "WoodSet":
|
|
224
|
+
"""Sets how far a log can be from the leaves holding on to it (4 like vanilla), going
|
|
225
|
+
through leaves. Set it to the distance of the farthest leaf of your trees."""
|
|
226
|
+
self._leaf_distance = blocks
|
|
227
|
+
return self
|
|
228
|
+
|
|
229
|
+
def map_color(self, color: Color) -> "WoodSet":
|
|
230
|
+
"""Sets the color every block of the set has on a map (a "#RRGGBB" hex value or an
|
|
231
|
+
[R, G, B] list from 0 to 255). By default it is "#e6d063". Boats are entities, so
|
|
232
|
+
they have none."""
|
|
233
|
+
self._map_color = color
|
|
234
|
+
return self
|
|
235
|
+
|
|
236
|
+
def sound_group(
|
|
237
|
+
self, group: BlockSoundGroup | str, parts: WoodBlock = WoodBlock.ALL
|
|
238
|
+
) -> "WoodSet":
|
|
239
|
+
"""Sets the vanilla sound group of the parts, which play all of its sounds. By default
|
|
240
|
+
the blocks have `BlockSoundGroup.Wood`, the hanging sign `HangingSign`, and the leaves
|
|
241
|
+
and saplings `Grass`.
|
|
242
|
+
|
|
243
|
+
WoodSet("rotten").sound_group(BlockSoundGroup.Mud)
|
|
244
|
+
WoodSet("rotten").sound_group(BlockSoundGroup.Mud, WoodBlock.LOG | WoodBlock.WOOD)
|
|
245
|
+
"""
|
|
246
|
+
return self.options(parts, sound_group=group)
|
|
247
|
+
|
|
248
|
+
def options(self, parts: WoodBlock = WoodBlock.ALL, **options) -> "WoodSet":
|
|
249
|
+
"""Passes keyword arguments to the `create` of the parts, to change what their files
|
|
250
|
+
document as options: the sound ids of the door (`open_sound`, `close_sound`), of the
|
|
251
|
+
button and the pressure plate (`on_sound`, `off_sound`)...
|
|
252
|
+
|
|
253
|
+
WoodSet("rotten").options(WoodBlock.DOOR, open_sound="rotten.door_open")
|
|
254
|
+
|
|
255
|
+
A part that doesn't take an option raises when the set is built; a later call wins.
|
|
256
|
+
"""
|
|
257
|
+
self._options.append((parts, options))
|
|
258
|
+
return self
|
|
259
|
+
|
|
260
|
+
def build(self) -> "WoodSet":
|
|
261
|
+
"""Creates and queues every block, and writes their scripts. Returns the set."""
|
|
262
|
+
if self._built:
|
|
263
|
+
return self
|
|
264
|
+
if WoodBlock.SAPLING in self.blocks and self._tree is None:
|
|
265
|
+
raise ValueError(
|
|
266
|
+
f"The '{self.name}' wood set has saplings, so it needs the feature they grow "
|
|
267
|
+
"into: call `.tree(...)`, or exclude WoodBlock.SAPLING."
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
_copy_base_models()
|
|
271
|
+
|
|
272
|
+
selected = {kind.name.lower() for kind in BLOCKS if kind in self.blocks}
|
|
273
|
+
|
|
274
|
+
extra_arguments = {
|
|
275
|
+
WoodBlock.LEAVES: lambda: (self._drops, self._leaf_distance),
|
|
276
|
+
WoodBlock.SAPLING: lambda: (self._resolve_tree(), self._soil),
|
|
277
|
+
}
|
|
278
|
+
for kind, create in BLOCKS.items():
|
|
279
|
+
if kind in self.blocks:
|
|
280
|
+
arguments = extra_arguments.get(kind, lambda: ())()
|
|
281
|
+
options = {}
|
|
282
|
+
if kind not in ENTITY_PARTS:
|
|
283
|
+
options["map_color"] = self._map_color
|
|
284
|
+
for parts, given in self._options:
|
|
285
|
+
if kind in parts:
|
|
286
|
+
options.update(given)
|
|
287
|
+
self._add_part(kind, create(self.name, selected, *arguments, **options))
|
|
288
|
+
|
|
289
|
+
if self.own_creative_group and self:
|
|
290
|
+
_add_creative_group(self.name, [part.item for part in self.values()])
|
|
291
|
+
generate_typescript([part.block for part in self.values()])
|
|
292
|
+
self._built = True
|
|
293
|
+
return self
|
|
294
|
+
|
|
295
|
+
def _resolve_tree(self) -> Feature | str:
|
|
296
|
+
"""The tree feature, built now if it was given as a function."""
|
|
297
|
+
self.tree_feature = self._tree(self) if callable(self._tree) else self._tree
|
|
298
|
+
return self.tree_feature
|
|
299
|
+
|
|
300
|
+
def _add_part(self, kind: WoodBlock, made: Block | tuple[Entity, Item]) -> None:
|
|
301
|
+
"""Stores what a `create` function made under the part's name: a block (its item is
|
|
302
|
+
`block.item`), or an (entity, item) pair for boats."""
|
|
303
|
+
block, item = made if isinstance(made, tuple) else (made, made.item)
|
|
304
|
+
self[kind.name.lower()] = WoodSetPart(block, item)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
BASE_MODELS = Path(__file__).parent / "models"
|
|
308
|
+
|
|
309
|
+
ENTITY_PARTS = {WoodBlock.BOAT, WoodBlock.CHEST_BOAT}
|
|
310
|
+
|
|
311
|
+
BLOCKS = {
|
|
312
|
+
WoodBlock.PLANKS: planks.create,
|
|
313
|
+
WoodBlock.BUTTON: button.create,
|
|
314
|
+
WoodBlock.PRESSURE_PLATE: pressure_plate.create,
|
|
315
|
+
WoodBlock.FENCE: fence.create,
|
|
316
|
+
WoodBlock.FENCE_GATE: fence_gate.create,
|
|
317
|
+
WoodBlock.STAIRS: stairs.create,
|
|
318
|
+
WoodBlock.DOOR: door.create,
|
|
319
|
+
WoodBlock.TRAPDOOR: trapdoor.create,
|
|
320
|
+
WoodBlock.SLAB: slab.create,
|
|
321
|
+
WoodBlock.LOG: log.create,
|
|
322
|
+
WoodBlock.LOG_STRIPPED: log_stripped.create,
|
|
323
|
+
WoodBlock.WOOD: wood.create,
|
|
324
|
+
WoodBlock.WOOD_STRIPPED: wood_stripped.create,
|
|
325
|
+
WoodBlock.SIGN: sign.create,
|
|
326
|
+
WoodBlock.HANGING_SIGN: hanging_sign.create,
|
|
327
|
+
WoodBlock.BOAT: boat.create,
|
|
328
|
+
WoodBlock.CHEST_BOAT: chest_boat.create,
|
|
329
|
+
WoodBlock.LEAVES: leaves.create,
|
|
330
|
+
WoodBlock.SAPLING: sapling.create,
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def create_wood_set(
|
|
335
|
+
name: str,
|
|
336
|
+
exclude: WoodBlock | Iterable[WoodBlock] = (),
|
|
337
|
+
*,
|
|
338
|
+
tree: Feature | str | Callable[[WoodSet], Feature | str] | None = None,
|
|
339
|
+
leaf_drops: Iterable[LeafDrop] = (),
|
|
340
|
+
map_color: Color = MAP_COLOR,
|
|
341
|
+
own_creative_group: bool = False,
|
|
342
|
+
) -> WoodSet:
|
|
343
|
+
"""Create every block of the `name` wood set except `exclude`, in one call.
|
|
344
|
+
|
|
345
|
+
A shortcut for `WoodSet(name, exclude, ...)` with its `tree`, `leaf_drops` and `map_color`, built right
|
|
346
|
+
away. Use the `WoodSet` class to add leaf drops step by step.
|
|
347
|
+
|
|
348
|
+
block, item = create_wood_set("rotten", tree=my_tree)["planks"]
|
|
349
|
+
"""
|
|
350
|
+
wood = WoodSet(name, exclude, own_creative_group=own_creative_group).map_color(
|
|
351
|
+
map_color
|
|
352
|
+
)
|
|
353
|
+
if tree is not None:
|
|
354
|
+
wood.tree(tree)
|
|
355
|
+
for drop in leaf_drops:
|
|
356
|
+
wood.leaf_drop(drop.item, drop.chance, drop.count)
|
|
357
|
+
return wood.build()
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _copy_base_models() -> None:
|
|
361
|
+
"""Copies the base Blockbench models into the project when they aren't there.
|
|
362
|
+
|
|
363
|
+
Nothing is ever overwritten: a model that exists is the user's. Each copy is reported,
|
|
364
|
+
so the user knows which model to finish with the set's textures.
|
|
365
|
+
"""
|
|
366
|
+
models = Path("assets") / "bbmodels"
|
|
367
|
+
missing = [
|
|
368
|
+
name
|
|
369
|
+
for name in (MODEL, BOAT_MODEL)
|
|
370
|
+
if not (models / f"{name}.bbmodel").exists()
|
|
371
|
+
]
|
|
372
|
+
if not missing:
|
|
373
|
+
return
|
|
374
|
+
|
|
375
|
+
models.mkdir(parents=True, exist_ok=True)
|
|
376
|
+
for name in missing:
|
|
377
|
+
shutil.copy(BASE_MODELS / f"{name}.bbmodel", models)
|
|
378
|
+
click.echo(
|
|
379
|
+
click.style(
|
|
380
|
+
f"\r[INFO]: {name}.bbmodel not found in {models}. Copied the base wood set model there to finish.",
|
|
381
|
+
fg="yellow",
|
|
382
|
+
)
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def _add_creative_group(name: str, items: list[Item]) -> None:
|
|
387
|
+
"""Move the items out of their vanilla groups into a group of their own."""
|
|
388
|
+
CraftingItemCatalog().add_group(
|
|
389
|
+
ItemCategory.Construction,
|
|
390
|
+
f"{name.replace('_', ' ').title()} Wood",
|
|
391
|
+
items[0],
|
|
392
|
+
items,
|
|
393
|
+
).queue()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""One self-contained file per block; none imports another.
|
|
2
|
+
|
|
3
|
+
Each exposes `create(wood, selected) -> Block`: `wood` is the set name ("rotten") and
|
|
4
|
+
`selected` holds the names of every block in the set ("planks", "log_stripped", ...), used
|
|
5
|
+
to skip recipes and features that need a block the set doesn't have. `create` builds the
|
|
6
|
+
block, names it, queues it and registers the recipes that make it.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
MAP_COLOR = "#e6d063"
|
|
10
|
+
|
|
11
|
+
MODEL = "wood_set"
|
|
12
|
+
"""The block collections (`assets/bbmodels/wood_set.bbmodel`). It also holds the block
|
|
13
|
+
textures of every wood set, named `<name>_planks`, `<name>_log` and so on."""
|
|
14
|
+
|
|
15
|
+
BOAT_MODEL = "wood_set_boat"
|
|
16
|
+
"""Both boats (`assets/bbmodels/wood_set_boat.bbmodel`), with the boat texture of every wood
|
|
17
|
+
set, named `<name>_boat`."""
|