litematica-render 0.1.0__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.
- litematica_render-0.1.0/.github/workflows/python-publish.yml +52 -0
- litematica_render-0.1.0/.github/workflows/test.yml +27 -0
- litematica_render-0.1.0/.gitignore +37 -0
- litematica_render-0.1.0/LICENSE +21 -0
- litematica_render-0.1.0/PKG-INFO +52 -0
- litematica_render-0.1.0/README.md +30 -0
- litematica_render-0.1.0/pyproject.toml +34 -0
- litematica_render-0.1.0/src/litematic/__init__.py +34 -0
- litematica_render-0.1.0/src/litematic/parse/__init__.py +1 -0
- litematica_render-0.1.0/src/litematic/parse/errors.py +13 -0
- litematica_render-0.1.0/src/litematic/parse/model.py +225 -0
- litematica_render-0.1.0/src/litematic/parse/nbt.py +167 -0
- litematica_render-0.1.0/src/litematic/parse/parser.py +317 -0
- litematica_render-0.1.0/src/litematic/render/__init__.py +134 -0
- litematica_render-0.1.0/src/litematic/render/errors.py +9 -0
- litematica_render-0.1.0/src/litematic/render/pack/__init__.py +7 -0
- litematica_render-0.1.0/src/litematic/render/pack/blockstate.py +111 -0
- litematica_render-0.1.0/src/litematic/render/pack/compile.py +423 -0
- litematica_render-0.1.0/src/litematic/render/pack/elements.py +421 -0
- litematica_render-0.1.0/src/litematic/render/pack/entities.py +181 -0
- litematica_render-0.1.0/src/litematic/render/pack/extract.py +243 -0
- litematica_render-0.1.0/src/litematic/render/pack/loader.py +186 -0
- litematica_render-0.1.0/src/litematic/render/pack/resolve.py +344 -0
- litematica_render-0.1.0/src/litematic/render/pack/stack.py +83 -0
- litematica_render-0.1.0/src/litematic/render/pack/texture.py +347 -0
- litematica_render-0.1.0/src/litematic/render/png.py +54 -0
- litematica_render-0.1.0/src/litematic/render/quads.py +106 -0
- litematica_render-0.1.0/src/litematic/render/scene/__init__.py +6 -0
- litematica_render-0.1.0/src/litematic/render/scene/isometric.py +579 -0
- litematica_render-0.1.0/src/litematic/render/scene/painter.py +395 -0
- litematica_render-0.1.0/src/litematic/render/shapes/__init__.py +6 -0
- litematica_render-0.1.0/src/litematic/render/shapes/boxes.py +290 -0
- litematica_render-0.1.0/src/litematic/render/shapes/families.py +357 -0
- litematica_render-0.1.0/tests/helpers/__init__.py +0 -0
- litematica_render-0.1.0/tests/helpers/litematica_packer.py +86 -0
- litematica_render-0.1.0/tests/helpers/nbt_writer.py +132 -0
- litematica_render-0.1.0/tests/parse/__init__.py +1 -0
- litematica_render-0.1.0/tests/parse/test_api.py +49 -0
- litematica_render-0.1.0/tests/parse/test_errors.py +20 -0
- litematica_render-0.1.0/tests/parse/test_model.py +152 -0
- litematica_render-0.1.0/tests/parse/test_nbt.py +165 -0
- litematica_render-0.1.0/tests/parse/test_parser.py +330 -0
- litematica_render-0.1.0/tests/parse/test_robustness.py +69 -0
- litematica_render-0.1.0/tests/parse/test_slab.py +114 -0
- litematica_render-0.1.0/tests/parse/test_unpack.py +113 -0
- litematica_render-0.1.0/tests/render/__init__.py +1 -0
- litematica_render-0.1.0/tests/render/pack/__init__.py +0 -0
- litematica_render-0.1.0/tests/render/pack/test_pack_entities.py +232 -0
- litematica_render-0.1.0/tests/render/pack/test_pack_extract.py +2011 -0
- litematica_render-0.1.0/tests/render/pack/test_pack_load.py +535 -0
- litematica_render-0.1.0/tests/render/pack/test_pack_stack.py +436 -0
- litematica_render-0.1.0/tests/render/pack/test_resolve.py +238 -0
- litematica_render-0.1.0/tests/render/scene/__init__.py +0 -0
- litematica_render-0.1.0/tests/render/scene/test_compose.py +1026 -0
- litematica_render-0.1.0/tests/render/scene/test_paint.py +426 -0
- litematica_render-0.1.0/tests/render/scene/test_sizing.py +68 -0
- litematica_render-0.1.0/tests/render/shapes/__init__.py +0 -0
- litematica_render-0.1.0/tests/render/shapes/test_shapes.py +513 -0
- litematica_render-0.1.0/tests/render/test_api.py +181 -0
- litematica_render-0.1.0/tests/render/test_init.py +27 -0
- litematica_render-0.1.0/tests/render/test_png.py +61 -0
- litematica_render-0.1.0/tests/render/test_quads.py +197 -0
- litematica_render-0.1.0/tests/render/test_unresolved.py +102 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Upload Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
release-build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.x"
|
|
20
|
+
|
|
21
|
+
- name: Build release distributions
|
|
22
|
+
run: |
|
|
23
|
+
python -m pip install build
|
|
24
|
+
python -m build
|
|
25
|
+
|
|
26
|
+
- name: Upload distributions
|
|
27
|
+
uses: actions/upload-artifact@v4
|
|
28
|
+
with:
|
|
29
|
+
name: release-dists
|
|
30
|
+
path: dist/
|
|
31
|
+
|
|
32
|
+
pypi-publish:
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
needs:
|
|
35
|
+
- release-build
|
|
36
|
+
permissions:
|
|
37
|
+
id-token: write
|
|
38
|
+
|
|
39
|
+
environment:
|
|
40
|
+
name: pypi
|
|
41
|
+
|
|
42
|
+
steps:
|
|
43
|
+
- name: Retrieve release distributions
|
|
44
|
+
uses: actions/download-artifact@v4
|
|
45
|
+
with:
|
|
46
|
+
name: release-dists
|
|
47
|
+
path: dist/
|
|
48
|
+
|
|
49
|
+
- name: Publish release distributions to PyPI
|
|
50
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
51
|
+
with:
|
|
52
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: ${{ matrix.python-version }}
|
|
20
|
+
- name: Install
|
|
21
|
+
run: pip install -e '.[dev]'
|
|
22
|
+
- name: Ruff
|
|
23
|
+
run: ruff check src tests
|
|
24
|
+
- name: Mypy
|
|
25
|
+
run: mypy src
|
|
26
|
+
- name: Tests
|
|
27
|
+
run: pytest -q
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Bytecode
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
|
|
5
|
+
# Packaging (hatchling)
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
|
|
10
|
+
# Virtual environments
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
|
|
14
|
+
# Test / tool caches
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.mypy_cache/
|
|
17
|
+
.ruff_cache/
|
|
18
|
+
.coverage
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# Editors
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
24
|
+
|
|
25
|
+
# OS junk (Windows / macOS)
|
|
26
|
+
Thumbs.db
|
|
27
|
+
.DS_Store
|
|
28
|
+
|
|
29
|
+
# Local-only files (not tracked)
|
|
30
|
+
AGENTS.md
|
|
31
|
+
GLOSSARY.md
|
|
32
|
+
docs/
|
|
33
|
+
test/
|
|
34
|
+
.scratch
|
|
35
|
+
|
|
36
|
+
# Superpowers SDD workspace
|
|
37
|
+
.superpowers/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 late_maple
|
|
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,52 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: litematica-render
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Parse Minecraft Litematica schematics and render them to isometric PNGs
|
|
5
|
+
Project-URL: Homepage, https://github.com/late-maple/Litematica-Render
|
|
6
|
+
Author: late-maple
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Games/Entertainment
|
|
11
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: numpy
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
16
|
+
Requires-Dist: pillow>=9.1; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
19
|
+
Provides-Extra: pack
|
|
20
|
+
Requires-Dist: pillow>=9.1; extra == 'pack'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# Litematica-Render
|
|
24
|
+
|
|
25
|
+
Offline isometric rendering of Minecraft Litematica `.litematic` schematics.
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Parse `.litematic` files: streaming NBT, lazy vectorized region unpacking
|
|
30
|
+
- Render isometric PNGs from a resource pack's real blockstates, models, and textures
|
|
31
|
+
- Pack stack: layer add-on packs (e.g. Faithful 32x) over a vanilla base, MC-style first-hit lookup
|
|
32
|
+
|
|
33
|
+
## Example
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from litematic import load
|
|
37
|
+
from litematic.render import isometric_png, unresolved_colors
|
|
38
|
+
|
|
39
|
+
schem = load("schematic.litematic")
|
|
40
|
+
|
|
41
|
+
png = isometric_png(
|
|
42
|
+
schem,
|
|
43
|
+
textures_path="vanilla-assets.zip", # base pack, required
|
|
44
|
+
extra_packs=["Faithful 32x.zip"], # add-ons, earlier = higher priority
|
|
45
|
+
max_size=2048,
|
|
46
|
+
)
|
|
47
|
+
with open("render.png", "wb") as f:
|
|
48
|
+
f.write(png)
|
|
49
|
+
|
|
50
|
+
# block names the pack stack cannot cover; those render magenta
|
|
51
|
+
missing = unresolved_colors(schem, textures_path="vanilla-assets.zip")
|
|
52
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Litematica-Render
|
|
2
|
+
|
|
3
|
+
Offline isometric rendering of Minecraft Litematica `.litematic` schematics.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Parse `.litematic` files: streaming NBT, lazy vectorized region unpacking
|
|
8
|
+
- Render isometric PNGs from a resource pack's real blockstates, models, and textures
|
|
9
|
+
- Pack stack: layer add-on packs (e.g. Faithful 32x) over a vanilla base, MC-style first-hit lookup
|
|
10
|
+
|
|
11
|
+
## Example
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from litematic import load
|
|
15
|
+
from litematic.render import isometric_png, unresolved_colors
|
|
16
|
+
|
|
17
|
+
schem = load("schematic.litematic")
|
|
18
|
+
|
|
19
|
+
png = isometric_png(
|
|
20
|
+
schem,
|
|
21
|
+
textures_path="vanilla-assets.zip", # base pack, required
|
|
22
|
+
extra_packs=["Faithful 32x.zip"], # add-ons, earlier = higher priority
|
|
23
|
+
max_size=2048,
|
|
24
|
+
)
|
|
25
|
+
with open("render.png", "wb") as f:
|
|
26
|
+
f.write(png)
|
|
27
|
+
|
|
28
|
+
# block names the pack stack cannot cover; those render magenta
|
|
29
|
+
missing = unresolved_colors(schem, textures_path="vanilla-assets.zip")
|
|
30
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "litematica-render"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Parse Minecraft Litematica schematics and render them to isometric PNGs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "late-maple" }]
|
|
13
|
+
dependencies = ["numpy"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Topic :: Games/Entertainment",
|
|
17
|
+
"Topic :: Multimedia :: Graphics",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/late-maple/Litematica-Render"
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
dev = ["pytest", "ruff", "mypy", "Pillow>=9.1"]
|
|
25
|
+
pack = ["Pillow>=9.1"]
|
|
26
|
+
|
|
27
|
+
[tool.hatch.version]
|
|
28
|
+
path = "src/litematic/__init__.py"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/litematic"]
|
|
32
|
+
|
|
33
|
+
[tool.ruff.lint]
|
|
34
|
+
select = ["E", "F", "I"]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""litematic - read-only parser for Minecraft Litematica .litematic schematics.
|
|
2
|
+
|
|
3
|
+
Instances are not thread-safe: parse and query a Litematic from a single
|
|
4
|
+
thread or asyncio task at a time.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from litematic.parse.errors import LitematicError, LitematicFormatError, NbtError
|
|
8
|
+
from litematic.parse.model import (
|
|
9
|
+
BlockEntity,
|
|
10
|
+
BlockState,
|
|
11
|
+
Entity,
|
|
12
|
+
Litematic,
|
|
13
|
+
LitematicMetadata,
|
|
14
|
+
Region,
|
|
15
|
+
Vec3i,
|
|
16
|
+
)
|
|
17
|
+
from litematic.parse.parser import load, loads
|
|
18
|
+
|
|
19
|
+
__version__ = "0.1.0"
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"BlockEntity",
|
|
23
|
+
"BlockState",
|
|
24
|
+
"Entity",
|
|
25
|
+
"Litematic",
|
|
26
|
+
"LitematicError",
|
|
27
|
+
"LitematicFormatError",
|
|
28
|
+
"LitematicMetadata",
|
|
29
|
+
"NbtError",
|
|
30
|
+
"Region",
|
|
31
|
+
"Vec3i",
|
|
32
|
+
"load",
|
|
33
|
+
"loads",
|
|
34
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Parsing core: NBT reading, data model, and .litematic decoding."""
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Public exception tree for litematic."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LitematicError(Exception):
|
|
5
|
+
"""Base class for all exceptions raised by this library."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class NbtError(LitematicError):
|
|
9
|
+
"""Input is not valid Java NBT: bad tag type, truncated stream, bad compression."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LitematicFormatError(LitematicError):
|
|
13
|
+
"""Input is valid NBT but violates the .litematic structure constraints."""
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""Read-only data model: metadata, block states, and lazily materialized regions."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from types import MappingProxyType
|
|
5
|
+
from typing import Callable, Mapping, NamedTuple, Optional, Sequence
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Vec3i(NamedTuple):
|
|
11
|
+
"""A 3D integer vector (x, y, z)."""
|
|
12
|
+
|
|
13
|
+
x: int
|
|
14
|
+
y: int
|
|
15
|
+
z: int
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class BlockState:
|
|
20
|
+
"""A palette entry: block id plus blockstate properties."""
|
|
21
|
+
|
|
22
|
+
name: str
|
|
23
|
+
properties: Mapping[str, str] = field(default_factory=dict)
|
|
24
|
+
|
|
25
|
+
def __post_init__(self) -> None:
|
|
26
|
+
object.__setattr__(
|
|
27
|
+
self, "properties", MappingProxyType(dict(self.properties))
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def __hash__(self) -> int:
|
|
31
|
+
return hash((self.name, frozenset(self.properties.items())))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True)
|
|
35
|
+
class LitematicMetadata:
|
|
36
|
+
"""Schematic-level metadata from the Metadata compound."""
|
|
37
|
+
|
|
38
|
+
name: str
|
|
39
|
+
author: str
|
|
40
|
+
description: str
|
|
41
|
+
enclosing_size: Vec3i
|
|
42
|
+
total_blocks: int
|
|
43
|
+
total_volume: int
|
|
44
|
+
time_created: int
|
|
45
|
+
time_modified: int
|
|
46
|
+
MinecraftDataVersion: int
|
|
47
|
+
LitematicVersion: int
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class BlockEntity:
|
|
52
|
+
"""A tile entity: position, id, and its raw NBT payload as a plain mapping.
|
|
53
|
+
|
|
54
|
+
The mapping is read-only at the top level only; nested compounds
|
|
55
|
+
(a chest's items, for example) stay mutable dicts.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
pos: tuple[int, int, int]
|
|
59
|
+
id: str
|
|
60
|
+
data: Mapping[str, object]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(frozen=True)
|
|
64
|
+
class Entity:
|
|
65
|
+
"""An entity: id, position, and its raw NBT payload as a plain mapping.
|
|
66
|
+
|
|
67
|
+
The mapping is read-only at the top level only; nested compounds
|
|
68
|
+
stay mutable dicts.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
id: str
|
|
72
|
+
pos: tuple[float, float, float]
|
|
73
|
+
data: Mapping[str, object]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass(frozen=True)
|
|
77
|
+
class Litematic:
|
|
78
|
+
"""A parsed schematic: metadata plus named regions.
|
|
79
|
+
|
|
80
|
+
`regions` is exposed as a read-only mapping.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
metadata: LitematicMetadata
|
|
84
|
+
regions: Mapping[str, "Region"]
|
|
85
|
+
|
|
86
|
+
def __post_init__(self) -> None:
|
|
87
|
+
object.__setattr__(self, "regions", MappingProxyType(self.regions))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Region:
|
|
91
|
+
"""One schematic region.
|
|
92
|
+
|
|
93
|
+
Block data is kept in packed form; `block_indices` materializes it on
|
|
94
|
+
first access and caches the result until `release()`.
|
|
95
|
+
`pending_block_ticks`/`pending_fluid_ticks` are sequences of scheduled-tick
|
|
96
|
+
compounds ({x, y, z, Time, Priority, Block or Fluid, SubTick}), retained
|
|
97
|
+
verbatim (semantics defined by the writing Litematica version).
|
|
98
|
+
Not thread-safe.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
def __init__(
|
|
102
|
+
self,
|
|
103
|
+
name: str,
|
|
104
|
+
position: Vec3i,
|
|
105
|
+
size: Vec3i,
|
|
106
|
+
palette: Sequence[BlockState],
|
|
107
|
+
block_entities: tuple[BlockEntity, ...],
|
|
108
|
+
entities: tuple[Entity, ...],
|
|
109
|
+
pending_block_ticks: Optional[tuple[Mapping[str, object], ...]],
|
|
110
|
+
pending_fluid_ticks: Optional[tuple[Mapping[str, object], ...]],
|
|
111
|
+
packed_indices: np.ndarray,
|
|
112
|
+
_unpack: Callable[[], np.ndarray],
|
|
113
|
+
_unpack_slab: Optional[Callable[[int, int], np.ndarray]] = None,
|
|
114
|
+
) -> None:
|
|
115
|
+
self._name = name
|
|
116
|
+
self._position = position
|
|
117
|
+
self._size = size
|
|
118
|
+
self._palette = tuple(palette)
|
|
119
|
+
self._block_entities = block_entities
|
|
120
|
+
self._entities = entities
|
|
121
|
+
self._pending_block_ticks = pending_block_ticks
|
|
122
|
+
self._pending_fluid_ticks = pending_fluid_ticks
|
|
123
|
+
# Read-only view: the caller keeps ownership of the array it passed.
|
|
124
|
+
packed = packed_indices.view()
|
|
125
|
+
packed.flags.writeable = False
|
|
126
|
+
self._packed_indices = packed
|
|
127
|
+
self._unpack = _unpack
|
|
128
|
+
self._unpack_slab = _unpack_slab
|
|
129
|
+
self._indices: Optional[np.ndarray] = None
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def name(self) -> str:
|
|
133
|
+
"""Region name as written in the file."""
|
|
134
|
+
return self._name
|
|
135
|
+
|
|
136
|
+
@property
|
|
137
|
+
def position(self) -> Vec3i:
|
|
138
|
+
"""Min corner in schematic coordinates (negative sizes normalized)."""
|
|
139
|
+
return self._position
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def size(self) -> Vec3i:
|
|
143
|
+
"""Region extents along x, y, z; always positive."""
|
|
144
|
+
return self._size
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def palette(self) -> tuple[BlockState, ...]:
|
|
148
|
+
"""Block states addressable by the values in `block_indices`."""
|
|
149
|
+
return self._palette
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def block_entities(self) -> tuple[BlockEntity, ...]:
|
|
153
|
+
"""Tile entities (chests, signs, spawners, ...) in this region."""
|
|
154
|
+
return self._block_entities
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def entities(self) -> tuple[Entity, ...]:
|
|
158
|
+
"""Entities (mobs, items, item frames, ...) in this region."""
|
|
159
|
+
return self._entities
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def pending_block_ticks(self) -> Optional[tuple[Mapping[str, object], ...]]:
|
|
163
|
+
"""Scheduled block ticks, one compound per tick; None if absent."""
|
|
164
|
+
return self._pending_block_ticks
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def pending_fluid_ticks(self) -> Optional[tuple[Mapping[str, object], ...]]:
|
|
168
|
+
"""Scheduled fluid ticks, one compound per tick; None if absent."""
|
|
169
|
+
return self._pending_fluid_ticks
|
|
170
|
+
|
|
171
|
+
@property
|
|
172
|
+
def packed_indices(self) -> np.ndarray:
|
|
173
|
+
"""The raw packed BlockStates long array, read-only."""
|
|
174
|
+
return self._packed_indices
|
|
175
|
+
|
|
176
|
+
@property
|
|
177
|
+
def is_unpacked(self) -> bool:
|
|
178
|
+
"""Whether `block_indices` is currently materialized."""
|
|
179
|
+
return self._indices is not None
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def block_indices(self) -> np.ndarray:
|
|
183
|
+
"""Palette indices as a read-only (x, y, z) array; materializes lazily."""
|
|
184
|
+
if self._indices is None:
|
|
185
|
+
indices = self._unpack()
|
|
186
|
+
indices.flags.writeable = False
|
|
187
|
+
self._indices = indices
|
|
188
|
+
return self._indices
|
|
189
|
+
|
|
190
|
+
def slab_indices(self, y0: int, y1: int) -> np.ndarray:
|
|
191
|
+
"""Palette indices for rows [y0, y1), shape (x, y1-y0, z); not cached.
|
|
192
|
+
|
|
193
|
+
Unpacks only the slab's contiguous entry span of the packed stream
|
|
194
|
+
when the parser injected a slab unpacker, so callers can stream a
|
|
195
|
+
region without ever materializing `block_indices`.
|
|
196
|
+
"""
|
|
197
|
+
if not (0 <= y0 < y1 <= self._size.y):
|
|
198
|
+
raise IndexError(
|
|
199
|
+
f"Slab rows out of range: [{y0}, {y1}) for size {self._size}"
|
|
200
|
+
)
|
|
201
|
+
if self._unpack_slab is not None:
|
|
202
|
+
arr = self._unpack_slab(y0, y1)
|
|
203
|
+
else:
|
|
204
|
+
arr = np.ascontiguousarray(self.block_indices[:, y0:y1, :])
|
|
205
|
+
arr.flags.writeable = False
|
|
206
|
+
return arr
|
|
207
|
+
|
|
208
|
+
def get_block(self, x: int, y: int, z: int) -> BlockState:
|
|
209
|
+
"""Return the block state at local coordinates (x, y, z).
|
|
210
|
+
|
|
211
|
+
Out-of-range coordinates are a caller bug and raise IndexError;
|
|
212
|
+
file corruption raises LitematicFormatError on first unpack.
|
|
213
|
+
"""
|
|
214
|
+
size_x, size_y, size_z = self._size
|
|
215
|
+
if not (0 <= x < size_x and 0 <= y < size_y and 0 <= z < size_z):
|
|
216
|
+
raise IndexError(
|
|
217
|
+
f"Block coordinates out of range: ({x}, {y}, {z})"
|
|
218
|
+
f" for size {self._size}"
|
|
219
|
+
)
|
|
220
|
+
index = int(self.block_indices[x, y, z])
|
|
221
|
+
return self._palette[index]
|
|
222
|
+
|
|
223
|
+
def release(self) -> None:
|
|
224
|
+
"""Drop the materialized `block_indices` cache to reclaim memory."""
|
|
225
|
+
self._indices = None
|