mcanvil-kit 0.1.1__py3-none-any.whl
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.
- anvil_kit/__init__.py +8 -0
- anvil_kit/__version__.py +1 -0
- anvil_kit/actors/__init__.py +0 -0
- anvil_kit/actors/materials.py +60 -0
- anvil_kit/blocks/__init__.py +0 -0
- anvil_kit/blocks/wood_set/__init__.py +393 -0
- anvil_kit/blocks/wood_set/blocks/__init__.py +17 -0
- anvil_kit/blocks/wood_set/blocks/boat.py +154 -0
- anvil_kit/blocks/wood_set/blocks/button.py +197 -0
- anvil_kit/blocks/wood_set/blocks/chest_boat.py +150 -0
- anvil_kit/blocks/wood_set/blocks/door.py +235 -0
- anvil_kit/blocks/wood_set/blocks/fence.py +196 -0
- anvil_kit/blocks/wood_set/blocks/fence_gate.py +196 -0
- anvil_kit/blocks/wood_set/blocks/hanging_sign.py +198 -0
- anvil_kit/blocks/wood_set/blocks/leaves.py +180 -0
- anvil_kit/blocks/wood_set/blocks/log.py +149 -0
- anvil_kit/blocks/wood_set/blocks/log_stripped.py +143 -0
- anvil_kit/blocks/wood_set/blocks/planks.py +131 -0
- anvil_kit/blocks/wood_set/blocks/pressure_plate.py +190 -0
- anvil_kit/blocks/wood_set/blocks/sapling.py +119 -0
- anvil_kit/blocks/wood_set/blocks/sign.py +196 -0
- anvil_kit/blocks/wood_set/blocks/slab.py +178 -0
- anvil_kit/blocks/wood_set/blocks/stairs.py +232 -0
- anvil_kit/blocks/wood_set/blocks/trapdoor.py +213 -0
- anvil_kit/blocks/wood_set/blocks/wood.py +153 -0
- anvil_kit/blocks/wood_set/blocks/wood_stripped.py +147 -0
- anvil_kit/blocks/wood_set/components.py +196 -0
- anvil_kit/blocks/wood_set/models/wood_set.bbmodel +1 -0
- anvil_kit/blocks/wood_set/models/wood_set_boat.bbmodel +1 -0
- anvil_kit/blocks/wood_set/typescript/boat.ts +102 -0
- anvil_kit/blocks/wood_set/typescript/constants.ts +92 -0
- anvil_kit/blocks/wood_set/typescript/door.ts +29 -0
- anvil_kit/blocks/wood_set/typescript/index.ts.template +12 -0
- anvil_kit/blocks/wood_set/typescript/interactable.ts +17 -0
- anvil_kit/blocks/wood_set/typescript/leaves.ts +84 -0
- anvil_kit/blocks/wood_set/typescript/redstone-consumer.ts +39 -0
- anvil_kit/blocks/wood_set/typescript/sapling.ts +57 -0
- anvil_kit/blocks/wood_set/typescript/sign.ts +432 -0
- anvil_kit/blocks/wood_set/typescript/slab.ts +110 -0
- anvil_kit/blocks/wood_set/typescript/strippable.ts +41 -0
- anvil_kit/blocks/wood_set/typescript/support.ts +68 -0
- anvil_kit/blocks/wood_set/typescript/togglable.ts +44 -0
- anvil_kit/blocks/wood_set/typescript.py +122 -0
- anvil_kit/world/__init__.py +0 -0
- anvil_kit/world/ldtk.py +320 -0
- anvil_kit/world/potions.py +449 -0
- mcanvil_kit-0.1.1.dist-info/METADATA +76 -0
- mcanvil_kit-0.1.1.dist-info/RECORD +51 -0
- mcanvil_kit-0.1.1.dist-info/WHEEL +5 -0
- mcanvil_kit-0.1.1.dist-info/licenses/LICENSE +21 -0
- mcanvil_kit-0.1.1.dist-info/top_level.txt +1 -0
anvil_kit/__init__.py
ADDED
|
@@ -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
|
+
"""
|
anvil_kit/__version__.py
ADDED
|
@@ -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`."""
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from anvil.api.actors.components import (
|
|
2
|
+
EntityAIRiseToLiquidLevel,
|
|
3
|
+
EntityBodyRotationAlwaysFollowsHead,
|
|
4
|
+
EntityCollisionBox,
|
|
5
|
+
EntityDamageSensor,
|
|
6
|
+
EntityIsCollidable,
|
|
7
|
+
EntityLeashable,
|
|
8
|
+
EntityMovementBasic,
|
|
9
|
+
EntityNavigationGeneric,
|
|
10
|
+
EntityPhysics,
|
|
11
|
+
EntityPushableByBlock,
|
|
12
|
+
EntityPushableByEntity,
|
|
13
|
+
EntityRideable,
|
|
14
|
+
EntityTypeFamily,
|
|
15
|
+
)
|
|
16
|
+
from anvil.api.actors.entity import Entity
|
|
17
|
+
from anvil.api.core.core import CONFIG
|
|
18
|
+
from anvil.api.items.components import (
|
|
19
|
+
ItemDisplayName,
|
|
20
|
+
ItemEntityPlacer,
|
|
21
|
+
ItemFuel,
|
|
22
|
+
ItemIcon,
|
|
23
|
+
ItemLiquidClipped,
|
|
24
|
+
ItemMaxStackSize,
|
|
25
|
+
)
|
|
26
|
+
from anvil.api.items.crafting import ShapedCraftingRecipe
|
|
27
|
+
from anvil.api.items.items import Item
|
|
28
|
+
from anvil.api.logic.molang import Math, Molang, Query, Variable
|
|
29
|
+
from anvil.api.pbr.texture_set import TextureComponents
|
|
30
|
+
from anvil.lib.jsonmodel.enums import (
|
|
31
|
+
DamageSensor,
|
|
32
|
+
ItemCategory,
|
|
33
|
+
ItemGroups,
|
|
34
|
+
RecipeUnlockContext,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
from . import BOAT_MODEL
|
|
38
|
+
|
|
39
|
+
BOAT_FAMILY = "wood_set_boat"
|
|
40
|
+
RIDER_ROTATION = 90
|
|
41
|
+
SEATS = [(0, 0.2, 0.2), (0, 0.2, -0.6)]
|
|
42
|
+
TURNING = 20
|
|
43
|
+
SHAKE_PER_HIT = 0.25
|
|
44
|
+
SHAKE_DECAY = 1
|
|
45
|
+
HITS_WRAP = 16
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def create(wood: str, selected: set[str]) -> tuple[Entity, Item]:
|
|
49
|
+
namespace = CONFIG.NAMESPACE
|
|
50
|
+
entity = Entity(f"{wood}_boat")
|
|
51
|
+
display_name = f"{wood.replace('_', ' ').title()} Boat"
|
|
52
|
+
|
|
53
|
+
entity.client.description.add_geometry(BOAT_MODEL)
|
|
54
|
+
entity.client.description.add_texture(
|
|
55
|
+
blockbench=BOAT_MODEL, component=TextureComponents(color=f"{wood}_boat")
|
|
56
|
+
)
|
|
57
|
+
entity.client.description.add_material("blend", "entity_alphablend")
|
|
58
|
+
entity.client.description.add_material("alpha", "entity_alphatest")
|
|
59
|
+
render = entity.client.description.render_controller("default")
|
|
60
|
+
render.set_geometry(BOAT_MODEL)
|
|
61
|
+
render.add_texture(f"{wood}_boat")
|
|
62
|
+
render.add_part_visibility("chest", False)
|
|
63
|
+
render.material("*", "alpha")
|
|
64
|
+
render.material("water_clip", "blend")
|
|
65
|
+
|
|
66
|
+
yaw_speed = Query.YawSpeed()
|
|
67
|
+
straight = (Math.abs(yaw_speed) <= TURNING) & (Query.GroundSpeed() > 0.5)
|
|
68
|
+
for animation, condition in (
|
|
69
|
+
("paddle_right", yaw_speed > TURNING),
|
|
70
|
+
("paddle_left", yaw_speed < -TURNING),
|
|
71
|
+
("paddle", straight),
|
|
72
|
+
):
|
|
73
|
+
entity.client.description.animation(
|
|
74
|
+
blockbench=BOAT_MODEL,
|
|
75
|
+
animation_name=animation,
|
|
76
|
+
animate=True,
|
|
77
|
+
condition=Query.HasRider() & condition,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
entity.server.description.add_int_property(
|
|
81
|
+
"hits", (0, HITS_WRAP - 1), client_sync=True
|
|
82
|
+
)
|
|
83
|
+
hits = Query.Property("hits")
|
|
84
|
+
entity.client.description.init_vars(shake_strength=0, last_hits=hits)
|
|
85
|
+
entity.client.description.add_script(
|
|
86
|
+
Variable.shake_strength,
|
|
87
|
+
Math.clamp(
|
|
88
|
+
Variable.shake_strength
|
|
89
|
+
- Query.DeltaTime() * SHAKE_DECAY
|
|
90
|
+
+ (Molang.condition(hits != Variable.last_hits, SHAKE_PER_HIT, 0)),
|
|
91
|
+
0,
|
|
92
|
+
1,
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
entity.client.description.add_script(Variable.last_hits, hits)
|
|
96
|
+
entity.client.description.animation(
|
|
97
|
+
blockbench=BOAT_MODEL,
|
|
98
|
+
animation_name="shake",
|
|
99
|
+
animate=True,
|
|
100
|
+
condition=Variable.shake_strength > 0,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
rideable = EntityRideable(
|
|
104
|
+
interact_text="Board", family_types=["player"], seat_count=len(SEATS)
|
|
105
|
+
)
|
|
106
|
+
for min_riders, position in enumerate(SEATS):
|
|
107
|
+
rideable.add_seat(
|
|
108
|
+
position=position,
|
|
109
|
+
max_rider_count=len(SEATS),
|
|
110
|
+
min_rider_count=min_riders,
|
|
111
|
+
lock_rider_rotation=RIDER_ROTATION,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
entity.server.description.config(is_summonable=True, is_spawnable=False)
|
|
115
|
+
entity.server.components.add(
|
|
116
|
+
EntityTypeFamily(family=[BOAT_FAMILY, "boat", "inanimate"]),
|
|
117
|
+
EntityCollisionBox(height=0.455, width=1.4),
|
|
118
|
+
EntityPhysics(push_towards_closest_space=True),
|
|
119
|
+
EntityAIRiseToLiquidLevel(
|
|
120
|
+
priority=0, liquid_y_offset=0, rise_delta=0.005, sink_delta=0.005
|
|
121
|
+
),
|
|
122
|
+
EntityNavigationGeneric(can_sink=False, can_walk=False, can_jump=False),
|
|
123
|
+
EntityMovementBasic(),
|
|
124
|
+
EntityBodyRotationAlwaysFollowsHead(),
|
|
125
|
+
rideable,
|
|
126
|
+
EntityLeashable(),
|
|
127
|
+
EntityDamageSensor().add_trigger(deals_damage=DamageSensor.No),
|
|
128
|
+
EntityIsCollidable(),
|
|
129
|
+
EntityPushableByEntity(),
|
|
130
|
+
EntityPushableByBlock(),
|
|
131
|
+
)
|
|
132
|
+
entity.set_display_name(display_name).queue()
|
|
133
|
+
|
|
134
|
+
item = Item(f"{wood}_boat")
|
|
135
|
+
item.server.components.add(
|
|
136
|
+
ItemDisplayName(value=display_name),
|
|
137
|
+
ItemIcon(textures=TextureComponents(color=f"{wood}_boat")),
|
|
138
|
+
ItemEntityPlacer(entity=entity),
|
|
139
|
+
ItemLiquidClipped(),
|
|
140
|
+
ItemMaxStackSize(value=1),
|
|
141
|
+
ItemFuel(duration=60),
|
|
142
|
+
)
|
|
143
|
+
item.server.description.set_menu_category(ItemCategory.Items, ItemGroups.Boat)
|
|
144
|
+
item.queue()
|
|
145
|
+
|
|
146
|
+
if "planks" in selected:
|
|
147
|
+
planks = f"{namespace}:{wood}_planks"
|
|
148
|
+
recipe = ShapedCraftingRecipe(f"{wood}_boat")
|
|
149
|
+
recipe.ingredients([[planks, None, planks], [planks, planks, planks]])
|
|
150
|
+
recipe.result(item.identifier, 1)
|
|
151
|
+
recipe.unlock_context(RecipeUnlockContext.AlwaysUnlocked)
|
|
152
|
+
recipe.queue()
|
|
153
|
+
|
|
154
|
+
return entity, item
|