Compare commits
99 commits
Author | SHA1 | Date | |
---|---|---|---|
118034dd27 | |||
ca880ab3b4 | |||
dd56e842b5 | |||
69b62576ea | |||
58f2ff53b9 | |||
42b302f493 | |||
5f84ec8ed2 | |||
ba6e4bae7f | |||
442009eb08 | |||
23b2f274be | |||
3008203080 | |||
d638c810f2 | |||
6e5b958912 | |||
974a0f37df | |||
54ea2b2f28 | |||
6a54f57c50 | |||
dca365f4e2 | |||
e600a9dabb | |||
0f52f6a2c1 | |||
d6cd0fc53b | |||
c49ad6e608 | |||
5ee826a11b | |||
775fcb2d1b | |||
7bba5bae55 | |||
5c85687554 | |||
708fb9645d | |||
53a0f24600 | |||
404ad74235 | |||
deb232ddf3 | |||
fbdd5ed457 | |||
b1c0f316cb | |||
7686996fd3 | |||
b8a5d1580b | |||
f8c8ca78ba | |||
40bc6cd2a9 | |||
5ee8e493d4 | |||
6e2f2697fc | |||
24c266fc78 | |||
0a08e8cc46 | |||
90f2c5fdd0 | |||
8cb1eee60b | |||
282f62fc30 | |||
7bc15f97de | |||
901489dbc3 | |||
dba3dd551e | |||
850b1a668b | |||
3b5ce82873 | |||
cb0aa235db | |||
d02ca9aea2 | |||
c10e9e4902 | |||
37126f69fc | |||
971afea727 | |||
f661f854a4 | |||
1d9be9a41c | |||
a25b3cdbd7 | |||
d96bb727f7 | |||
0dd36a409a | |||
a10151a4f3 | |||
d7fc95c950 | |||
561a1e6577 | |||
0bf1d46aad | |||
a2f0ad401d | |||
ec309dc15f | |||
6763e2b4ec | |||
c23b53a8c3 | |||
bb11b29e92 | |||
28a191a23a | |||
52572a9e81 | |||
b9cd94b235 | |||
f9954d1ce4 | |||
a67bdb3b67 | |||
0a3f6d7765 | |||
ff6e28d381 | |||
9375af8d54 | |||
7f329ac8e7 | |||
650cd23198 | |||
941cd16337 | |||
c1d2eaa17e | |||
00237101f2 | |||
8f408e78a0 | |||
7b98954c80 | |||
00216341ca | |||
83bd936f80 | |||
9b3b345318 | |||
11e25106cf | |||
491ec5cdca | |||
feaf90c96c | |||
4933d8e15f | |||
![]() |
2156bff59a | ||
7b44ee30d6 | |||
f9a03b332c | |||
f43e84eb2b | |||
269f08d356 | |||
f1bc18add1 | |||
6d6f3e5b49 | |||
414ad5a493 | |||
7f3e47fcb4 | |||
bc8219772f | |||
661da4698d |
4
.dockerignore
Normal file
|
@ -0,0 +1,4 @@
|
|||
*
|
||||
!/Cargo.*
|
||||
!/src
|
||||
!/crates
|
124
.github/workflows/MinedMap.yml
vendored
|
@ -1,5 +1,14 @@
|
|||
name: 'MinedMap'
|
||||
on: ['push', 'pull_request', 'workflow_dispatch']
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'main'
|
||||
workflow_dispatch: {}
|
||||
|
||||
env:
|
||||
RUSTFLAGS: -Dwarnings
|
||||
|
@ -7,7 +16,7 @@ env:
|
|||
|
||||
jobs:
|
||||
viewer:
|
||||
runs-on: 'ubuntu-20.04'
|
||||
runs-on: 'ubuntu-latest'
|
||||
|
||||
steps:
|
||||
- name: 'Checkout'
|
||||
|
@ -25,9 +34,10 @@ jobs:
|
|||
pkgdir='build/pkg/MinedMap-${{ steps.tag.outputs.tag }}-viewer'
|
||||
mkdir -p "$pkgdir"
|
||||
cp -r viewer/* "$pkgdir"/
|
||||
rm "$pkgdir"/Dockerfile
|
||||
|
||||
- name: 'Archive'
|
||||
uses: 'actions/upload-artifact@v3'
|
||||
uses: 'actions/upload-artifact@v4'
|
||||
with:
|
||||
name: 'MinedMap-${{ steps.tag.outputs.tag }}-viewer'
|
||||
path: 'build/pkg'
|
||||
|
@ -38,7 +48,7 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: '1.86'
|
||||
components: rustfmt
|
||||
- run: cargo fmt --all -- --check
|
||||
|
||||
|
@ -48,7 +58,7 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: '1.86'
|
||||
components: clippy
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- uses: actions-rs/clippy-check@v1
|
||||
|
@ -62,7 +72,7 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: '1.86'
|
||||
components: rust-docs
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- run: cargo doc --workspace --no-deps --document-private-items
|
||||
|
@ -73,12 +83,11 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
rust: [stable]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
toolchain: '1.86'
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- run: cargo test --workspace
|
||||
- run: cargo test --workspace --no-default-features
|
||||
|
@ -91,9 +100,9 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: 'macos-11'
|
||||
- os: 'macos-13'
|
||||
target: 'aarch64-apple-darwin'
|
||||
- os: 'macos-11'
|
||||
- os: 'macos-13'
|
||||
target: 'x86_64-apple-darwin'
|
||||
- os: 'windows-2019'
|
||||
target: 'x86_64-pc-windows-msvc'
|
||||
|
@ -101,7 +110,7 @@ jobs:
|
|||
- os: 'windows-2019'
|
||||
target: 'i686-pc-windows-msvc'
|
||||
ext: '.exe'
|
||||
- os: 'ubuntu-20.04'
|
||||
- os: 'ubuntu-22.04'
|
||||
target: 'x86_64-unknown-linux-gnu'
|
||||
|
||||
steps:
|
||||
|
@ -118,10 +127,12 @@ jobs:
|
|||
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: '1.86'
|
||||
targets: '${{ matrix.target }}'
|
||||
|
||||
- uses: swatinem/rust-cache@v2
|
||||
with:
|
||||
key: '${{ matrix.target }}'
|
||||
|
||||
- name: 'Build'
|
||||
shell: 'bash'
|
||||
|
@ -134,7 +145,94 @@ jobs:
|
|||
cp target/${{ matrix.target }}/release/minedmap${{ matrix.ext }} "$pkgdir"/
|
||||
|
||||
- name: 'Archive'
|
||||
uses: 'actions/upload-artifact@v3'
|
||||
uses: 'actions/upload-artifact@v4'
|
||||
with:
|
||||
name: 'MinedMap-${{ steps.tag.outputs.tag }}-${{ matrix.target }}'
|
||||
path: 'target/pkg'
|
||||
|
||||
build-container:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- test
|
||||
steps:
|
||||
- name: 'Checkout'
|
||||
uses: 'actions/checkout@v4'
|
||||
|
||||
- name: 'Get version'
|
||||
id: 'tag'
|
||||
run: |
|
||||
set -o pipefail
|
||||
git fetch --prune --unshallow --tags -f
|
||||
echo "tag=$(git describe --abbrev=7 --match='v*' | sed 's/^v//')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/neocturne/minedmap/minedmap
|
||||
tags: |
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
type=ref,event=branch
|
||||
type=ref,event=branch,suffix=-{{sha}}
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
- name: Login to GHCR
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
build-args: |
|
||||
MINEDMAP_VERSION=${{ steps.tag.outputs.tag }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
viewer-container:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- test
|
||||
steps:
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/neocturne/minedmap/viewer
|
||||
tags: |
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
type=ref,event=branch
|
||||
type=ref,event=branch,suffix=-{{sha}}
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
- name: Login to GHCR
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: "{{defaultContext}}:viewer"
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
|
112
CHANGELOG.md
|
@ -2,6 +2,111 @@
|
|||
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for Minecraft 1.21.5
|
||||
|
||||
Added new block types and handling for changed sign text storage format.
|
||||
|
||||
## [2.5.0] - 2025-03-16
|
||||
|
||||
### Added
|
||||
|
||||
- Added experimental watch mode
|
||||
|
||||
Passing `--watch` will cause MinedMap to run continuously instead of exiting
|
||||
after map generation, regenerating tiles whenever they change.
|
||||
|
||||
`--watch-delay` can be used to configure the delay between detecting a change
|
||||
and runing the map generation, also limiting how often the regeneration
|
||||
happens. This defaults to `30s`; significantly smaller values probably don't
|
||||
make sense because Minecraft writes out changes in batches anyways.
|
||||
|
||||
Finally, `--jobs-initial` can be used to configure the number of parallel
|
||||
generation threads for the initial cycle separately from the value used for
|
||||
subsequent cycles after a change is detected (`-j`/`--jobs`). Subsequent
|
||||
cycles usually need to regenerate only a small number of tiles, so setting
|
||||
`--jobs` to a smaller value than `--jobs-initial` may be advantageous.
|
||||
|
||||
- Added jemalloc support to fix performace on musl targets
|
||||
|
||||
The global allocator can be switched to jemalloc by enabling the `jemalloc`
|
||||
cargo feature now. This is not the default because it is not always faster
|
||||
than the default system allocator; in particular, the glibc allocator has
|
||||
slightly better performance in multithreaded mode. In addition, jemalloc
|
||||
uses a bit more memory.
|
||||
|
||||
In addition, the `jemalloc-auto` feature has been introduced, which is enabled
|
||||
by default and sets the global allocator to jemalloc on platforms where it is
|
||||
clearly advantageous. For now, this is only done on musl-based targets, as
|
||||
musl's default allocator is very slow in multithreaded operation (which was
|
||||
making higher thread counts like `-j8` basically useless due to 7-8x
|
||||
slowdowns). With the new default, performance on musl is basically identical
|
||||
to glibc.
|
||||
|
||||
Note that some platforms like `msvc` are unsupported by jemalloc, and trying
|
||||
to enable the `jemalloc` feature on these platforms may break the MinedMap
|
||||
build or cause issues at runtime.
|
||||
- Docker images can be downloaded from the GitHub Container registry
|
||||
|
||||
Two images are provided, one for the tile renderer and one with the viewer
|
||||
and a web server. A `docker-compose.yml` example can be found in the
|
||||
repository as a starting point.
|
||||
|
||||
### Changed
|
||||
|
||||
- Unknown biome types (from not yet supported or modded versions of Minecraft)
|
||||
will now use plains biome colors as a fallback instead of resulting in water,
|
||||
grass and foliage blocks to be rendered as transparent pixels
|
||||
- Switched from zlib-ng to zlib-rs
|
||||
|
||||
This should have no noticable effect on the usage of MinedMap, but avoids
|
||||
an external build dependency on CMake.
|
||||
- Small (1-block) seagrass is now visible on the map
|
||||
|
||||
1-block seagrass in 1-block deep water would previously result in the ground
|
||||
to be shown instead of water, as MinedMap currently doesn't handle the
|
||||
"waterlogged" block status. As 1-block seagrass is relatively big compared to
|
||||
other "small" plants, just considering it opaque seems like a good enough
|
||||
solution that avoids having to implement advanced block status flags.
|
||||
- Use Bincode 2 for storage of intermediate data
|
||||
|
||||
The update from Bincode 1 to 2 slightly reduces the size of the `processed`
|
||||
directory used for intermediate data. At least Rust 1.85 is now required to
|
||||
build MinedMap.
|
||||
|
||||
## [2.4.0] - 2025-01-11
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for rendering tiles in WebP format using the `--image-format` option
|
||||
|
||||
## [2.3.1] - 2025-01-06
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix text colors for signs modified using dye
|
||||
- Fix text colors specified using `#rrggbb` CSS syntax in JSON text
|
||||
|
||||
Only named colors specified via JSON text were working as intended.
|
||||
|
||||
The mapping of color names to values is now handled by the generator. Both the generator and the
|
||||
viewer must be updated for sign text colors to work.
|
||||
|
||||
## [2.3.0] - 2025-01-02
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for Minecraft 1.21.4 block types
|
||||
- Added support for Minecraft 1.21.4 Pale Garden biome
|
||||
- viewer: added images for pale oak signs
|
||||
|
||||
## [2.2.0] - 2024-06-23
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for Minecraft 1.21 block types
|
||||
|
||||
## [2.1.1] - 2024-06-14
|
||||
|
||||
### Fixed
|
||||
|
@ -89,7 +194,12 @@ intermediate data.
|
|||
Full support for custom biomes datapacks might be added in a future release.
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/neocturne/MinedMap/compare/v2.1.1...HEAD
|
||||
[Unreleased]: https://github.com/neocturne/MinedMap/compare/v2.5.0...HEAD
|
||||
[2.5.0]: https://github.com/neocturne/MinedMap/compare/v2.4.0...v2.5.0
|
||||
[2.4.0]: https://github.com/neocturne/MinedMap/compare/v2.3.1...v2.4.0
|
||||
[2.3.1]: https://github.com/neocturne/MinedMap/compare/v2.3.0...v2.3.1
|
||||
[2.3.0]: https://github.com/neocturne/MinedMap/compare/v2.2.0...v2.3.0
|
||||
[2.2.0]: https://github.com/neocturne/MinedMap/compare/v2.1.1...v2.2.0
|
||||
[2.1.1]: https://github.com/neocturne/MinedMap/compare/v2.1.0...v2.1.1
|
||||
[2.1.0]: https://github.com/neocturne/MinedMap/compare/v2.0.2...v2.1.0
|
||||
[2.0.2]: https://github.com/neocturne/MinedMap/compare/v2.0.1...v2.0.2
|
||||
|
|
947
Cargo.lock
generated
32
Cargo.toml
|
@ -2,7 +2,7 @@
|
|||
members = ["crates/*"]
|
||||
|
||||
[workspace.package]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/neocturne/MinedMap"
|
||||
|
@ -13,7 +13,7 @@ pre-release-commit-message = "{{crate_name}} {{version}}"
|
|||
|
||||
[package]
|
||||
name = "minedmap"
|
||||
version = "2.1.1"
|
||||
version = "2.5.0"
|
||||
description = "Generate browsable maps from Minecraft save data"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
@ -38,24 +38,29 @@ pre-release-replacements = [
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.68"
|
||||
bincode = "1.3.3"
|
||||
bincode = "2.0.1"
|
||||
clap = { version = "4.1.4", features = ["derive", "wrap_help"] }
|
||||
enum-map = "2.7.3"
|
||||
fastnbt = "2.3.2"
|
||||
flate2 = { version = "1.1.0", features = ["zlib-rs"] }
|
||||
futures-util = "0.3.28"
|
||||
git-version = "0.3.5"
|
||||
image = { version = "0.24.5", default-features = false, features = ["png"] }
|
||||
indexmap = { version = "2.0.0", features = ["serde"] }
|
||||
lru = "0.12.0"
|
||||
minedmap-nbt = { version = "0.1.1", path = "crates/nbt", default-features = false }
|
||||
minedmap-resource = { version = "0.3.0", path = "crates/resource" }
|
||||
minedmap-types = { version = "0.1.2", path = "crates/types" }
|
||||
humantime = "2.1.0"
|
||||
image = { version = "0.25.1", default-features = false, features = ["png", "webp"] }
|
||||
indexmap = "2.0.0"
|
||||
lru = "0.13.0"
|
||||
minedmap-default-alloc = { version = "0.1.0", path = "crates/default-alloc", optional = true }
|
||||
minedmap-nbt = { version = "0.2.0", path = "crates/nbt", default-features = false }
|
||||
minedmap-resource = { version = "0.7.0", path = "crates/resource" }
|
||||
minedmap-types = { version = "0.2.0", path = "crates/types" }
|
||||
notify = "8.0.0"
|
||||
num-integer = "0.1.45"
|
||||
num_cpus = "1.16.0"
|
||||
phf = { version = "0.11.2", features = ["macros"] }
|
||||
rayon = "1.7.0"
|
||||
regex = "1.10.2"
|
||||
rustc-hash = "1.1.0"
|
||||
serde = { version = "1.0.152", features = ["rc", "derive"] }
|
||||
rustc-hash = "2.0.0"
|
||||
serde = { version = "1.0.152", features = ["derive"] }
|
||||
serde_json = "1.0.99"
|
||||
tokio = { version = "1.31.0", features = ["rt", "parking_lot", "sync"] }
|
||||
tracing = "0.1.37"
|
||||
|
@ -63,5 +68,6 @@ tracing-subscriber = "0.3.17"
|
|||
zstd = "0.13.0"
|
||||
|
||||
[features]
|
||||
default = ["zlib-ng"]
|
||||
zlib-ng = ["minedmap-nbt/zlib-ng"]
|
||||
default = ["jemalloc-auto"]
|
||||
jemalloc-auto = ["dep:minedmap-default-alloc"]
|
||||
jemalloc = ["jemalloc-auto", "minedmap-default-alloc/jemalloc"]
|
||||
|
|
17
Dockerfile
Normal file
|
@ -0,0 +1,17 @@
|
|||
FROM docker.io/library/rust:1.85.1-alpine AS builder
|
||||
|
||||
WORKDIR /build
|
||||
RUN apk add --no-cache build-base tini-static
|
||||
|
||||
ARG MINEDMAP_VERSION
|
||||
|
||||
COPY . .
|
||||
RUN cargo build -r
|
||||
RUN strip target/release/minedmap
|
||||
|
||||
FROM scratch
|
||||
|
||||
COPY --from=builder /sbin/tini-static /build/target/release/minedmap /bin/
|
||||
ENTRYPOINT [ "/bin/tini-static", "--", "/bin/minedmap" ]
|
||||
|
||||
USER 1000:1000
|
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2015 Matthias Schiffer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
25
README.md
|
@ -2,7 +2,7 @@
|
|||
|
||||
* Render beautiful maps of your [Minecraft](https://minecraft.net/) worlds!
|
||||
* Put them on a webserver and view them in your browser!
|
||||
* Compatible with unmodified Minecraft Java Edition 1.8 up to 1.20 (no mod installation necessary!)
|
||||
* Compatible with unmodified Minecraft Java Edition 1.8 up to 1.21.4 (no mod installation required!)
|
||||
* Illumination layer: the world at night
|
||||
* Fast: create a full map for a huge 3GB savegame in less than 5 minutes in single-threaded operation
|
||||
* Multi-threading support: pass `-j N` to the renderer to use `N` parallel threads for generation
|
||||
|
@ -55,9 +55,18 @@ a proper webserver like [nginx](https://nginx.org/) or upload the viewer togethe
|
|||
the generated map files to public webspace to make the map available to others.
|
||||
|
||||
If you are uploading the directory to a remote webserver, you do not need to upload the
|
||||
`<viewer>/data/processed` directory, as that is only used locally to allow processing
|
||||
`<viewer>/data/processed` directory, as it is only used locally to allow processing
|
||||
updates more quickly.
|
||||
|
||||
### Image formats
|
||||
|
||||
MinedMap renders map tiles as PNG by default. Pass `--image-format webp` to select
|
||||
WebP instead. For typical Minecraft worlds, using WebP reduces file sizes by 20-25%
|
||||
without increasing processing time.
|
||||
|
||||
MinedMap always uses lossless compression for tile images, regardless of the
|
||||
image format.
|
||||
|
||||
### Signs
|
||||
|
||||

|
||||
|
@ -89,9 +98,14 @@ matches.
|
|||
Finally, `--sign-transform` allows to specify sed-style replacement patterns to
|
||||
modify the text displayed on the map. This can be used if the text matched by
|
||||
`--sign-prefix` or `--sign-filter` should not be displayed:
|
||||
`--sign-filter 's/\[Map\]//'` would replace each occurence of "\[Map\]" with
|
||||
`--sign-transform 's/\[Map\]//'` would replace each occurence of "\[Map\]" with
|
||||
the empty string.
|
||||
|
||||
**Note:** On Windows, double quotes (`"`) must be used for arguments instead
|
||||
of single quotes (`'`), and all backslashes in the arguments must be escaped
|
||||
by doubling them. This can make regular expressions somewhat difficult to
|
||||
write and to read.
|
||||
|
||||
## Installation
|
||||
|
||||
Binary builds of the map generator for Linux and Windows, as well as an archive
|
||||
|
@ -103,11 +117,6 @@ or newer). The following command can be used to build the current development ve
|
|||
cargo install --git 'https://github.com/neocturne/MinedMap.git'
|
||||
```
|
||||
|
||||
In addition, CMake is needed to build the zlib-ng library. If you do not have
|
||||
CMake installed, you can disable the zlib-ng feature by passing `--no-default-features`
|
||||
to cargo. A pure-Rust zlib implementation will be used, which is more portable,
|
||||
but slower than zlib-ng.
|
||||
|
||||
If you are looking for the older C++ implementation of the MinedMap tile renderer,
|
||||
see the [v1.19.1](https://github.com/neocturne/MinedMap/tree/v1.19.1) tag.
|
||||
|
||||
|
|
17
crates/default-alloc/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "minedmap-default-alloc"
|
||||
version = "0.1.0"
|
||||
description = "Helper crate for target-specific selection of global allocator default"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
readme.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tikv-jemallocator = { version = "0.6.0", optional = true }
|
||||
|
||||
[target.'cfg(target_env = "musl")'.dependencies]
|
||||
tikv-jemallocator = "0.6.0"
|
||||
|
||||
[features]
|
||||
jemalloc = ["dep:tikv-jemallocator"]
|
3
crates/default-alloc/src/lib.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
#[cfg(any(target_env = "musl", feature = "jemalloc"))]
|
||||
#[global_allocator]
|
||||
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "minedmap-nbt"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
description = "MinedMap's handling of Minecraft NBT data and region files"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
@ -11,12 +11,10 @@ repository.workspace = true
|
|||
anyhow = "1.0.75"
|
||||
bytemuck = "1.13.1"
|
||||
fastnbt = "2.4.4"
|
||||
flate2 = "1.0.27"
|
||||
minedmap-types = { version = "0.1.2", path = "../types" }
|
||||
flate2 = "1.1.0"
|
||||
minedmap-types = { version = "0.2.0", path = "../types" }
|
||||
serde = "1.0.183"
|
||||
|
||||
[features]
|
||||
zlib-ng = ["flate2/zlib-ng"]
|
||||
|
||||
[dev-dependencies]
|
||||
clap = { version = "4.3.23", features = ["derive"] }
|
||||
flate2 = { version = "1.1.0", features = ["zlib-rs"] }
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{prelude::*, SeekFrom},
|
||||
io::{SeekFrom, prelude::*},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use flate2::read::ZlibDecoder;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "minedmap-resource"
|
||||
version = "0.3.0"
|
||||
version = "0.7.0"
|
||||
description = "Data describing Minecraft biomes and block types"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
@ -8,6 +8,6 @@ readme.workspace = true
|
|||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
enumflags2 = { version = "0.7.7", features = ["serde"] }
|
||||
glam = "0.25.0"
|
||||
serde = { version = "1.0.183", features = ["derive"] }
|
||||
bincode = "2.0.1"
|
||||
enumflags2 = "0.7.7"
|
||||
glam = "0.30.0"
|
||||
|
|
|
@ -1,437 +1,117 @@
|
|||
//! Biome data structures
|
||||
//! Biome data
|
||||
//!
|
||||
//! This file is generated using resource/biomes.py, do not edit
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::*;
|
||||
use BiomeGrassColorModifier::*;
|
||||
|
||||
use super::Color;
|
||||
|
||||
/// Grass color modifier used by a biome
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum BiomeGrassColorModifier {
|
||||
/// Grass color modifier used by the dark forest biome
|
||||
DarkForest,
|
||||
/// Grass color modifier used by swamp biomes
|
||||
Swamp,
|
||||
}
|
||||
|
||||
/// A biome specification
|
||||
///
|
||||
/// A Biome contains all information about a biome necessary to compute a block
|
||||
/// color given a block type and depth
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct Biome {
|
||||
/// Temperature value
|
||||
///
|
||||
/// For more efficient storage, the temperature is stored as an integer
|
||||
/// after mutiplying the raw value by 20
|
||||
pub temp: i8,
|
||||
/// Downfall value
|
||||
///
|
||||
/// For more efficient storage, the downfall is stored as an integer
|
||||
/// after mutiplying the raw value by 20
|
||||
pub downfall: i8,
|
||||
/// Water color override
|
||||
pub water_color: Option<Color>,
|
||||
/// Foliage color override
|
||||
pub foliage_color: Option<Color>,
|
||||
/// Grass color override
|
||||
pub grass_color: Option<Color>,
|
||||
/// Grass color modifier
|
||||
pub grass_color_modifier: Option<BiomeGrassColorModifier>,
|
||||
}
|
||||
|
||||
impl Biome {
|
||||
/// Constructs a new Biome
|
||||
const fn new(temp: i16, downfall: i16) -> Biome {
|
||||
/// Helper to encode temperature and downfall values
|
||||
///
|
||||
/// Converts temperatue and downfall from the input format
|
||||
/// (mutiplied by 100) to i8 range for more efficient storage.
|
||||
const fn encode(v: i16) -> i8 {
|
||||
(v / 5) as i8
|
||||
}
|
||||
Biome {
|
||||
temp: encode(temp),
|
||||
downfall: encode(downfall),
|
||||
grass_color_modifier: None,
|
||||
water_color: None,
|
||||
foliage_color: None,
|
||||
grass_color: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to override the biome water color
|
||||
const fn water(self, water_color: [u8; 3]) -> Biome {
|
||||
Biome {
|
||||
water_color: Some(Color(water_color)),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to override the biome foliage color
|
||||
const fn foliage(self, foliage_color: [u8; 3]) -> Biome {
|
||||
Biome {
|
||||
foliage_color: Some(Color(foliage_color)),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to override the biome grass color
|
||||
const fn grass(self, grass_color: [u8; 3]) -> Biome {
|
||||
Biome {
|
||||
grass_color: Some(Color(grass_color)),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to set a grass color modifier
|
||||
const fn modify(self, grass_color_modifier: BiomeGrassColorModifier) -> Biome {
|
||||
Biome {
|
||||
grass_color_modifier: Some(grass_color_modifier),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Decodes a temperature or downfall value from the storage format to
|
||||
/// f32 for further calculation
|
||||
fn decode(val: i8) -> f32 {
|
||||
f32::from(val) / 20.0
|
||||
}
|
||||
|
||||
/// Returns the biome's temperature decoded to its original float value
|
||||
pub fn temp(&self) -> f32 {
|
||||
Self::decode(self.temp)
|
||||
}
|
||||
|
||||
/// Returns the biome's downfall decoded to its original float value
|
||||
pub fn downfall(&self) -> f32 {
|
||||
Self::decode(self.downfall)
|
||||
}
|
||||
}
|
||||
|
||||
/// Standard biome specifications
|
||||
pub const BIOMES: &[(&str, Biome)] = {
|
||||
use BiomeGrassColorModifier::*;
|
||||
|
||||
// Data extracted from Minecraft code decompiled using https://github.com/Hexeption/MCP-Reborn
|
||||
|
||||
// We can't use floats in const functions, to temperature and downfall values
|
||||
// are specified multipled by 100. The underscore is used in place of the decimal point
|
||||
// of the original values.
|
||||
|
||||
#[allow(clippy::zero_prefixed_literal)]
|
||||
&[
|
||||
// Overworld
|
||||
(
|
||||
"badlands",
|
||||
Biome::new(2_00, 0_00)
|
||||
.foliage([158, 129, 77])
|
||||
.grass([144, 129, 77]),
|
||||
),
|
||||
("bamboo_jungle", Biome::new(0_95, 0_90)),
|
||||
("beach", Biome::new(0_80, 0_40)),
|
||||
("birch_forest", Biome::new(0_60, 0_60)),
|
||||
(
|
||||
"cherry_grove",
|
||||
Biome::new(0_50, 0_80)
|
||||
.water([93, 183, 239])
|
||||
.grass([182, 219, 97])
|
||||
.foliage([182, 219, 97]),
|
||||
),
|
||||
("cold_ocean", Biome::new(0_50, 0_50).water([61, 87, 214])),
|
||||
("dark_forest", Biome::new(0_70, 0_80).modify(DarkForest)),
|
||||
(
|
||||
"deep_cold_ocean",
|
||||
Biome::new(0_50, 0_50).water([61, 87, 214]),
|
||||
),
|
||||
("deep_dark", Biome::new(0_80, 0_40)),
|
||||
(
|
||||
"deep_frozen_ocean",
|
||||
Biome::new(0_50, 0_50).water([57, 56, 201]),
|
||||
),
|
||||
(
|
||||
"deep_lukewarm_ocean",
|
||||
Biome::new(0_50, 0_50).water([69, 173, 242]),
|
||||
),
|
||||
("deep_ocean", Biome::new(0_50, 0_50)),
|
||||
("desert", Biome::new(2_00, 0_00)),
|
||||
("dripstone_caves", Biome::new(0_80, 0_40)),
|
||||
(
|
||||
"eroded_badlands",
|
||||
Biome::new(2_00, 0_00)
|
||||
.foliage([158, 129, 77])
|
||||
.grass([144, 129, 77]),
|
||||
),
|
||||
("flower_forest", Biome::new(0_70, 0_80)),
|
||||
("forest", Biome::new(0_70, 0_80)),
|
||||
("frozen_ocean", Biome::new(0_00, 0_50).water([57, 56, 201])),
|
||||
("frozen_peaks", Biome::new(-0_70, 0_90)),
|
||||
("frozen_river", Biome::new(0_00, 0_50).water([57, 56, 201])),
|
||||
("grove", Biome::new(-0_20, 0_80)),
|
||||
("ice_spikes", Biome::new(0_00, 0_50)),
|
||||
("jagged_peaks", Biome::new(-0_70, 0_90)),
|
||||
("jungle", Biome::new(0_95, 0_90)),
|
||||
(
|
||||
"lukewarm_ocean",
|
||||
Biome::new(0_50, 0_50).water([69, 173, 242]),
|
||||
),
|
||||
("lush_caves", Biome::new(0_50, 0_50)),
|
||||
(
|
||||
"mangrove_swamp",
|
||||
Biome::new(0_80, 0_90)
|
||||
.water([58, 122, 106])
|
||||
.foliage([141, 177, 39])
|
||||
.modify(Swamp),
|
||||
),
|
||||
("meadow", Biome::new(0_50, 0_80).water([14, 78, 207])),
|
||||
("mushroom_fields", Biome::new(0_90, 1_00)),
|
||||
("ocean", Biome::new(0_50, 0_50)),
|
||||
("old_growth_birch_forest", Biome::new(0_60, 0_60)),
|
||||
("old_growth_pine_taiga", Biome::new(0_30, 0_80)),
|
||||
("old_growth_spruce_taiga", Biome::new(0_25, 0_80)),
|
||||
("plains", Biome::new(0_80, 0_40)),
|
||||
("river", Biome::new(0_50, 0_50)),
|
||||
("savanna", Biome::new(2_00, 0_00)),
|
||||
("savanna_plateau", Biome::new(2_00, 0_00)),
|
||||
("snowy_beach", Biome::new(0_05, 0_30).water([61, 87, 214])),
|
||||
("snowy_plains", Biome::new(0_00, 0_50)),
|
||||
("snowy_slopes", Biome::new(-0_30, 0_90)),
|
||||
("snowy_taiga", Biome::new(-0_50, 0_40).water([61, 87, 214])),
|
||||
("sparse_jungle", Biome::new(0_95, 0_80)),
|
||||
("stony_peaks", Biome::new(1_00, 0_30)),
|
||||
("stony_shore", Biome::new(0_20, 0_30)),
|
||||
("sunflower_plains", Biome::new(0_80, 0_40)),
|
||||
(
|
||||
"swamp",
|
||||
Biome::new(0_80, 0_90)
|
||||
.water([97, 123, 100])
|
||||
.foliage([106, 112, 57])
|
||||
.modify(Swamp),
|
||||
),
|
||||
("taiga", Biome::new(0_25, 0_80)),
|
||||
("the_void", Biome::new(0_50, 0_50)),
|
||||
("warm_ocean", Biome::new(0_50, 0_50).water([67, 213, 238])),
|
||||
("windswept_forest", Biome::new(0_20, 0_30)),
|
||||
("windswept_gravelly_hills", Biome::new(0_20, 0_30)),
|
||||
("windswept_hills", Biome::new(0_20, 0_30)),
|
||||
("windswept_savanna", Biome::new(2_00, 0_00)),
|
||||
(
|
||||
"wooded_badlands",
|
||||
Biome::new(2_00, 0_00)
|
||||
.foliage([158, 129, 77])
|
||||
.grass([144, 129, 77]),
|
||||
),
|
||||
// Nether
|
||||
("basalt_deltas", Biome::new(2_00, 0_00)),
|
||||
("crimson_forest", Biome::new(2_00, 0_00)),
|
||||
("nether_wastes", Biome::new(2_00, 0_00)),
|
||||
("soul_sand_valley", Biome::new(2_00, 0_00)),
|
||||
("warped_forest", Biome::new(2_00, 0_00)),
|
||||
// End
|
||||
("end_barrens", Biome::new(0_50, 0_50)),
|
||||
("end_highlands", Biome::new(0_50, 0_50)),
|
||||
("end_midlands", Biome::new(0_50, 0_50)),
|
||||
("small_end_islands", Biome::new(0_50, 0_50)),
|
||||
("the_end", Biome::new(0_50, 0_50)),
|
||||
]
|
||||
};
|
||||
|
||||
/// Biome ID aliases
|
||||
///
|
||||
/// Some biomes have been renamed or merged in recent Minecraft versions.
|
||||
/// Maintain a list of aliases to support chunks saved by older versions.
|
||||
pub const BIOME_ALIASES: &[(&str, &str)] = &[
|
||||
// Biomes fix
|
||||
("beaches", "beach"),
|
||||
("cold_beach", "snowy_beach"),
|
||||
("cold_deep_ocean", "deep_cold_ocean"),
|
||||
("extreme_hills", "mountains"),
|
||||
("extreme_hills_with_trees", "wooded_mountains"),
|
||||
("forest_hills", "wooded_hills"),
|
||||
("frozen_deep_ocean", "deep_frozen_ocean"),
|
||||
("hell", "nether_wastes"),
|
||||
("ice_flats", "snowy_tundra"),
|
||||
("ice_mountains", "snowy_mountains"),
|
||||
("lukewarm_deep_ocean", "deep_lukewarm_ocean"),
|
||||
("mesa", "badlands"),
|
||||
("mesa_clear_rock", "badlands_plateau"),
|
||||
("mesa_rock", "wooded_badlands_plateau"),
|
||||
("mushroom_island", "mushroom_fields"),
|
||||
("mushroom_island_shore", "mushroom_field_shore"),
|
||||
("mutated_birch_forest", "tall_birch_forest"),
|
||||
("mutated_birch_forest_hills", "tall_birch_hills"),
|
||||
("mutated_desert", "desert_lakes"),
|
||||
("mutated_extreme_hills", "gravelly_mountains"),
|
||||
/// List if known biomes and their properties
|
||||
pub const BIOMES: &[(&str, Biome)] = &[
|
||||
(
|
||||
"mutated_extreme_hills_with_trees",
|
||||
"modified_gravelly_mountains",
|
||||
"badlands",
|
||||
Biome::new(200, 0)
|
||||
.foliage([158, 129, 77])
|
||||
.grass([144, 129, 77]),
|
||||
),
|
||||
("bamboo_jungle", Biome::new(95, 90)),
|
||||
("basalt_deltas", Biome::new(200, 0)),
|
||||
("beach", Biome::new(80, 40)),
|
||||
("birch_forest", Biome::new(60, 60)),
|
||||
(
|
||||
"cherry_grove",
|
||||
Biome::new(50, 80)
|
||||
.foliage([182, 219, 97])
|
||||
.grass([182, 219, 97])
|
||||
.water([93, 183, 239]),
|
||||
),
|
||||
("cold_ocean", Biome::new(50, 50).water([61, 87, 214])),
|
||||
("crimson_forest", Biome::new(200, 0)),
|
||||
("dark_forest", Biome::new(70, 80).modify(DarkForest)),
|
||||
("deep_cold_ocean", Biome::new(50, 50).water([61, 87, 214])),
|
||||
("deep_dark", Biome::new(80, 40)),
|
||||
("deep_frozen_ocean", Biome::new(50, 50).water([57, 56, 201])),
|
||||
(
|
||||
"deep_lukewarm_ocean",
|
||||
Biome::new(50, 50).water([69, 173, 242]),
|
||||
),
|
||||
("deep_ocean", Biome::new(50, 50)),
|
||||
("desert", Biome::new(200, 0)),
|
||||
("dripstone_caves", Biome::new(80, 40)),
|
||||
("end_barrens", Biome::new(50, 50)),
|
||||
("end_highlands", Biome::new(50, 50)),
|
||||
("end_midlands", Biome::new(50, 50)),
|
||||
(
|
||||
"eroded_badlands",
|
||||
Biome::new(200, 0)
|
||||
.foliage([158, 129, 77])
|
||||
.grass([144, 129, 77]),
|
||||
),
|
||||
("flower_forest", Biome::new(70, 80)),
|
||||
("forest", Biome::new(70, 80)),
|
||||
("frozen_ocean", Biome::new(0, 50).water([57, 56, 201])),
|
||||
("frozen_peaks", Biome::new(-70, 90)),
|
||||
("frozen_river", Biome::new(0, 50).water([57, 56, 201])),
|
||||
("grove", Biome::new(-20, 80)),
|
||||
("ice_spikes", Biome::new(0, 50)),
|
||||
("jagged_peaks", Biome::new(-70, 90)),
|
||||
("jungle", Biome::new(95, 90)),
|
||||
("lukewarm_ocean", Biome::new(50, 50).water([69, 173, 242])),
|
||||
("lush_caves", Biome::new(50, 50)),
|
||||
(
|
||||
"mangrove_swamp",
|
||||
Biome::new(80, 90)
|
||||
.foliage([141, 177, 39])
|
||||
.modify(Swamp)
|
||||
.water([58, 122, 106]),
|
||||
),
|
||||
("meadow", Biome::new(50, 80).water([14, 78, 207])),
|
||||
("mushroom_fields", Biome::new(90, 100)),
|
||||
("nether_wastes", Biome::new(200, 0)),
|
||||
("ocean", Biome::new(50, 50)),
|
||||
("old_growth_birch_forest", Biome::new(60, 60)),
|
||||
("old_growth_pine_taiga", Biome::new(30, 80)),
|
||||
("old_growth_spruce_taiga", Biome::new(25, 80)),
|
||||
(
|
||||
"pale_garden",
|
||||
Biome::new(70, 80)
|
||||
.foliage([135, 141, 118])
|
||||
.grass([119, 130, 114])
|
||||
.water([118, 136, 157]),
|
||||
),
|
||||
("plains", Biome::new(80, 40)),
|
||||
("river", Biome::new(50, 50)),
|
||||
("savanna", Biome::new(200, 0)),
|
||||
("savanna_plateau", Biome::new(200, 0)),
|
||||
("small_end_islands", Biome::new(50, 50)),
|
||||
("snowy_beach", Biome::new(5, 30).water([61, 87, 214])),
|
||||
("snowy_plains", Biome::new(0, 50)),
|
||||
("snowy_slopes", Biome::new(-30, 90)),
|
||||
("snowy_taiga", Biome::new(-50, 40).water([61, 87, 214])),
|
||||
("soul_sand_valley", Biome::new(200, 0)),
|
||||
("sparse_jungle", Biome::new(95, 80)),
|
||||
("stony_peaks", Biome::new(100, 30)),
|
||||
("stony_shore", Biome::new(20, 30)),
|
||||
("sunflower_plains", Biome::new(80, 40)),
|
||||
(
|
||||
"swamp",
|
||||
Biome::new(80, 90)
|
||||
.foliage([106, 112, 57])
|
||||
.modify(Swamp)
|
||||
.water([97, 123, 100]),
|
||||
),
|
||||
("taiga", Biome::new(25, 80)),
|
||||
("the_end", Biome::new(50, 50)),
|
||||
("the_void", Biome::new(50, 50)),
|
||||
("warm_ocean", Biome::new(50, 50).water([67, 213, 238])),
|
||||
("warped_forest", Biome::new(200, 0)),
|
||||
("windswept_forest", Biome::new(20, 30)),
|
||||
("windswept_gravelly_hills", Biome::new(20, 30)),
|
||||
("windswept_hills", Biome::new(20, 30)),
|
||||
("windswept_savanna", Biome::new(200, 0)),
|
||||
(
|
||||
"wooded_badlands",
|
||||
Biome::new(200, 0)
|
||||
.foliage([158, 129, 77])
|
||||
.grass([144, 129, 77]),
|
||||
),
|
||||
("mutated_forest", "flower_forest"),
|
||||
("mutated_ice_flats", "ice_spikes"),
|
||||
("mutated_jungle", "modified_jungle"),
|
||||
("mutated_jungle_edge", "modified_jungle_edge"),
|
||||
("mutated_mesa", "eroded_badlands"),
|
||||
("mutated_mesa_clear_rock", "modified_badlands_plateau"),
|
||||
("mutated_mesa_rock", "modified_wooded_badlands_plateau"),
|
||||
("mutated_plains", "sunflower_plains"),
|
||||
("mutated_redwood_taiga", "giant_spruce_taiga"),
|
||||
("mutated_redwood_taiga_hills", "giant_spruce_taiga_hills"),
|
||||
("mutated_roofed_forest", "dark_forest_hills"),
|
||||
("mutated_savanna", "shattered_savanna"),
|
||||
("mutated_savanna_rock", "shattered_savanna_plateau"),
|
||||
("mutated_swampland", "swamp_hills"),
|
||||
("mutated_taiga", "taiga_mountains"),
|
||||
("mutated_taiga_cold", "snowy_taiga_mountains"),
|
||||
("redwood_taiga", "giant_tree_taiga"),
|
||||
("redwood_taiga_hills", "giant_tree_taiga_hills"),
|
||||
("roofed_forest", "dark_forest"),
|
||||
("savanna_rock", "savanna_plateau"),
|
||||
("sky", "the_end"),
|
||||
("sky_island_barren", "end_barrens"),
|
||||
("sky_island_high", "end_highlands"),
|
||||
("sky_island_low", "small_end_islands"),
|
||||
("sky_island_medium", "end_midlands"),
|
||||
("smaller_extreme_hills", "mountain_edge"),
|
||||
("stone_beach", "stone_shore"),
|
||||
("swampland", "swamp"),
|
||||
("taiga_cold", "snowy_taiga"),
|
||||
("taiga_cold_hills", "snowy_taiga_hills"),
|
||||
("void", "the_void"),
|
||||
("warm_deep_ocean", "deep_warm_ocean"),
|
||||
// Nether biome rename
|
||||
("nether", "nether_wastes"),
|
||||
// Caves and Cliffs biome renames
|
||||
("badlands_plateau", "badlands"),
|
||||
("bamboo_jungle_hills", "bamboo_jungle"),
|
||||
("birch_forest_hills", "birch_forest"),
|
||||
("dark_forest_hills", "dark_forest"),
|
||||
("desert_hills", "desert"),
|
||||
("desert_lakes", "desert"),
|
||||
("giant_spruce_taiga", "old_growth_spruce_taiga"),
|
||||
("giant_spruce_taiga_hills", "old_growth_spruce_taiga"),
|
||||
("giant_tree_taiga", "old_growth_pine_taiga"),
|
||||
("giant_tree_taiga_hills", "old_growth_pine_taiga"),
|
||||
("gravelly_mountains", "windswept_gravelly_hills"),
|
||||
("jungle_edge", "sparse_jungle"),
|
||||
("jungle_hills", "jungle"),
|
||||
("lofty_peaks", "jagged_peaks"),
|
||||
("modified_badlands_plateau", "badlands"),
|
||||
("modified_gravelly_mountains", "windswept_gravelly_hills"),
|
||||
("modified_jungle", "jungle"),
|
||||
("modified_jungle_edge", "sparse_jungle"),
|
||||
("modified_wooded_badlands_plateau", "wooded_badlands"),
|
||||
("mountain_edge", "windswept_hills"),
|
||||
("mountains", "windswept_hills"),
|
||||
("mushroom_field_shore", "mushroom_fields"),
|
||||
("shattered_savanna", "windswept_savanna"),
|
||||
("shattered_savanna_plateau", "windswept_savanna"),
|
||||
("snowcapped_peaks", "frozen_peaks"),
|
||||
("snowy_mountains", "snowy_plains"),
|
||||
("snowy_taiga_hills", "snowy_taiga"),
|
||||
("snowy_taiga_mountains", "snowy_taiga"),
|
||||
("snowy_tundra", "snowy_plains"),
|
||||
("stone_shore", "stony_shore"),
|
||||
("swamp_hills", "swamp"),
|
||||
("taiga_hills", "taiga"),
|
||||
("taiga_mountains", "taiga"),
|
||||
("tall_birch_forest", "old_growth_birch_forest"),
|
||||
("tall_birch_hills", "old_growth_birch_forest"),
|
||||
("wooded_badlands_plateau", "wooded_badlands"),
|
||||
("wooded_hills", "forest"),
|
||||
("wooded_mountains", "windswept_forest"),
|
||||
// Remove Deep Warm Ocean
|
||||
("deep_warm_ocean", "warm_ocean"),
|
||||
];
|
||||
|
||||
/// Maps old numeric biome IDs to new string IDs
|
||||
pub fn legacy_biome(index: u8) -> &'static str {
|
||||
match index {
|
||||
0 => "ocean",
|
||||
1 => "plains",
|
||||
2 => "desert",
|
||||
3 => "mountains",
|
||||
4 => "forest",
|
||||
5 => "taiga",
|
||||
6 => "swamp",
|
||||
7 => "river",
|
||||
8 => "nether_wastes",
|
||||
9 => "the_end",
|
||||
10 => "frozen_ocean",
|
||||
11 => "frozen_river",
|
||||
12 => "snowy_tundra",
|
||||
13 => "snowy_mountains",
|
||||
14 => "mushroom_fields",
|
||||
15 => "mushroom_field_shore",
|
||||
16 => "beach",
|
||||
17 => "desert_hills",
|
||||
18 => "wooded_hills",
|
||||
19 => "taiga_hills",
|
||||
20 => "mountain_edge",
|
||||
21 => "jungle",
|
||||
22 => "jungle_hills",
|
||||
23 => "jungle_edge",
|
||||
24 => "deep_ocean",
|
||||
25 => "stone_shore",
|
||||
26 => "snowy_beach",
|
||||
27 => "birch_forest",
|
||||
28 => "birch_forest_hills",
|
||||
29 => "dark_forest",
|
||||
30 => "snowy_taiga",
|
||||
31 => "snowy_taiga_hills",
|
||||
32 => "giant_tree_taiga",
|
||||
33 => "giant_tree_taiga_hills",
|
||||
34 => "wooded_mountains",
|
||||
35 => "savanna",
|
||||
36 => "savanna_plateau",
|
||||
37 => "badlands",
|
||||
38 => "wooded_badlands_plateau",
|
||||
39 => "badlands_plateau",
|
||||
40 => "small_end_islands",
|
||||
41 => "end_midlands",
|
||||
42 => "end_highlands",
|
||||
43 => "end_barrens",
|
||||
44 => "warm_ocean",
|
||||
45 => "lukewarm_ocean",
|
||||
46 => "cold_ocean",
|
||||
47 => "deep_warm_ocean",
|
||||
48 => "deep_lukewarm_ocean",
|
||||
49 => "deep_cold_ocean",
|
||||
50 => "deep_frozen_ocean",
|
||||
127 => "the_void",
|
||||
129 => "sunflower_plains",
|
||||
130 => "desert_lakes",
|
||||
131 => "gravelly_mountains",
|
||||
132 => "flower_forest",
|
||||
133 => "taiga_mountains",
|
||||
134 => "swamp_hills",
|
||||
140 => "ice_spikes",
|
||||
149 => "modified_jungle",
|
||||
151 => "modified_jungle_edge",
|
||||
155 => "tall_birch_forest",
|
||||
156 => "tall_birch_hills",
|
||||
157 => "dark_forest_hills",
|
||||
158 => "snowy_taiga_mountains",
|
||||
160 => "giant_spruce_taiga",
|
||||
161 => "giant_spruce_taiga_hills",
|
||||
162 => "modified_gravelly_mountains",
|
||||
163 => "shattered_savanna",
|
||||
164 => "shattered_savanna_plateau",
|
||||
165 => "eroded_badlands",
|
||||
166 => "modified_wooded_badlands_plateau",
|
||||
167 => "modified_badlands_plateau",
|
||||
168 => "bamboo_jungle",
|
||||
169 => "bamboo_jungle_hills",
|
||||
170 => "soul_sand_valley",
|
||||
171 => "crimson_forest",
|
||||
172 => "warped_forest",
|
||||
173 => "basalt_deltas",
|
||||
174 => "dripstone_caves",
|
||||
175 => "lush_caves",
|
||||
177 => "meadow",
|
||||
178 => "grove",
|
||||
179 => "snowy_slopes",
|
||||
180 => "snowcapped_peaks",
|
||||
181 => "lofty_peaks",
|
||||
182 => "stony_peaks",
|
||||
_ => "ocean",
|
||||
}
|
||||
}
|
||||
|
|
202
crates/resource/src/legacy_biomes.rs
Normal file
|
@ -0,0 +1,202 @@
|
|||
//! Manually maintained biome data (aliases and legacy biome IDs)
|
||||
|
||||
/// Biome ID aliases
|
||||
///
|
||||
/// Some biomes have been renamed or merged in recent Minecraft versions.
|
||||
/// Maintain a list of aliases to support chunks saved by older versions.
|
||||
pub const BIOME_ALIASES: &[(&str, &str)] = &[
|
||||
// Biomes fix
|
||||
("beaches", "beach"),
|
||||
("cold_beach", "snowy_beach"),
|
||||
("cold_deep_ocean", "deep_cold_ocean"),
|
||||
("extreme_hills", "mountains"),
|
||||
("extreme_hills_with_trees", "wooded_mountains"),
|
||||
("forest_hills", "wooded_hills"),
|
||||
("frozen_deep_ocean", "deep_frozen_ocean"),
|
||||
("hell", "nether_wastes"),
|
||||
("ice_flats", "snowy_tundra"),
|
||||
("ice_mountains", "snowy_mountains"),
|
||||
("lukewarm_deep_ocean", "deep_lukewarm_ocean"),
|
||||
("mesa", "badlands"),
|
||||
("mesa_clear_rock", "badlands_plateau"),
|
||||
("mesa_rock", "wooded_badlands_plateau"),
|
||||
("mushroom_island", "mushroom_fields"),
|
||||
("mushroom_island_shore", "mushroom_field_shore"),
|
||||
("mutated_birch_forest", "tall_birch_forest"),
|
||||
("mutated_birch_forest_hills", "tall_birch_hills"),
|
||||
("mutated_desert", "desert_lakes"),
|
||||
("mutated_extreme_hills", "gravelly_mountains"),
|
||||
(
|
||||
"mutated_extreme_hills_with_trees",
|
||||
"modified_gravelly_mountains",
|
||||
),
|
||||
("mutated_forest", "flower_forest"),
|
||||
("mutated_ice_flats", "ice_spikes"),
|
||||
("mutated_jungle", "modified_jungle"),
|
||||
("mutated_jungle_edge", "modified_jungle_edge"),
|
||||
("mutated_mesa", "eroded_badlands"),
|
||||
("mutated_mesa_clear_rock", "modified_badlands_plateau"),
|
||||
("mutated_mesa_rock", "modified_wooded_badlands_plateau"),
|
||||
("mutated_plains", "sunflower_plains"),
|
||||
("mutated_redwood_taiga", "giant_spruce_taiga"),
|
||||
("mutated_redwood_taiga_hills", "giant_spruce_taiga_hills"),
|
||||
("mutated_roofed_forest", "dark_forest_hills"),
|
||||
("mutated_savanna", "shattered_savanna"),
|
||||
("mutated_savanna_rock", "shattered_savanna_plateau"),
|
||||
("mutated_swampland", "swamp_hills"),
|
||||
("mutated_taiga", "taiga_mountains"),
|
||||
("mutated_taiga_cold", "snowy_taiga_mountains"),
|
||||
("redwood_taiga", "giant_tree_taiga"),
|
||||
("redwood_taiga_hills", "giant_tree_taiga_hills"),
|
||||
("roofed_forest", "dark_forest"),
|
||||
("savanna_rock", "savanna_plateau"),
|
||||
("sky", "the_end"),
|
||||
("sky_island_barren", "end_barrens"),
|
||||
("sky_island_high", "end_highlands"),
|
||||
("sky_island_low", "small_end_islands"),
|
||||
("sky_island_medium", "end_midlands"),
|
||||
("smaller_extreme_hills", "mountain_edge"),
|
||||
("stone_beach", "stone_shore"),
|
||||
("swampland", "swamp"),
|
||||
("taiga_cold", "snowy_taiga"),
|
||||
("taiga_cold_hills", "snowy_taiga_hills"),
|
||||
("void", "the_void"),
|
||||
("warm_deep_ocean", "deep_warm_ocean"),
|
||||
// Nether biome rename
|
||||
("nether", "nether_wastes"),
|
||||
// Caves and Cliffs biome renames
|
||||
("badlands_plateau", "badlands"),
|
||||
("bamboo_jungle_hills", "bamboo_jungle"),
|
||||
("birch_forest_hills", "birch_forest"),
|
||||
("dark_forest_hills", "dark_forest"),
|
||||
("desert_hills", "desert"),
|
||||
("desert_lakes", "desert"),
|
||||
("giant_spruce_taiga", "old_growth_spruce_taiga"),
|
||||
("giant_spruce_taiga_hills", "old_growth_spruce_taiga"),
|
||||
("giant_tree_taiga", "old_growth_pine_taiga"),
|
||||
("giant_tree_taiga_hills", "old_growth_pine_taiga"),
|
||||
("gravelly_mountains", "windswept_gravelly_hills"),
|
||||
("jungle_edge", "sparse_jungle"),
|
||||
("jungle_hills", "jungle"),
|
||||
("lofty_peaks", "jagged_peaks"),
|
||||
("modified_badlands_plateau", "badlands"),
|
||||
("modified_gravelly_mountains", "windswept_gravelly_hills"),
|
||||
("modified_jungle", "jungle"),
|
||||
("modified_jungle_edge", "sparse_jungle"),
|
||||
("modified_wooded_badlands_plateau", "wooded_badlands"),
|
||||
("mountain_edge", "windswept_hills"),
|
||||
("mountains", "windswept_hills"),
|
||||
("mushroom_field_shore", "mushroom_fields"),
|
||||
("shattered_savanna", "windswept_savanna"),
|
||||
("shattered_savanna_plateau", "windswept_savanna"),
|
||||
("snowcapped_peaks", "frozen_peaks"),
|
||||
("snowy_mountains", "snowy_plains"),
|
||||
("snowy_taiga_hills", "snowy_taiga"),
|
||||
("snowy_taiga_mountains", "snowy_taiga"),
|
||||
("snowy_tundra", "snowy_plains"),
|
||||
("stone_shore", "stony_shore"),
|
||||
("swamp_hills", "swamp"),
|
||||
("taiga_hills", "taiga"),
|
||||
("taiga_mountains", "taiga"),
|
||||
("tall_birch_forest", "old_growth_birch_forest"),
|
||||
("tall_birch_hills", "old_growth_birch_forest"),
|
||||
("wooded_badlands_plateau", "wooded_badlands"),
|
||||
("wooded_hills", "forest"),
|
||||
("wooded_mountains", "windswept_forest"),
|
||||
// Remove Deep Warm Ocean
|
||||
("deep_warm_ocean", "warm_ocean"),
|
||||
];
|
||||
|
||||
/// Maps old numeric biome IDs to new string IDs
|
||||
pub fn legacy_biome(index: u8) -> &'static str {
|
||||
match index {
|
||||
0 => "ocean",
|
||||
1 => "plains",
|
||||
2 => "desert",
|
||||
3 => "mountains",
|
||||
4 => "forest",
|
||||
5 => "taiga",
|
||||
6 => "swamp",
|
||||
7 => "river",
|
||||
8 => "nether_wastes",
|
||||
9 => "the_end",
|
||||
10 => "frozen_ocean",
|
||||
11 => "frozen_river",
|
||||
12 => "snowy_tundra",
|
||||
13 => "snowy_mountains",
|
||||
14 => "mushroom_fields",
|
||||
15 => "mushroom_field_shore",
|
||||
16 => "beach",
|
||||
17 => "desert_hills",
|
||||
18 => "wooded_hills",
|
||||
19 => "taiga_hills",
|
||||
20 => "mountain_edge",
|
||||
21 => "jungle",
|
||||
22 => "jungle_hills",
|
||||
23 => "jungle_edge",
|
||||
24 => "deep_ocean",
|
||||
25 => "stone_shore",
|
||||
26 => "snowy_beach",
|
||||
27 => "birch_forest",
|
||||
28 => "birch_forest_hills",
|
||||
29 => "dark_forest",
|
||||
30 => "snowy_taiga",
|
||||
31 => "snowy_taiga_hills",
|
||||
32 => "giant_tree_taiga",
|
||||
33 => "giant_tree_taiga_hills",
|
||||
34 => "wooded_mountains",
|
||||
35 => "savanna",
|
||||
36 => "savanna_plateau",
|
||||
37 => "badlands",
|
||||
38 => "wooded_badlands_plateau",
|
||||
39 => "badlands_plateau",
|
||||
40 => "small_end_islands",
|
||||
41 => "end_midlands",
|
||||
42 => "end_highlands",
|
||||
43 => "end_barrens",
|
||||
44 => "warm_ocean",
|
||||
45 => "lukewarm_ocean",
|
||||
46 => "cold_ocean",
|
||||
47 => "deep_warm_ocean",
|
||||
48 => "deep_lukewarm_ocean",
|
||||
49 => "deep_cold_ocean",
|
||||
50 => "deep_frozen_ocean",
|
||||
127 => "the_void",
|
||||
129 => "sunflower_plains",
|
||||
130 => "desert_lakes",
|
||||
131 => "gravelly_mountains",
|
||||
132 => "flower_forest",
|
||||
133 => "taiga_mountains",
|
||||
134 => "swamp_hills",
|
||||
140 => "ice_spikes",
|
||||
149 => "modified_jungle",
|
||||
151 => "modified_jungle_edge",
|
||||
155 => "tall_birch_forest",
|
||||
156 => "tall_birch_hills",
|
||||
157 => "dark_forest_hills",
|
||||
158 => "snowy_taiga_mountains",
|
||||
160 => "giant_spruce_taiga",
|
||||
161 => "giant_spruce_taiga_hills",
|
||||
162 => "modified_gravelly_mountains",
|
||||
163 => "shattered_savanna",
|
||||
164 => "shattered_savanna_plateau",
|
||||
165 => "eroded_badlands",
|
||||
166 => "modified_wooded_badlands_plateau",
|
||||
167 => "modified_badlands_plateau",
|
||||
168 => "bamboo_jungle",
|
||||
169 => "bamboo_jungle_hills",
|
||||
170 => "soul_sand_valley",
|
||||
171 => "crimson_forest",
|
||||
172 => "warped_forest",
|
||||
173 => "basalt_deltas",
|
||||
174 => "dripstone_caves",
|
||||
175 => "lush_caves",
|
||||
177 => "meadow",
|
||||
178 => "grove",
|
||||
179 => "snowy_slopes",
|
||||
180 => "snowcapped_peaks",
|
||||
181 => "lofty_peaks",
|
||||
182 => "stony_peaks",
|
||||
_ => "ocean",
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ const DEF: &str = "air";
|
|||
const EMPTY: [&str; 16] = simple(DEF);
|
||||
|
||||
/// Mapping from each numeric block type and damage/subtype ID to new string ID
|
||||
#[allow(clippy::large_const_arrays)]
|
||||
pub const LEGACY_BLOCK_TYPES: [[&str; 16]; 256] = [
|
||||
/* 0 */
|
||||
simple("air"),
|
||||
|
|
|
@ -4,20 +4,19 @@
|
|||
|
||||
mod biomes;
|
||||
mod block_color;
|
||||
mod legacy_block_types;
|
||||
|
||||
#[allow(clippy::missing_docs_in_private_items)] // Generated module
|
||||
mod block_types;
|
||||
mod legacy_biomes;
|
||||
mod legacy_block_types;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use enumflags2::{bitflags, BitFlags};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use bincode::{BorrowDecode, Decode, Encode};
|
||||
use enumflags2::{BitFlags, bitflags};
|
||||
|
||||
/// Flags describing special properties of [BlockType]s
|
||||
#[bitflags]
|
||||
#[repr(u8)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum BlockFlag {
|
||||
/// The block type is opaque
|
||||
Opaque,
|
||||
|
@ -39,14 +38,14 @@ pub enum BlockFlag {
|
|||
}
|
||||
|
||||
/// An RGB color with u8 components
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode)]
|
||||
pub struct Color(pub [u8; 3]);
|
||||
|
||||
/// An RGB color with f32 components
|
||||
pub type Colorf = glam::Vec3;
|
||||
|
||||
/// A block type specification
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct BlockColor {
|
||||
/// Bit set of [BlockFlag]s describing special properties of the block type
|
||||
pub flags: BitFlags<BlockFlag>,
|
||||
|
@ -62,6 +61,43 @@ impl BlockColor {
|
|||
}
|
||||
}
|
||||
|
||||
impl Encode for BlockColor {
|
||||
fn encode<E: bincode::enc::Encoder>(
|
||||
&self,
|
||||
encoder: &mut E,
|
||||
) -> Result<(), bincode::error::EncodeError> {
|
||||
bincode::Encode::encode(&self.flags.bits(), encoder)?;
|
||||
bincode::Encode::encode(&self.color, encoder)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Context> Decode<Context> for BlockColor {
|
||||
fn decode<D: bincode::de::Decoder<Context = Context>>(
|
||||
decoder: &mut D,
|
||||
) -> Result<Self, bincode::error::DecodeError> {
|
||||
Ok(BlockColor {
|
||||
flags: BitFlags::from_bits(bincode::Decode::decode(decoder)?).or(Err(
|
||||
bincode::error::DecodeError::Other("invalid block flags"),
|
||||
))?,
|
||||
color: bincode::Decode::decode(decoder)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, Context> BorrowDecode<'de, Context> for BlockColor {
|
||||
fn borrow_decode<D: bincode::de::BorrowDecoder<'de, Context = Context>>(
|
||||
decoder: &mut D,
|
||||
) -> Result<Self, bincode::error::DecodeError> {
|
||||
Ok(BlockColor {
|
||||
flags: BitFlags::from_bits(bincode::BorrowDecode::borrow_decode(decoder)?).or(Err(
|
||||
bincode::error::DecodeError::Other("invalid block flags"),
|
||||
))?,
|
||||
color: bincode::BorrowDecode::borrow_decode(decoder)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A block type specification (for use in constants)
|
||||
#[derive(Debug, Clone)]
|
||||
struct ConstBlockType {
|
||||
|
@ -135,9 +171,112 @@ impl BlockTypes {
|
|||
}
|
||||
}
|
||||
|
||||
pub use biomes::{Biome, BiomeGrassColorModifier};
|
||||
pub use block_color::{block_color, needs_biome};
|
||||
|
||||
/// Grass color modifier used by a biome
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)]
|
||||
pub enum BiomeGrassColorModifier {
|
||||
/// Grass color modifier used by the dark forest biome
|
||||
DarkForest,
|
||||
/// Grass color modifier used by swamp biomes
|
||||
Swamp,
|
||||
}
|
||||
|
||||
/// A biome specification
|
||||
///
|
||||
/// A Biome contains all information about a biome necessary to compute a block
|
||||
/// color given a block type and depth
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)]
|
||||
pub struct Biome {
|
||||
/// Temperature value
|
||||
///
|
||||
/// For more efficient storage, the temperature is stored as an integer
|
||||
/// after mutiplying the raw value by 20
|
||||
pub temp: i8,
|
||||
/// Downfall value
|
||||
///
|
||||
/// For more efficient storage, the downfall is stored as an integer
|
||||
/// after mutiplying the raw value by 20
|
||||
pub downfall: i8,
|
||||
/// Water color override
|
||||
pub water_color: Option<Color>,
|
||||
/// Foliage color override
|
||||
pub foliage_color: Option<Color>,
|
||||
/// Grass color override
|
||||
pub grass_color: Option<Color>,
|
||||
/// Grass color modifier
|
||||
pub grass_color_modifier: Option<BiomeGrassColorModifier>,
|
||||
}
|
||||
|
||||
impl Biome {
|
||||
/// Constructs a new Biome
|
||||
const fn new(temp: i16, downfall: i16) -> Biome {
|
||||
/// Helper to encode temperature and downfall values
|
||||
///
|
||||
/// Converts temperatue and downfall from the input format
|
||||
/// (mutiplied by 100) to i8 range for more efficient storage.
|
||||
const fn encode(v: i16) -> i8 {
|
||||
(v / 5) as i8
|
||||
}
|
||||
Biome {
|
||||
temp: encode(temp),
|
||||
downfall: encode(downfall),
|
||||
grass_color_modifier: None,
|
||||
water_color: None,
|
||||
foliage_color: None,
|
||||
grass_color: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to override the biome water color
|
||||
const fn water(self, water_color: [u8; 3]) -> Biome {
|
||||
Biome {
|
||||
water_color: Some(Color(water_color)),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to override the biome foliage color
|
||||
const fn foliage(self, foliage_color: [u8; 3]) -> Biome {
|
||||
Biome {
|
||||
foliage_color: Some(Color(foliage_color)),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to override the biome grass color
|
||||
const fn grass(self, grass_color: [u8; 3]) -> Biome {
|
||||
Biome {
|
||||
grass_color: Some(Color(grass_color)),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder function to set a grass color modifier
|
||||
const fn modify(self, grass_color_modifier: BiomeGrassColorModifier) -> Biome {
|
||||
Biome {
|
||||
grass_color_modifier: Some(grass_color_modifier),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Decodes a temperature or downfall value from the storage format to
|
||||
/// f32 for further calculation
|
||||
fn decode(val: i8) -> f32 {
|
||||
f32::from(val) / 20.0
|
||||
}
|
||||
|
||||
/// Returns the biome's temperature decoded to its original float value
|
||||
pub fn temp(&self) -> f32 {
|
||||
Self::decode(self.temp)
|
||||
}
|
||||
|
||||
/// Returns the biome's downfall decoded to its original float value
|
||||
pub fn downfall(&self) -> f32 {
|
||||
Self::decode(self.downfall)
|
||||
}
|
||||
}
|
||||
|
||||
/// Used to look up standard Minecraft biome types
|
||||
#[derive(Debug)]
|
||||
pub struct BiomeTypes {
|
||||
|
@ -145,6 +284,8 @@ pub struct BiomeTypes {
|
|||
biome_map: HashMap<String, &'static Biome>,
|
||||
/// Array used to look up old numeric biome IDs
|
||||
legacy_biomes: Box<[&'static Biome; 256]>,
|
||||
/// Fallback for unknown (new/modded) biomes
|
||||
fallback_biome: &'static Biome,
|
||||
}
|
||||
|
||||
impl Default for BiomeTypes {
|
||||
|
@ -154,7 +295,7 @@ impl Default for BiomeTypes {
|
|||
.map(|(k, v)| (String::from(*k), v))
|
||||
.collect();
|
||||
|
||||
for &(old, new) in biomes::BIOME_ALIASES.iter().rev() {
|
||||
for &(old, new) in legacy_biomes::BIOME_ALIASES.iter().rev() {
|
||||
let biome = biome_map
|
||||
.get(new)
|
||||
.copied()
|
||||
|
@ -164,16 +305,19 @@ impl Default for BiomeTypes {
|
|||
|
||||
let legacy_biomes = (0..=255)
|
||||
.map(|index| {
|
||||
let id = biomes::legacy_biome(index);
|
||||
let id = legacy_biomes::legacy_biome(index);
|
||||
*biome_map.get(id).expect("Unknown legacy biome")
|
||||
})
|
||||
.collect::<Box<[_]>>()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
let fallback_biome = *biome_map.get("plains").expect("Plains biome undefined");
|
||||
|
||||
Self {
|
||||
biome_map,
|
||||
legacy_biomes,
|
||||
fallback_biome,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,4 +335,10 @@ impl BiomeTypes {
|
|||
pub fn get_legacy(&self, id: u8) -> Option<&Biome> {
|
||||
Some(self.legacy_biomes[id as usize])
|
||||
}
|
||||
|
||||
/// Returns the fallback for unknown (new/modded) biomes
|
||||
#[inline]
|
||||
pub fn get_fallback(&self) -> &Biome {
|
||||
self.fallback_biome
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "minedmap-types"
|
||||
version = "0.1.2"
|
||||
version = "0.2.0"
|
||||
description = "Common types used by several MinedMap crates"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
@ -8,5 +8,5 @@ readme.workspace = true
|
|||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
itertools = "0.12.0"
|
||||
serde = { version = "1.0.183", features = ["derive"] }
|
||||
bincode = "2.0.1"
|
||||
itertools = "0.14.0"
|
||||
|
|
|
@ -8,8 +8,8 @@ use std::{
|
|||
ops::{Index, IndexMut},
|
||||
};
|
||||
|
||||
use bincode::{Decode, Encode};
|
||||
use itertools::iproduct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Const generic AXIS arguments for coordinate types
|
||||
pub mod axis {
|
||||
|
@ -48,10 +48,10 @@ macro_rules! coord_type {
|
|||
/// Returns an iterator over all possible values of the type
|
||||
#[inline]
|
||||
pub fn iter() -> impl DoubleEndedIterator<Item = $t<AXIS>>
|
||||
+ ExactSizeIterator
|
||||
+ FusedIterator
|
||||
+ Clone
|
||||
+ Debug {
|
||||
+ ExactSizeIterator
|
||||
+ FusedIterator
|
||||
+ Clone
|
||||
+ Debug {
|
||||
(0..Self::MAX as u8).map($t)
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ impl LayerBlockCoords {
|
|||
/// Generic array for data stored per block of a chunk layer
|
||||
///
|
||||
/// Includes various convenient iteration functions.
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Default, Encode, Decode)]
|
||||
pub struct LayerBlockArray<T>(pub [[T; BLOCKS_PER_CHUNK]; BLOCKS_PER_CHUNK]);
|
||||
|
||||
impl<T> Index<LayerBlockCoords> for LayerBlockArray<T> {
|
||||
|
@ -196,7 +196,7 @@ impl Debug for ChunkCoords {
|
|||
/// Generic array for data stored per chunk of a region
|
||||
///
|
||||
/// Includes various convenient iteration functions.
|
||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Default, Encode, Decode)]
|
||||
pub struct ChunkArray<T>(pub [[T; CHUNKS_PER_REGION]; CHUNKS_PER_REGION]);
|
||||
|
||||
impl<T> ChunkArray<T> {
|
||||
|
|
51
docker-compose.yml
Normal file
|
@ -0,0 +1,51 @@
|
|||
# This is an example docker-compose configuration providing a Minecraft server,
|
||||
# map generator and webserver. Visit http://localhost:8080 to view the map.
|
||||
#
|
||||
# See https://docker-minecraft-server.readthedocs.io/ for more information on
|
||||
# the itzg/minecraft-server image and its configuration.
|
||||
|
||||
services:
|
||||
mc:
|
||||
image: docker.io/itzg/minecraft-server
|
||||
environment:
|
||||
EULA: 'true'
|
||||
ports:
|
||||
- '25565:25565'
|
||||
volumes:
|
||||
- data:/data
|
||||
stdin_open: true
|
||||
tty: true
|
||||
restart: unless-stopped
|
||||
|
||||
minedmap:
|
||||
image: ghcr.io/neocturne/minedmap/minedmap
|
||||
command:
|
||||
- '--jobs-initial=2'
|
||||
- '--image-format=webp'
|
||||
- '--sign-filter=\[Map\]'
|
||||
- '--sign-transform=s/\[Map\]//'
|
||||
- '--watch'
|
||||
- '/input/world'
|
||||
- '/output'
|
||||
volumes:
|
||||
- data:/input:ro
|
||||
- output:/output
|
||||
- processed:/output/processed
|
||||
network_mode: 'none'
|
||||
depends_on:
|
||||
mc:
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
viewer:
|
||||
image: ghcr.io/neocturne/minedmap/viewer
|
||||
ports:
|
||||
- '8080:80'
|
||||
volumes:
|
||||
- output:/usr/share/nginx/html/data:ro
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
data: {}
|
||||
processed: {}
|
||||
output: {}
|
|
@ -11,13 +11,15 @@ work.
|
|||
- `extract.py`: Takes the block type information from `blocks.json` and texture data
|
||||
from an unpacked Minecraft JAR, storing the result in `colors.json`
|
||||
- `generate.py`: Generates `block_types.rs` from `colors.json`
|
||||
- `biomes.py`: Generates `biomes.rs` from biome JSON files of an unpacked
|
||||
Minecraft JAR
|
||||
- `sign_textures.py`: Generates all needed sign graphics from Minecraft assets
|
||||
|
||||
In addition to these scripts, the JSON processor *jq* is a useful tool to work
|
||||
with MinedMap's resource metadata.
|
||||
|
||||
|
||||
## How to add support for block IDs of a new Minecraft version
|
||||
## How to add support for block IDs and biomes of a new Minecraft version
|
||||
|
||||
1. Download the Minecraft version you want to support as well as the previous
|
||||
version currently supported by MinedMap. You can use the Minecraft launcher
|
||||
|
@ -69,6 +71,17 @@ with MinedMap's resource metadata.
|
|||
cargo fmt --all
|
||||
```
|
||||
|
||||
8. Update the source code for new biome data:
|
||||
|
||||
```sh
|
||||
./biomes.py data/new ../crates/resource/src/biomes.rs
|
||||
cargo fmt --all
|
||||
```
|
||||
|
||||
After regenerating, check if only new biomes were added. If entries
|
||||
got removed, biomes may have been renamed or merged, requiring updates
|
||||
to the alias list in `crates/resource/src/legacy_biomes.rs`.
|
||||
|
||||
After the update, the new version should be tested with old savegames (both
|
||||
before and after migration by the new version) as well as newly generated
|
||||
worlds. Use creative mode to add the new block types to your test world.
|
||||
|
|
70
resource/biomes.py
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
sys.exit('Usage: biomes.py <data directory> <biomes.rs>')
|
||||
|
||||
biomes = {}
|
||||
|
||||
for file in os.scandir(os.path.join(sys.argv[1], 'data/minecraft/worldgen/biome')):
|
||||
(name, ext) = os.path.splitext(file.name)
|
||||
if ext != '.json':
|
||||
continue
|
||||
with open(file) as f:
|
||||
data = json.load(f)
|
||||
biomes[name] = {
|
||||
'downfall': data['downfall'],
|
||||
'temperature': data['temperature'],
|
||||
'foliage_color': data['effects'].get('foliage_color'),
|
||||
'grass_color': data['effects'].get('grass_color'),
|
||||
'grass_color_modifier': data['effects'].get('grass_color_modifier'),
|
||||
'water_color': data['effects'].get('water_color'),
|
||||
}
|
||||
|
||||
def color(v):
|
||||
return f'[{v>>16}, {(v>>8)&0xff}, {v&0xff}]'
|
||||
|
||||
# Converts the snake_case grass color modifier to CamelCase
|
||||
def modify(v):
|
||||
return ''.join([s.capitalize() for s in v.split('_')])
|
||||
|
||||
def gen_biome(name, info, f):
|
||||
temp = round(100*info['temperature'])
|
||||
downfall = round(100*info['downfall'])
|
||||
foliage_color = info['foliage_color']
|
||||
grass_color = info['grass_color']
|
||||
grass_color_modifier = info['grass_color_modifier']
|
||||
water_color = info['water_color']
|
||||
|
||||
print(f'\t("{name}", Biome::new({temp}, {downfall})', file=f)
|
||||
|
||||
if foliage_color is not None:
|
||||
print(f'\t\t.foliage({color(foliage_color)})', file=f)
|
||||
if grass_color is not None:
|
||||
print(f'\t\t.grass({color(grass_color)})', file=f)
|
||||
if grass_color_modifier is not None:
|
||||
print(f'\t\t.modify({modify(grass_color_modifier)})', file=f)
|
||||
if water_color is not None and water_color != 0x3f76e4:
|
||||
print(f'\t\t.water({color(water_color)})', file=f)
|
||||
|
||||
print('\t),', file=f)
|
||||
|
||||
with open(sys.argv[2], 'w') as f:
|
||||
print('//! Biome data', file=f);
|
||||
print('//!', file=f);
|
||||
print('//! This file is generated using resource/biomes.py, do not edit', file=f);
|
||||
print('', file=f)
|
||||
print('use super::*;', file=f)
|
||||
print('use BiomeGrassColorModifier::*;', file=f)
|
||||
print('', file=f)
|
||||
print('/// List if known biomes and their properties', file=f);
|
||||
print('pub const BIOMES: &[(&str, Biome)] = &[', file=f)
|
||||
|
||||
for name in sorted(biomes):
|
||||
gen_biome(name, biomes[name], f)
|
||||
|
||||
print('];', file=f)
|
|
@ -316,9 +316,13 @@
|
|||
"bubble_coral_fan": null,
|
||||
"bubble_coral_wall_fan": null,
|
||||
"budding_amethyst": {},
|
||||
"bush": {
|
||||
"grass": true
|
||||
},
|
||||
"cactus": {
|
||||
"texture": "cactus_top"
|
||||
},
|
||||
"cactus_flower": {},
|
||||
"cake": {
|
||||
"texture": "cake_top"
|
||||
},
|
||||
|
@ -408,6 +412,7 @@
|
|||
"chiseled_bookshelf": {
|
||||
"texture": "chiseled_bookshelf_top"
|
||||
},
|
||||
"chiseled_copper": {},
|
||||
"chiseled_deepslate": {},
|
||||
"chiseled_nether_bricks": {},
|
||||
"chiseled_polished_blackstone": {},
|
||||
|
@ -415,13 +420,19 @@
|
|||
"chiseled_red_sandstone": {
|
||||
"texture": "red_sandstone_top"
|
||||
},
|
||||
"chiseled_resin_bricks": {},
|
||||
"chiseled_sandstone": {
|
||||
"texture": "sandstone_top"
|
||||
},
|
||||
"chiseled_stone_bricks": {},
|
||||
"chiseled_tuff": {},
|
||||
"chiseled_tuff_bricks": {
|
||||
"texture": "chiseled_tuff_bricks_top"
|
||||
},
|
||||
"chorus_flower": {},
|
||||
"chorus_plant": {},
|
||||
"clay": {},
|
||||
"closed_eyeblossom": null,
|
||||
"coal_block": {},
|
||||
"coal_ore": {},
|
||||
"coarse_dirt": {},
|
||||
|
@ -458,16 +469,28 @@
|
|||
},
|
||||
"conduit": {},
|
||||
"copper_block": {},
|
||||
"copper_bulb": {},
|
||||
"copper_door": {
|
||||
"texture": "copper_door_top"
|
||||
},
|
||||
"copper_grate": {},
|
||||
"copper_ore": {},
|
||||
"copper_trapdoor": {},
|
||||
"cornflower": null,
|
||||
"cracked_deepslate_bricks": {},
|
||||
"cracked_deepslate_tiles": {},
|
||||
"cracked_nether_bricks": {},
|
||||
"cracked_polished_blackstone_bricks": {},
|
||||
"cracked_stone_bricks": {},
|
||||
"crafter": {
|
||||
"texture": "crafter_top"
|
||||
},
|
||||
"crafting_table": {
|
||||
"texture": "crafting_table_top"
|
||||
},
|
||||
"creaking_heart": {
|
||||
"texture": "creaking_heart_top"
|
||||
},
|
||||
"creeper_head": null,
|
||||
"creeper_wall_head": null,
|
||||
"crimson_button": null,
|
||||
|
@ -733,7 +756,14 @@
|
|||
"ender_chest": {
|
||||
"texture": "obsidian"
|
||||
},
|
||||
"exposed_chiseled_copper": {},
|
||||
"exposed_copper": {},
|
||||
"exposed_copper_bulb": {},
|
||||
"exposed_copper_door": {
|
||||
"texture": "exposed_copper_door_top"
|
||||
},
|
||||
"exposed_copper_grate": {},
|
||||
"exposed_copper_trapdoor": {},
|
||||
"exposed_cut_copper": {},
|
||||
"exposed_cut_copper_slab": {
|
||||
"texture": "exposed_cut_copper"
|
||||
|
@ -752,6 +782,7 @@
|
|||
"fire_coral_block": {},
|
||||
"fire_coral_fan": null,
|
||||
"fire_coral_wall_fan": null,
|
||||
"firefly_bush": {},
|
||||
"fletching_table": {
|
||||
"texture": "fletching_table_top"
|
||||
},
|
||||
|
@ -843,6 +874,7 @@
|
|||
"hay_block": {
|
||||
"texture": "hay_block_top"
|
||||
},
|
||||
"heavy_core": {},
|
||||
"heavy_weighted_pressure_plate": {
|
||||
"texture": "iron_block"
|
||||
},
|
||||
|
@ -960,6 +992,7 @@
|
|||
"lava_cauldron": {
|
||||
"texture": "cauldron_top"
|
||||
},
|
||||
"leaf_litter": null,
|
||||
"lectern": {
|
||||
"texture": "lectern_top"
|
||||
},
|
||||
|
@ -1247,6 +1280,7 @@
|
|||
"ochre_froglight": {
|
||||
"texture": "ochre_froglight_top"
|
||||
},
|
||||
"open_eyeblossom": null,
|
||||
"orange_banner": null,
|
||||
"orange_bed": null,
|
||||
"orange_candle": null,
|
||||
|
@ -1269,7 +1303,14 @@
|
|||
"orange_wall_banner": null,
|
||||
"orange_wool": {},
|
||||
"oxeye_daisy": null,
|
||||
"oxidized_chiseled_copper": {},
|
||||
"oxidized_copper": {},
|
||||
"oxidized_copper_bulb": {},
|
||||
"oxidized_copper_door": {
|
||||
"texture": "oxidized_copper_door_top"
|
||||
},
|
||||
"oxidized_copper_grate": {},
|
||||
"oxidized_copper_trapdoor": {},
|
||||
"oxidized_cut_copper": {},
|
||||
"oxidized_cut_copper_slab": {
|
||||
"texture": "oxidized_cut_copper"
|
||||
|
@ -1279,6 +1320,56 @@
|
|||
},
|
||||
"packed_ice": {},
|
||||
"packed_mud": {},
|
||||
"pale_hanging_moss": null,
|
||||
"pale_moss_block": {},
|
||||
"pale_moss_carpet": {},
|
||||
"pale_oak_button": null,
|
||||
"pale_oak_door": {
|
||||
"texture": "pale_oak_door_top"
|
||||
},
|
||||
"pale_oak_fence": {
|
||||
"texture": "pale_oak_planks"
|
||||
},
|
||||
"pale_oak_fence_gate": {
|
||||
"texture": "pale_oak_planks"
|
||||
},
|
||||
"pale_oak_hanging_sign": {
|
||||
"sign_material": "pale_oak",
|
||||
"texture": null
|
||||
},
|
||||
"pale_oak_leaves": {},
|
||||
"pale_oak_log": {
|
||||
"texture": "pale_oak_log_top"
|
||||
},
|
||||
"pale_oak_planks": {},
|
||||
"pale_oak_pressure_plate": {
|
||||
"texture": "pale_oak_planks"
|
||||
},
|
||||
"pale_oak_sapling": {},
|
||||
"pale_oak_sign": {
|
||||
"sign_material": "pale_oak",
|
||||
"texture": null
|
||||
},
|
||||
"pale_oak_slab": {
|
||||
"texture": "pale_oak_planks"
|
||||
},
|
||||
"pale_oak_stairs": {
|
||||
"texture": "pale_oak_planks"
|
||||
},
|
||||
"pale_oak_trapdoor": {},
|
||||
"pale_oak_wall_hanging_sign": {
|
||||
"sign_material": "pale_oak",
|
||||
"texture": null,
|
||||
"wall_sign": true
|
||||
},
|
||||
"pale_oak_wall_sign": {
|
||||
"sign_material": "pale_oak",
|
||||
"texture": null,
|
||||
"wall_sign": true
|
||||
},
|
||||
"pale_oak_wood": {
|
||||
"texture": "pale_oak_log"
|
||||
},
|
||||
"pearlescent_froglight": {
|
||||
"texture": "pearlescent_froglight_top"
|
||||
},
|
||||
|
@ -1390,6 +1481,16 @@
|
|||
"polished_granite_stairs": {
|
||||
"texture": "polished_granite"
|
||||
},
|
||||
"polished_tuff": {},
|
||||
"polished_tuff_slab": {
|
||||
"texture": "polished_tuff"
|
||||
},
|
||||
"polished_tuff_stairs": {
|
||||
"texture": "polished_tuff"
|
||||
},
|
||||
"polished_tuff_wall": {
|
||||
"texture": "polished_tuff"
|
||||
},
|
||||
"poppy": null,
|
||||
"potatoes": {
|
||||
"texture": "potatoes_stage3"
|
||||
|
@ -1424,6 +1525,9 @@
|
|||
"potted_cherry_sapling": {
|
||||
"texture": "cherry_sapling"
|
||||
},
|
||||
"potted_closed_eyeblossom": {
|
||||
"texture": "closed_eyeblossom"
|
||||
},
|
||||
"potted_cornflower": {
|
||||
"texture": "cornflower"
|
||||
},
|
||||
|
@ -1461,12 +1565,18 @@
|
|||
"potted_oak_sapling": {
|
||||
"texture": "oak_sapling"
|
||||
},
|
||||
"potted_open_eyeblossom": {
|
||||
"texture": "open_eyeblossom"
|
||||
},
|
||||
"potted_orange_tulip": {
|
||||
"texture": "orange_tulip"
|
||||
},
|
||||
"potted_oxeye_daisy": {
|
||||
"texture": "oxeye_daisy"
|
||||
},
|
||||
"potted_pale_oak_sapling": {
|
||||
"texture": "pale_oak_sapling"
|
||||
},
|
||||
"potted_pink_tulip": {
|
||||
"texture": "pink_tulip"
|
||||
},
|
||||
|
@ -1629,6 +1739,18 @@
|
|||
"repeating_command_block": {
|
||||
"texture": "repeating_command_block_front"
|
||||
},
|
||||
"resin_block": {},
|
||||
"resin_brick_slab": {
|
||||
"texture": "resin_bricks"
|
||||
},
|
||||
"resin_brick_stairs": {
|
||||
"texture": "resin_bricks"
|
||||
},
|
||||
"resin_brick_wall": {
|
||||
"texture": "resin_bricks"
|
||||
},
|
||||
"resin_bricks": {},
|
||||
"resin_clump": null,
|
||||
"respawn_anchor": {
|
||||
"texture": "respawn_anchor_top"
|
||||
},
|
||||
|
@ -1665,7 +1787,8 @@
|
|||
"sculk_vein": {},
|
||||
"sea_lantern": {},
|
||||
"sea_pickle": {},
|
||||
"seagrass": null,
|
||||
"seagrass": {},
|
||||
"short_dry_grass": {},
|
||||
"short_grass": null,
|
||||
"shroomlight": {},
|
||||
"shulker_box": {},
|
||||
|
@ -1864,6 +1987,12 @@
|
|||
"stripped_oak_wood": {
|
||||
"texture": "stripped_oak_log"
|
||||
},
|
||||
"stripped_pale_oak_log": {
|
||||
"texture": "stripped_pale_oak_log_top"
|
||||
},
|
||||
"stripped_pale_oak_wood": {
|
||||
"texture": "stripped_pale_oak_log"
|
||||
},
|
||||
"stripped_spruce_log": {
|
||||
"texture": "stripped_spruce_log_top"
|
||||
},
|
||||
|
@ -1891,6 +2020,7 @@
|
|||
"sweet_berry_bush": {
|
||||
"texture": "sweet_berry_bush_stage3"
|
||||
},
|
||||
"tall_dry_grass": {},
|
||||
"tall_grass": {
|
||||
"grass": true,
|
||||
"texture": "tall_grass_top"
|
||||
|
@ -1902,6 +2032,8 @@
|
|||
"texture": "target_top"
|
||||
},
|
||||
"terracotta": {},
|
||||
"test_block": null,
|
||||
"test_instance_block": null,
|
||||
"tinted_glass": {},
|
||||
"tnt": {
|
||||
"texture": "tnt_top"
|
||||
|
@ -1912,6 +2044,9 @@
|
|||
"trapped_chest": {
|
||||
"texture": "oak_planks"
|
||||
},
|
||||
"trial_spawner": {
|
||||
"texture": "trial_spawner_top_inactive"
|
||||
},
|
||||
"tripwire": null,
|
||||
"tripwire_hook": null,
|
||||
"tube_coral": null,
|
||||
|
@ -1919,9 +2054,31 @@
|
|||
"tube_coral_fan": null,
|
||||
"tube_coral_wall_fan": null,
|
||||
"tuff": {},
|
||||
"tuff_brick_slab": {
|
||||
"texture": "tuff_bricks"
|
||||
},
|
||||
"tuff_brick_stairs": {
|
||||
"texture": "tuff_bricks"
|
||||
},
|
||||
"tuff_brick_wall": {
|
||||
"texture": "tuff_bricks"
|
||||
},
|
||||
"tuff_bricks": {},
|
||||
"tuff_slab": {
|
||||
"texture": "tuff"
|
||||
},
|
||||
"tuff_stairs": {
|
||||
"texture": "tuff"
|
||||
},
|
||||
"tuff_wall": {
|
||||
"texture": "tuff"
|
||||
},
|
||||
"turtle_egg": {},
|
||||
"twisting_vines": {},
|
||||
"twisting_vines_plant": {},
|
||||
"vault": {
|
||||
"texture": "vault_top"
|
||||
},
|
||||
"verdant_froglight": {
|
||||
"texture": "verdant_froglight_top"
|
||||
},
|
||||
|
@ -1991,9 +2148,24 @@
|
|||
"water_cauldron": {
|
||||
"texture": "cauldron_top"
|
||||
},
|
||||
"waxed_chiseled_copper": {
|
||||
"texture": "chiseled_copper"
|
||||
},
|
||||
"waxed_copper_block": {
|
||||
"texture": "copper_block"
|
||||
},
|
||||
"waxed_copper_bulb": {
|
||||
"texture": "copper_bulb"
|
||||
},
|
||||
"waxed_copper_door": {
|
||||
"texture": "copper_door_top"
|
||||
},
|
||||
"waxed_copper_grate": {
|
||||
"texture": "copper_grate"
|
||||
},
|
||||
"waxed_copper_trapdoor": {
|
||||
"texture": "copper_trapdoor"
|
||||
},
|
||||
"waxed_cut_copper": {
|
||||
"texture": "cut_copper"
|
||||
},
|
||||
|
@ -2003,9 +2175,24 @@
|
|||
"waxed_cut_copper_stairs": {
|
||||
"texture": "cut_copper"
|
||||
},
|
||||
"waxed_exposed_chiseled_copper": {
|
||||
"texture": "exposed_chiseled_copper"
|
||||
},
|
||||
"waxed_exposed_copper": {
|
||||
"texture": "exposed_copper"
|
||||
},
|
||||
"waxed_exposed_copper_bulb": {
|
||||
"texture": "exposed_copper_bulb"
|
||||
},
|
||||
"waxed_exposed_copper_door": {
|
||||
"texture": "exposed_copper_door_top"
|
||||
},
|
||||
"waxed_exposed_copper_grate": {
|
||||
"texture": "exposed_copper_grate"
|
||||
},
|
||||
"waxed_exposed_copper_trapdoor": {
|
||||
"texture": "exposed_copper_trapdoor"
|
||||
},
|
||||
"waxed_exposed_cut_copper": {
|
||||
"texture": "exposed_cut_copper"
|
||||
},
|
||||
|
@ -2015,9 +2202,24 @@
|
|||
"waxed_exposed_cut_copper_stairs": {
|
||||
"texture": "exposed_cut_copper"
|
||||
},
|
||||
"waxed_oxidized_chiseled_copper": {
|
||||
"texture": "oxidized_chiseled_copper"
|
||||
},
|
||||
"waxed_oxidized_copper": {
|
||||
"texture": "oxidized_copper"
|
||||
},
|
||||
"waxed_oxidized_copper_bulb": {
|
||||
"texture": "oxidized_copper_bulb"
|
||||
},
|
||||
"waxed_oxidized_copper_door": {
|
||||
"texture": "oxidized_copper_door_top"
|
||||
},
|
||||
"waxed_oxidized_copper_grate": {
|
||||
"texture": "oxidized_copper_grate"
|
||||
},
|
||||
"waxed_oxidized_copper_trapdoor": {
|
||||
"texture": "oxidized_copper_trapdoor"
|
||||
},
|
||||
"waxed_oxidized_cut_copper": {
|
||||
"texture": "oxidized_cut_copper"
|
||||
},
|
||||
|
@ -2027,9 +2229,24 @@
|
|||
"waxed_oxidized_cut_copper_stairs": {
|
||||
"texture": "oxidized_cut_copper"
|
||||
},
|
||||
"waxed_weathered_chiseled_copper": {
|
||||
"texture": "weathered_chiseled_copper"
|
||||
},
|
||||
"waxed_weathered_copper": {
|
||||
"texture": "weathered_copper"
|
||||
},
|
||||
"waxed_weathered_copper_bulb": {
|
||||
"texture": "weathered_copper_bulb"
|
||||
},
|
||||
"waxed_weathered_copper_door": {
|
||||
"texture": "weathered_copper_door_top"
|
||||
},
|
||||
"waxed_weathered_copper_grate": {
|
||||
"texture": "weathered_copper_grate"
|
||||
},
|
||||
"waxed_weathered_copper_trapdoor": {
|
||||
"texture": "weathered_copper_trapdoor"
|
||||
},
|
||||
"waxed_weathered_cut_copper": {
|
||||
"texture": "weathered_cut_copper"
|
||||
},
|
||||
|
@ -2039,7 +2256,14 @@
|
|||
"waxed_weathered_cut_copper_stairs": {
|
||||
"texture": "weathered_cut_copper"
|
||||
},
|
||||
"weathered_chiseled_copper": {},
|
||||
"weathered_copper": {},
|
||||
"weathered_copper_bulb": {},
|
||||
"weathered_copper_door": {
|
||||
"texture": "weathered_copper_door_top"
|
||||
},
|
||||
"weathered_copper_grate": {},
|
||||
"weathered_copper_trapdoor": {},
|
||||
"weathered_cut_copper": {},
|
||||
"weathered_cut_copper_slab": {
|
||||
"texture": "weathered_cut_copper"
|
||||
|
@ -2074,6 +2298,7 @@
|
|||
"white_tulip": null,
|
||||
"white_wall_banner": null,
|
||||
"white_wool": {},
|
||||
"wildflowers": null,
|
||||
"wither_rose": null,
|
||||
"wither_skeleton_skull": null,
|
||||
"wither_skeleton_wall_skull": null,
|
||||
|
|
|
@ -14,10 +14,15 @@ with open(sys.argv[1]) as f:
|
|||
output = {}
|
||||
|
||||
with open(sys.argv[2], 'w') as f:
|
||||
print('//! Block type information', file=f);
|
||||
print('//!', file=f);
|
||||
print('//! This file is generated using resource/generate.py, do not edit', file=f);
|
||||
print('', file=f)
|
||||
print('use enumflags2::make_bitflags;', file=f);
|
||||
print('', file=f)
|
||||
print('use super::*;', file=f)
|
||||
print('', file=f)
|
||||
print('/// List if known block types and their properties', file=f);
|
||||
print('pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[', file=f)
|
||||
|
||||
for name, info in colors.items():
|
||||
|
|
|
@ -15,6 +15,7 @@ MATERIALS = [
|
|||
'jungle',
|
||||
'mangrove',
|
||||
'oak',
|
||||
'pale_oak',
|
||||
'spruce',
|
||||
'warped',
|
||||
]
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
fmt::Debug,
|
||||
hash::Hash,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use indexmap::IndexSet;
|
||||
use bincode::{Decode, Encode};
|
||||
use clap::ValueEnum;
|
||||
use regex::{Regex, RegexSet};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
io::fs::FileMetaVersion,
|
||||
|
@ -18,13 +20,13 @@ use crate::{
|
|||
world::{block_entity::BlockEntity, layer},
|
||||
};
|
||||
|
||||
/// Increase to force regeneration of all output files
|
||||
// Increase to force regeneration of all output files
|
||||
|
||||
/// MinedMap processed region data version number
|
||||
///
|
||||
/// Increase when the generation of processed regions from region data changes
|
||||
/// (usually because of updated resource data)
|
||||
pub const REGION_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(1);
|
||||
pub const REGION_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(7);
|
||||
|
||||
/// MinedMap map tile data version number
|
||||
///
|
||||
|
@ -36,7 +38,7 @@ pub const MAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
|
|||
///
|
||||
/// Increase when the generation of lightmap tiles from region data changes
|
||||
/// (usually because of updated resource data)
|
||||
pub const LIGHTMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(1);
|
||||
pub const LIGHTMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(5);
|
||||
|
||||
/// MinedMap mipmap data version number
|
||||
///
|
||||
|
@ -46,7 +48,7 @@ pub const MIPMAP_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
|
|||
/// MinedMap processed entity data version number
|
||||
///
|
||||
/// Increase when entity collection changes bacause of code changes.
|
||||
pub const ENTITIES_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(0);
|
||||
pub const ENTITIES_FILE_META_VERSION: FileMetaVersion = FileMetaVersion(3);
|
||||
|
||||
/// Coordinate pair of a generated tile
|
||||
///
|
||||
|
@ -85,7 +87,7 @@ impl TileCoordMap {
|
|||
}
|
||||
|
||||
/// Data structure for storing chunk data between processing and rendering steps
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Encode, Decode)]
|
||||
pub struct ProcessedChunk {
|
||||
/// Block type data
|
||||
pub blocks: Box<layer::BlockArray>,
|
||||
|
@ -96,18 +98,18 @@ pub struct ProcessedChunk {
|
|||
}
|
||||
|
||||
/// Data structure for storing region data between processing and rendering steps
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Encode, Decode)]
|
||||
pub struct ProcessedRegion {
|
||||
/// List of biomes used in the region
|
||||
///
|
||||
/// Indexed by [ProcessedChunk] biome data
|
||||
pub biome_list: IndexSet<Biome>,
|
||||
pub biome_list: Vec<Biome>,
|
||||
/// Processed chunk data
|
||||
pub chunks: ChunkArray<Option<Box<ProcessedChunk>>>,
|
||||
}
|
||||
|
||||
/// Data structure for storing entity data between processing and collection steps
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Encode, Decode)]
|
||||
pub struct ProcessedEntities {
|
||||
/// List of block entities
|
||||
pub block_entities: Vec<BlockEntity>,
|
||||
|
@ -134,10 +136,14 @@ pub enum TileKind {
|
|||
pub struct Config {
|
||||
/// Number of threads for parallel processing
|
||||
pub num_threads: usize,
|
||||
/// Number of threads for initial parallel processing
|
||||
pub num_threads_initial: usize,
|
||||
/// Path of input region directory
|
||||
pub region_dir: PathBuf,
|
||||
/// Path of input `level.dat` file
|
||||
pub level_dat_path: PathBuf,
|
||||
/// Path of input `level.dat_old` file
|
||||
pub level_dat_old_path: PathBuf,
|
||||
/// Base path for storage of rendered tile data
|
||||
pub output_dir: PathBuf,
|
||||
/// Path for storage of intermediate processed data files
|
||||
|
@ -150,6 +156,8 @@ pub struct Config {
|
|||
pub viewer_info_path: PathBuf,
|
||||
/// Path of viewer entities file
|
||||
pub viewer_entities_path: PathBuf,
|
||||
/// Format of generated map tiles
|
||||
pub image_format: ImageFormat,
|
||||
/// Sign text filter patterns
|
||||
pub sign_patterns: RegexSet,
|
||||
/// Sign text transformation pattern
|
||||
|
@ -164,9 +172,13 @@ impl Config {
|
|||
Some(threads) => threads,
|
||||
None => 1,
|
||||
};
|
||||
let num_threads_initial = args.jobs_initial.unwrap_or(num_threads);
|
||||
|
||||
let region_dir = [&args.input_dir, Path::new("region")].iter().collect();
|
||||
let level_dat_path = [&args.input_dir, Path::new("level.dat")].iter().collect();
|
||||
let level_dat_old_path = [&args.input_dir, Path::new("level.dat_old")]
|
||||
.iter()
|
||||
.collect();
|
||||
let processed_dir: PathBuf = [&args.output_dir, Path::new("processed")].iter().collect();
|
||||
let entities_dir: PathBuf = [&processed_dir, Path::new("entities")].iter().collect();
|
||||
let entities_path_final = [&entities_dir, Path::new("entities.bin")].iter().collect();
|
||||
|
@ -181,14 +193,17 @@ impl Config {
|
|||
|
||||
Ok(Config {
|
||||
num_threads,
|
||||
num_threads_initial,
|
||||
region_dir,
|
||||
level_dat_path,
|
||||
level_dat_old_path,
|
||||
output_dir: args.output_dir.clone(),
|
||||
processed_dir,
|
||||
entities_dir,
|
||||
entities_path_final,
|
||||
viewer_info_path,
|
||||
viewer_entities_path,
|
||||
image_format: args.image_format,
|
||||
sign_patterns,
|
||||
sign_transforms,
|
||||
})
|
||||
|
@ -264,14 +279,39 @@ impl Config {
|
|||
[&self.output_dir, Path::new(&dir)].iter().collect()
|
||||
}
|
||||
|
||||
/// Returns the file extension for the configured image format
|
||||
pub fn tile_extension(&self) -> &'static str {
|
||||
match self.image_format {
|
||||
ImageFormat::Png => "png",
|
||||
ImageFormat::Webp => "webp",
|
||||
}
|
||||
}
|
||||
/// Returns the configurured image format for the image library
|
||||
pub fn tile_image_format(&self) -> image::ImageFormat {
|
||||
match self.image_format {
|
||||
ImageFormat::Png => image::ImageFormat::Png,
|
||||
ImageFormat::Webp => image::ImageFormat::WebP,
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs the path of an output tile image
|
||||
pub fn tile_path(&self, kind: TileKind, level: usize, coords: TileCoords) -> PathBuf {
|
||||
let filename = coord_filename(coords, "png");
|
||||
let filename = coord_filename(coords, self.tile_extension());
|
||||
let dir = self.tile_dir(kind, level);
|
||||
[Path::new(&dir), Path::new(&filename)].iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Format of generated map tiles
|
||||
#[derive(Debug, Clone, Copy, Default, ValueEnum)]
|
||||
pub enum ImageFormat {
|
||||
/// Generate PNG images
|
||||
#[default]
|
||||
Png,
|
||||
/// Generate WebP images
|
||||
Webp,
|
||||
}
|
||||
|
||||
/// Copies a chunk image into a region tile
|
||||
pub fn overlay_chunk<I, J>(image: &mut I, chunk: &J, coords: ChunkCoords)
|
||||
where
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct EntityCollector<'a> {
|
|||
regions: &'a [TileCoords],
|
||||
}
|
||||
|
||||
impl<'a> TileMerger for EntityCollector<'a> {
|
||||
impl TileMerger for EntityCollector<'_> {
|
||||
fn file_meta_version(&self) -> fs::FileMetaVersion {
|
||||
ENTITIES_FILE_META_VERSION
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ impl<'a> TileMerger for EntityCollector<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> TileCollector for EntityCollector<'a> {
|
||||
impl TileCollector for EntityCollector<'_> {
|
||||
type CollectOutput = ();
|
||||
|
||||
fn tiles(&self) -> &[TileCoords] {
|
||||
|
@ -78,23 +78,22 @@ impl<'a> EntityCollector<'a> {
|
|||
let mut output = ProcessedEntities::default();
|
||||
|
||||
for source_path in sources {
|
||||
let mut source: ProcessedEntities =
|
||||
match storage::read_file(source_path.as_ref(), storage::Format::Json) {
|
||||
Ok(source) => source,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Failed to read entity data file {}: {:?}",
|
||||
source_path.as_ref().display(),
|
||||
err,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let mut source: ProcessedEntities = match storage::read_file(source_path.as_ref()) {
|
||||
Ok(source) => source,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Failed to read entity data file {}: {:?}",
|
||||
source_path.as_ref().display(),
|
||||
err,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
output.block_entities.append(&mut source.block_entities);
|
||||
}
|
||||
|
||||
storage::write(file, &output, storage::Format::Json).context("Failed to write entity data")
|
||||
storage::write(file, &output).context("Failed to write entity data")
|
||||
}
|
||||
|
||||
/// Runs the mipmap generation
|
||||
|
|
|
@ -61,6 +61,8 @@ struct Metadata<'t> {
|
|||
spawn: Spawn,
|
||||
/// Enabled MinedMap features
|
||||
features: Features,
|
||||
/// Format of generated map tiles
|
||||
tile_extension: &'static str,
|
||||
}
|
||||
|
||||
/// Viewer entity JSON data structure
|
||||
|
@ -122,7 +124,14 @@ impl<'a> MetadataWriter<'a> {
|
|||
|
||||
/// Reads and deserializes the `level.dat` of the Minecraft save data
|
||||
fn read_level_dat(&self) -> Result<de::LevelDat> {
|
||||
crate::nbt::data::from_file(&self.config.level_dat_path).context("Failed to read level.dat")
|
||||
let res = crate::nbt::data::from_file(&self.config.level_dat_path);
|
||||
if res.is_err() {
|
||||
if let Ok(level_dat_old) = crate::nbt::data::from_file(&self.config.level_dat_old_path)
|
||||
{
|
||||
return Ok(level_dat_old);
|
||||
}
|
||||
}
|
||||
res.context("Failed to read level.dat")
|
||||
}
|
||||
|
||||
/// Generates [Spawn] data from a [de::LevelDat]
|
||||
|
@ -170,9 +179,8 @@ impl<'a> MetadataWriter<'a> {
|
|||
|
||||
/// Generates [Entities] data from collected entity lists
|
||||
fn entities(&self) -> Result<Entities> {
|
||||
let data: ProcessedEntities =
|
||||
storage::read_file(&self.config.entities_path_final, storage::Format::Json)
|
||||
.context("Failed to read entity data file")?;
|
||||
let data: ProcessedEntities = storage::read_file(&self.config.entities_path_final)
|
||||
.context("Failed to read entity data file")?;
|
||||
|
||||
let ret = Entities {
|
||||
signs: data
|
||||
|
@ -205,6 +213,7 @@ impl<'a> MetadataWriter<'a> {
|
|||
mipmaps: Vec::new(),
|
||||
spawn: Self::spawn(&level_dat),
|
||||
features,
|
||||
tile_extension: self.config.tile_extension(),
|
||||
};
|
||||
|
||||
for tile_map in self.tiles.iter() {
|
||||
|
|
141
src/core/mod.rs
|
@ -10,31 +10,46 @@ mod tile_merger;
|
|||
mod tile_mipmapper;
|
||||
mod tile_renderer;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::mpsc::{self, Receiver},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use git_version::git_version;
|
||||
|
||||
use common::Config;
|
||||
use common::{Config, ImageFormat};
|
||||
use metadata_writer::MetadataWriter;
|
||||
use notify::{RecommendedWatcher, RecursiveMode, Watcher as _};
|
||||
use rayon::ThreadPool;
|
||||
use region_processor::RegionProcessor;
|
||||
use tile_mipmapper::TileMipmapper;
|
||||
use tile_renderer::TileRenderer;
|
||||
use tokio::runtime::Runtime;
|
||||
use tracing::{info, warn};
|
||||
|
||||
use self::entity_collector::EntityCollector;
|
||||
|
||||
/// MinedMap version number
|
||||
const VERSION: &str = git_version!(
|
||||
args = ["--abbrev=7", "--match=v*", "--dirty=-modified"],
|
||||
cargo_prefix = "v",
|
||||
);
|
||||
/// Returns the MinedMap version number
|
||||
fn version() -> &'static str {
|
||||
option_env!("MINEDMAP_VERSION").unwrap_or(
|
||||
git_version!(
|
||||
args = ["--abbrev=7", "--match=v*", "--dirty=-modified"],
|
||||
cargo_prefix = "v",
|
||||
)
|
||||
.strip_prefix("v")
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Command line arguments for minedmap CLI
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(
|
||||
about,
|
||||
version = VERSION.strip_prefix("v").unwrap(),
|
||||
version = version(),
|
||||
max_term_width = 100,
|
||||
)]
|
||||
pub struct Args {
|
||||
|
@ -44,9 +59,29 @@ pub struct Args {
|
|||
/// use one thread per logical CPU core.
|
||||
#[arg(short, long)]
|
||||
pub jobs: Option<usize>,
|
||||
/// Number of parallel threads to use for initial processing
|
||||
///
|
||||
/// Passing this option only makes sense with --watch. The first run after
|
||||
/// starting MinedMap will use as many parallel jobs as configured using
|
||||
/// --job-initial, while subsequent regenerations of tiles will use the
|
||||
/// the number configured using --jobs.
|
||||
///
|
||||
/// If not given, the value from the --jobs option is used.
|
||||
#[arg(long)]
|
||||
pub jobs_initial: Option<usize>,
|
||||
/// Enable verbose messages
|
||||
#[arg(short, long)]
|
||||
pub verbose: bool,
|
||||
/// Watch for file changes and regenerate tiles automatically instead of
|
||||
/// exiting after generation
|
||||
#[arg(long)]
|
||||
pub watch: bool,
|
||||
/// Minimum delay between map generation cycles in watch mode
|
||||
#[arg(long, value_parser = humantime::parse_duration, default_value = "30s")]
|
||||
pub watch_delay: Duration,
|
||||
/// Format of generated map tiles
|
||||
#[arg(long, value_enum, default_value_t)]
|
||||
pub image_format: ImageFormat,
|
||||
/// Prefix for text of signs to show on the map
|
||||
#[arg(long)]
|
||||
pub sign_prefix: Vec<String>,
|
||||
|
@ -71,14 +106,73 @@ pub struct Args {
|
|||
pub output_dir: PathBuf,
|
||||
}
|
||||
|
||||
/// Configures the Rayon thread pool for parallel processing
|
||||
fn setup_threads(num_threads: usize) -> Result<()> {
|
||||
/// Configures a Rayon thread pool for parallel processing
|
||||
fn setup_threads(num_threads: usize) -> Result<ThreadPool> {
|
||||
rayon::ThreadPoolBuilder::new()
|
||||
.num_threads(num_threads)
|
||||
.build_global()
|
||||
.build()
|
||||
.context("Failed to configure thread pool")
|
||||
}
|
||||
|
||||
/// Runs all MinedMap generation steps, updating all tiles as needed
|
||||
fn generate(config: &Config, rt: &Runtime) -> Result<()> {
|
||||
let regions = RegionProcessor::new(config).run()?;
|
||||
TileRenderer::new(config, rt, ®ions).run()?;
|
||||
let tiles = TileMipmapper::new(config, ®ions).run()?;
|
||||
EntityCollector::new(config, ®ions).run()?;
|
||||
MetadataWriter::new(config, &tiles).run()
|
||||
}
|
||||
|
||||
/// Creates a file watcher for the
|
||||
fn create_watcher(args: &Args) -> Result<(RecommendedWatcher, Receiver<()>)> {
|
||||
let (tx, rx) = mpsc::sync_channel::<()>(1);
|
||||
let mut watcher = notify::recommended_watcher(move |res| {
|
||||
// Ignore errors - we already have a watch trigger queued if try_send() fails
|
||||
let event: notify::Event = match res {
|
||||
Ok(event) => event,
|
||||
Err(err) => {
|
||||
warn!("Watch error: {err}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let notify::EventKind::Modify(modify_kind) = event.kind else {
|
||||
return;
|
||||
};
|
||||
if !matches!(
|
||||
modify_kind,
|
||||
notify::event::ModifyKind::Data(_)
|
||||
| notify::event::ModifyKind::Name(notify::event::RenameMode::To)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if !event
|
||||
.paths
|
||||
.iter()
|
||||
.any(|path| path.ends_with("level.dat") || path.extension() == Some("mcu".as_ref()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
let _ = tx.try_send(());
|
||||
})?;
|
||||
watcher.watch(&args.input_dir, RecursiveMode::Recursive)?;
|
||||
Ok((watcher, rx))
|
||||
}
|
||||
|
||||
/// Watches the data directory for changes, returning when a change has happened
|
||||
fn wait_watcher(args: &Args, watch_channel: &Receiver<()>) -> Result<()> {
|
||||
info!("Watching for changes...");
|
||||
let () = watch_channel
|
||||
.recv()
|
||||
.context("Failed to read watch event channel")?;
|
||||
info!("Change detected.");
|
||||
|
||||
thread::sleep(args.watch_delay);
|
||||
|
||||
let _ = watch_channel.try_recv();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// MinedMap CLI main function
|
||||
pub fn cli() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
|
@ -93,17 +187,28 @@ pub fn cli() -> Result<()> {
|
|||
.with_target(false)
|
||||
.init();
|
||||
|
||||
setup_threads(config.num_threads)?;
|
||||
let mut pool = setup_threads(config.num_threads_initial)?;
|
||||
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let regions = RegionProcessor::new(&config).run()?;
|
||||
TileRenderer::new(&config, &rt, ®ions).run()?;
|
||||
let tiles = TileMipmapper::new(&config, ®ions).run()?;
|
||||
EntityCollector::new(&config, ®ions).run()?;
|
||||
MetadataWriter::new(&config, &tiles).run()?;
|
||||
let watch = args.watch.then(|| create_watcher(&args)).transpose()?;
|
||||
|
||||
Ok(())
|
||||
pool.install(|| generate(&config, &rt))?;
|
||||
|
||||
let Some((_watcher, watch_channel)) = watch else {
|
||||
// watch mode disabled
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if config.num_threads != config.num_threads_initial {
|
||||
pool = setup_threads(config.num_threads)?;
|
||||
}
|
||||
pool.install(move || {
|
||||
loop {
|
||||
wait_watcher(&args, &watch_channel)?;
|
||||
generate(&config, &rt)?;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ use std::{ffi::OsStr, path::PathBuf, sync::mpsc, time::SystemTime};
|
|||
|
||||
use anyhow::{Context, Result};
|
||||
use enum_map::{Enum, EnumMap};
|
||||
use indexmap::IndexSet;
|
||||
use minedmap_resource::Biome;
|
||||
use rayon::prelude::*;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
|
@ -43,6 +45,37 @@ enum RegionProcessorStatus {
|
|||
ErrorMissing,
|
||||
}
|
||||
|
||||
/// Data of a region being processed by a [SingleRegionProcessor]
|
||||
#[derive(Debug)]
|
||||
struct SingleRegionData {
|
||||
/// [IndexSet] of biomes used by the processed region
|
||||
biome_list: IndexSet<Biome>,
|
||||
/// Processed region chunk intermediate data
|
||||
chunks: ChunkArray<Option<Box<ProcessedChunk>>>,
|
||||
/// Lightmap intermediate data
|
||||
lightmap: image::GrayAlphaImage,
|
||||
/// Processed entity intermediate data
|
||||
entities: ProcessedEntities,
|
||||
/// True if any unknown block or biome types were encountered during processing
|
||||
has_unknown: bool,
|
||||
}
|
||||
|
||||
impl Default for SingleRegionData {
|
||||
fn default() -> Self {
|
||||
/// Width/height of the region data
|
||||
const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32;
|
||||
|
||||
let lightmap = image::GrayAlphaImage::new(N, N);
|
||||
Self {
|
||||
biome_list: Default::default(),
|
||||
chunks: Default::default(),
|
||||
lightmap,
|
||||
entities: Default::default(),
|
||||
has_unknown: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles processing for a single region
|
||||
struct SingleRegionProcessor<'a> {
|
||||
/// Registry of known block types
|
||||
|
@ -73,22 +106,13 @@ struct SingleRegionProcessor<'a> {
|
|||
lightmap_needed: bool,
|
||||
/// True if entity output file needs to be updated
|
||||
entities_needed: bool,
|
||||
/// Processed region intermediate data
|
||||
processed_region: ProcessedRegion,
|
||||
/// Lightmap intermediate data
|
||||
lightmap: image::GrayAlphaImage,
|
||||
/// Processed entity intermediate data
|
||||
entities: ProcessedEntities,
|
||||
/// True if any unknown block or biome types were encountered during processing
|
||||
has_unknown: bool,
|
||||
/// Format of generated map tiles
|
||||
image_format: image::ImageFormat,
|
||||
}
|
||||
|
||||
impl<'a> SingleRegionProcessor<'a> {
|
||||
/// Initializes a [SingleRegionProcessor]
|
||||
fn new(processor: &'a RegionProcessor<'a>, coords: TileCoords) -> Result<Self> {
|
||||
/// Width/height of the region data
|
||||
const N: u32 = (BLOCKS_PER_CHUNK * CHUNKS_PER_REGION) as u32;
|
||||
|
||||
let input_path = processor.config.region_path(coords);
|
||||
let input_timestamp = fs::modified_timestamp(&input_path)?;
|
||||
|
||||
|
@ -105,10 +129,6 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
let lightmap_needed = Some(input_timestamp) > lightmap_timestamp;
|
||||
let entities_needed = Some(input_timestamp) > entities_timestamp;
|
||||
|
||||
let processed_region = ProcessedRegion::default();
|
||||
let lightmap = image::GrayAlphaImage::new(N, N);
|
||||
let entities = ProcessedEntities::default();
|
||||
|
||||
Ok(SingleRegionProcessor {
|
||||
block_types: &processor.block_types,
|
||||
biome_types: &processor.biome_types,
|
||||
|
@ -124,10 +144,7 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
output_needed,
|
||||
lightmap_needed,
|
||||
entities_needed,
|
||||
processed_region,
|
||||
lightmap,
|
||||
entities,
|
||||
has_unknown: false,
|
||||
image_format: processor.config.tile_image_format(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -151,15 +168,14 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
/// Saves processed region data
|
||||
///
|
||||
/// The timestamp is the time of the last modification of the input region data.
|
||||
fn save_region(&self) -> Result<()> {
|
||||
fn save_region(&self, processed_region: &ProcessedRegion) -> Result<()> {
|
||||
if !self.output_needed {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
storage::write_file(
|
||||
&self.output_path,
|
||||
&self.processed_region,
|
||||
storage::Format::Bincode,
|
||||
processed_region,
|
||||
REGION_FILE_META_VERSION,
|
||||
self.input_timestamp,
|
||||
)
|
||||
|
@ -168,7 +184,7 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
/// Saves a lightmap tile
|
||||
///
|
||||
/// The timestamp is the time of the last modification of the input region data.
|
||||
fn save_lightmap(&self) -> Result<()> {
|
||||
fn save_lightmap(&self, lightmap: &image::GrayAlphaImage) -> Result<()> {
|
||||
if !self.lightmap_needed {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -178,8 +194,8 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
LIGHTMAP_FILE_META_VERSION,
|
||||
self.input_timestamp,
|
||||
|file| {
|
||||
self.lightmap
|
||||
.write_to(file, image::ImageFormat::Png)
|
||||
lightmap
|
||||
.write_to(file, self.image_format)
|
||||
.context("Failed to save image")
|
||||
},
|
||||
)
|
||||
|
@ -188,28 +204,32 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
/// Saves processed entity data
|
||||
///
|
||||
/// The timestamp is the time of the last modification of the input region data.
|
||||
fn save_entities(&mut self) -> Result<()> {
|
||||
fn save_entities(&self, entities: &mut ProcessedEntities) -> Result<()> {
|
||||
if !self.entities_needed {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.entities.block_entities.sort_unstable();
|
||||
entities.block_entities.sort_unstable();
|
||||
|
||||
storage::write_file(
|
||||
&self.entities_path,
|
||||
&self.entities,
|
||||
storage::Format::Json,
|
||||
entities,
|
||||
ENTITIES_FILE_META_VERSION,
|
||||
self.input_timestamp,
|
||||
)
|
||||
}
|
||||
|
||||
/// Processes a single chunk
|
||||
fn process_chunk(&mut self, chunk_coords: ChunkCoords, data: world::de::Chunk) -> Result<()> {
|
||||
fn process_chunk(
|
||||
&self,
|
||||
data: &mut SingleRegionData,
|
||||
chunk_coords: ChunkCoords,
|
||||
chunk_data: world::de::Chunk,
|
||||
) -> Result<()> {
|
||||
let (chunk, has_unknown) =
|
||||
world::chunk::Chunk::new(&data, self.block_types, self.biome_types)
|
||||
world::chunk::Chunk::new(&chunk_data, self.block_types, self.biome_types)
|
||||
.with_context(|| format!("Failed to decode chunk {:?}", chunk_coords))?;
|
||||
self.has_unknown |= has_unknown;
|
||||
data.has_unknown |= has_unknown;
|
||||
|
||||
if self.output_needed || self.lightmap_needed {
|
||||
if let Some(layer::LayerData {
|
||||
|
@ -217,11 +237,11 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
biomes,
|
||||
block_light,
|
||||
depths,
|
||||
}) = world::layer::top_layer(&mut self.processed_region.biome_list, &chunk)
|
||||
}) = world::layer::top_layer(&mut data.biome_list, &chunk)
|
||||
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?
|
||||
{
|
||||
if self.output_needed {
|
||||
self.processed_region.chunks[chunk_coords] = Some(Box::new(ProcessedChunk {
|
||||
data.chunks[chunk_coords] = Some(Box::new(ProcessedChunk {
|
||||
blocks,
|
||||
biomes,
|
||||
depths,
|
||||
|
@ -230,7 +250,7 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
|
||||
if self.lightmap_needed {
|
||||
let chunk_lightmap = Self::render_chunk_lightmap(block_light);
|
||||
overlay_chunk(&mut self.lightmap, &chunk_lightmap, chunk_coords);
|
||||
overlay_chunk(&mut data.lightmap, &chunk_lightmap, chunk_coords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,20 +262,21 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
chunk_coords,
|
||||
)
|
||||
})?;
|
||||
self.entities.block_entities.append(&mut block_entities);
|
||||
data.entities.block_entities.append(&mut block_entities);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Processes the chunks of the region
|
||||
fn process_chunks(&mut self) -> Result<()> {
|
||||
crate::nbt::region::from_file(&self.input_path)?
|
||||
.foreach_chunk(|chunk_coords, data| self.process_chunk(chunk_coords, data))
|
||||
fn process_chunks(&self, data: &mut SingleRegionData) -> Result<()> {
|
||||
crate::nbt::region::from_file(&self.input_path)?.foreach_chunk(
|
||||
|chunk_coords, chunk_data| self.process_chunk(data, chunk_coords, chunk_data),
|
||||
)
|
||||
}
|
||||
|
||||
/// Processes the region
|
||||
fn run(mut self) -> Result<RegionProcessorStatus> {
|
||||
fn run(&self) -> Result<RegionProcessorStatus> {
|
||||
if !self.output_needed && !self.lightmap_needed && !self.entities_needed {
|
||||
debug!(
|
||||
"Skipping unchanged region r.{}.{}.mca",
|
||||
|
@ -269,7 +290,9 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
self.coords.x, self.coords.z
|
||||
);
|
||||
|
||||
if let Err(err) = self.process_chunks() {
|
||||
let mut data = SingleRegionData::default();
|
||||
|
||||
if let Err(err) = self.process_chunks(&mut data) {
|
||||
if self.output_timestamp.is_some()
|
||||
&& self.lightmap_timestamp.is_some()
|
||||
&& self.entities_timestamp.is_some()
|
||||
|
@ -288,11 +311,16 @@ impl<'a> SingleRegionProcessor<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
self.save_region()?;
|
||||
self.save_lightmap()?;
|
||||
self.save_entities()?;
|
||||
let processed_region = ProcessedRegion {
|
||||
biome_list: data.biome_list.into_iter().collect(),
|
||||
chunks: data.chunks,
|
||||
};
|
||||
|
||||
Ok(if self.has_unknown {
|
||||
self.save_region(&processed_region)?;
|
||||
self.save_lightmap(&data.lightmap)?;
|
||||
self.save_entities(&mut data.entities)?;
|
||||
|
||||
Ok(if data.has_unknown {
|
||||
RegionProcessorStatus::OkWithUnknown
|
||||
} else {
|
||||
RegionProcessorStatus::Ok
|
||||
|
|
|
@ -74,7 +74,7 @@ impl<'a, P> MapMerger<'a, P> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: image::PixelWithColorType> TileMerger for MapMerger<'a, P>
|
||||
impl<P: image::PixelWithColorType> TileMerger for MapMerger<'_, P>
|
||||
where
|
||||
[P::Subpixel]: image::EncodableLayout,
|
||||
image::ImageBuffer<P, Vec<P::Subpixel>>: Into<image::DynamicImage>,
|
||||
|
@ -144,7 +144,7 @@ where
|
|||
}
|
||||
|
||||
image
|
||||
.write_to(file, image::ImageFormat::Png)
|
||||
.write_to(file, self.config.tile_image_format())
|
||||
.context("Failed to save image")
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ pub struct TileMipmapper<'a> {
|
|||
regions: &'a [TileCoords],
|
||||
}
|
||||
|
||||
impl<'a> TileCollector for TileMipmapper<'a> {
|
||||
impl TileCollector for TileMipmapper<'_> {
|
||||
type CollectOutput = MipmapStat;
|
||||
|
||||
fn tiles(&self) -> &[TileCoords] {
|
||||
|
|
|
@ -16,7 +16,7 @@ use tracing::{debug, info};
|
|||
use super::{common::*, region_group::RegionGroup};
|
||||
use crate::{
|
||||
io::{fs, storage},
|
||||
resource::{block_color, needs_biome, Colorf},
|
||||
resource::{Colorf, block_color, needs_biome},
|
||||
types::*,
|
||||
util::coord_offset,
|
||||
};
|
||||
|
@ -105,8 +105,7 @@ impl<'a> TileRenderer<'a> {
|
|||
|
||||
region_loader
|
||||
.get_or_try_init(|| async {
|
||||
storage::read_file(&processed_path, storage::Format::Bincode)
|
||||
.context("Failed to load processed region data")
|
||||
storage::read_file(&processed_path).context("Failed to load processed region data")
|
||||
})
|
||||
.await
|
||||
.cloned()
|
||||
|
@ -134,7 +133,7 @@ impl<'a> TileRenderer<'a> {
|
|||
/// Hashing the value as a single u32 is more efficient than hashing
|
||||
/// the tuple elements separately.
|
||||
fn biome_key((dx, dz, index): (i8, i8, u16)) -> u32 {
|
||||
(dx as u8 as u32) | (dz as u8 as u32) << 8 | (index as u32) << 16
|
||||
(dx as u8 as u32) | ((dz as u8 as u32) << 8) | ((index as u32) << 16)
|
||||
}
|
||||
|
||||
/// One quadrant of the kernel used to smooth biome edges
|
||||
|
@ -187,7 +186,7 @@ impl<'a> TileRenderer<'a> {
|
|||
|
||||
for ((region_x, region_z, index), w) in weights.into_values() {
|
||||
let region = region_group.get(region_x, region_z)?;
|
||||
let biome = region.biome_list.get_index(index.into())?;
|
||||
let biome = region.biome_list.get(usize::from(index))?;
|
||||
|
||||
total += w;
|
||||
color += w * block_color(block, Some(biome), depth.0 as f32);
|
||||
|
@ -304,7 +303,7 @@ impl<'a> TileRenderer<'a> {
|
|||
processed_timestamp,
|
||||
|file| {
|
||||
image
|
||||
.write_to(file, image::ImageFormat::Png)
|
||||
.write_to(file, self.config.tile_image_format())
|
||||
.context("Failed to save image")
|
||||
},
|
||||
)?;
|
||||
|
|
|
@ -10,28 +10,16 @@ use std::{
|
|||
};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use bincode::{Decode, Encode};
|
||||
|
||||
use super::fs;
|
||||
|
||||
/// Storage format
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Format {
|
||||
/// Encode as Bincode
|
||||
///
|
||||
/// Bincode is more efficient than JSON, but cannot handle many of
|
||||
/// serde's features like flatten, conditional skipping, ...
|
||||
Bincode,
|
||||
/// Encode as JSON
|
||||
Json,
|
||||
}
|
||||
/// Bincode configuration
|
||||
const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard();
|
||||
|
||||
/// Serializes data and writes it to a writer
|
||||
pub fn write<W: Write, T: Serialize>(writer: &mut W, value: &T, format: Format) -> Result<()> {
|
||||
let data = match format {
|
||||
Format::Bincode => bincode::serialize(value)?,
|
||||
Format::Json => serde_json::to_vec(value)?,
|
||||
};
|
||||
pub fn write<W: Write, T: Encode>(writer: &mut W, value: &T) -> Result<()> {
|
||||
let data = bincode::encode_to_vec(value, BINCODE_CONFIG)?;
|
||||
let len = u32::try_from(data.len())?;
|
||||
let compressed = zstd::bulk::compress(&data, 1)?;
|
||||
drop(data);
|
||||
|
@ -45,18 +33,21 @@ pub fn write<W: Write, T: Serialize>(writer: &mut W, value: &T, format: Format)
|
|||
/// Serializes data and stores it in a file
|
||||
///
|
||||
/// A timestamp is stored in an assiciated metadata file.
|
||||
pub fn write_file<T: Serialize>(
|
||||
pub fn write_file<T: Encode>(
|
||||
path: &Path,
|
||||
value: &T,
|
||||
format: Format,
|
||||
version: fs::FileMetaVersion,
|
||||
timestamp: SystemTime,
|
||||
) -> Result<()> {
|
||||
fs::create_with_timestamp(path, version, timestamp, |file| write(file, value, format))
|
||||
fs::create_with_timestamp(path, version, timestamp, |file| write(file, value))
|
||||
}
|
||||
|
||||
/// Reads data from a reader and deserializes it
|
||||
pub fn read<R: Read, T: DeserializeOwned>(reader: &mut R, format: Format) -> Result<T> {
|
||||
pub fn read<R, T>(reader: &mut R) -> Result<T>
|
||||
where
|
||||
R: Read,
|
||||
T: Decode<()>,
|
||||
{
|
||||
let mut len_buf = [0u8; 4];
|
||||
reader.read_exact(&mut len_buf)?;
|
||||
let len = usize::try_from(u32::from_be_bytes(len_buf))?;
|
||||
|
@ -66,18 +57,17 @@ pub fn read<R: Read, T: DeserializeOwned>(reader: &mut R, format: Format) -> Res
|
|||
let data = zstd::bulk::decompress(&compressed, len)?;
|
||||
drop(compressed);
|
||||
|
||||
let value = match format {
|
||||
Format::Bincode => bincode::deserialize(&data)?,
|
||||
Format::Json => serde_json::from_slice(&data)?,
|
||||
};
|
||||
Ok(value)
|
||||
Ok(bincode::decode_from_slice(&data, BINCODE_CONFIG)?.0)
|
||||
}
|
||||
|
||||
/// Reads data from a file and deserializes it
|
||||
pub fn read_file<T: DeserializeOwned>(path: &Path, format: Format) -> Result<T> {
|
||||
pub fn read_file<T>(path: &Path) -> Result<T>
|
||||
where
|
||||
T: Decode<()>,
|
||||
{
|
||||
(|| -> Result<T> {
|
||||
let mut file = File::open(path)?;
|
||||
read(&mut file, format)
|
||||
read(&mut file)
|
||||
})()
|
||||
.with_context(|| format!("Failed to read file {}", path.display()))
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#![warn(missing_docs)]
|
||||
#![warn(clippy::missing_docs_in_private_items)]
|
||||
|
||||
#[cfg(feature = "jemalloc-auto")]
|
||||
extern crate minedmap_default_alloc;
|
||||
|
||||
mod core;
|
||||
mod io;
|
||||
mod util;
|
||||
|
|
|
@ -39,7 +39,9 @@ pub fn to_flat_coord<const AXIS: u8>(
|
|||
chunk: ChunkCoord<AXIS>,
|
||||
block: BlockCoord<AXIS>,
|
||||
) -> i32 {
|
||||
(region as i32) << (BLOCK_BITS + CHUNK_BITS) | ((chunk.0 as i32) << BLOCK_BITS | block.0 as i32)
|
||||
((region as i32) << (BLOCK_BITS + CHUNK_BITS))
|
||||
| ((chunk.0 as i32) << BLOCK_BITS)
|
||||
| (block.0 as i32)
|
||||
}
|
||||
|
||||
/// Splits a flat (linear) coordinate into region, chunk and block numbers
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
//! Processing of block entity data
|
||||
|
||||
use bincode::{Decode, Encode};
|
||||
use minedmap_resource::{BlockFlag, BlockType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{
|
||||
de,
|
||||
|
@ -9,7 +10,7 @@ use super::{
|
|||
};
|
||||
|
||||
/// Kind of sign block
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SignKind {
|
||||
/// Standing sign
|
||||
|
@ -23,7 +24,7 @@ pub enum SignKind {
|
|||
}
|
||||
|
||||
/// Processed sign data
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Serialize)]
|
||||
pub struct Sign {
|
||||
/// The kind of the sign
|
||||
pub kind: SignKind,
|
||||
|
@ -40,10 +41,15 @@ pub struct Sign {
|
|||
|
||||
impl Sign {
|
||||
/// Processes a [de::BlockEntitySign] into a [Sign]
|
||||
fn new(sign: &de::BlockEntitySign, kind: SignKind, material: Option<String>) -> Sign {
|
||||
fn new(
|
||||
sign: &de::BlockEntitySign,
|
||||
kind: SignKind,
|
||||
material: Option<String>,
|
||||
data_version: u32,
|
||||
) -> Sign {
|
||||
let (front_text, back_text) = sign.text();
|
||||
let front_text = front_text.decode();
|
||||
let back_text = back_text.decode();
|
||||
let front_text = front_text.decode(data_version);
|
||||
let back_text = back_text.decode(data_version);
|
||||
Sign {
|
||||
kind,
|
||||
material,
|
||||
|
@ -54,7 +60,7 @@ impl Sign {
|
|||
}
|
||||
|
||||
/// Data for different kinds of [BlockEntity]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Serialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum BlockEntityData {
|
||||
/// A sign block
|
||||
|
@ -62,7 +68,7 @@ pub enum BlockEntityData {
|
|||
}
|
||||
|
||||
/// A processed block entity
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Serialize)]
|
||||
pub struct BlockEntity {
|
||||
/// Global X coordinate
|
||||
pub x: i32,
|
||||
|
@ -77,7 +83,11 @@ pub struct BlockEntity {
|
|||
|
||||
impl BlockEntity {
|
||||
/// Processes a [de::BlockEntity] into a [BlockEntity]
|
||||
pub fn new(entity: &de::BlockEntity, block_type: Option<&BlockType>) -> Option<Self> {
|
||||
pub fn new(
|
||||
entity: &de::BlockEntity,
|
||||
block_type: Option<&BlockType>,
|
||||
data_version: u32,
|
||||
) -> Option<Self> {
|
||||
let wall_sign = block_type
|
||||
.map(|block_type| block_type.block_color.is(BlockFlag::WallSign))
|
||||
.unwrap_or_default();
|
||||
|
@ -91,7 +101,7 @@ impl BlockEntity {
|
|||
let material = block_type
|
||||
.as_ref()
|
||||
.and_then(|block_type| block_type.sign_material.as_ref());
|
||||
let data = BlockEntityData::Sign(Sign::new(sign, kind, material.cloned()));
|
||||
let data = BlockEntityData::Sign(Sign::new(sign, kind, material.cloned(), data_version));
|
||||
|
||||
Some(BlockEntity {
|
||||
x: entity.x,
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
//! over different data versions as much as possible.
|
||||
|
||||
use std::{
|
||||
collections::{btree_map, BTreeMap},
|
||||
collections::{BTreeMap, btree_map},
|
||||
iter::{self, FusedIterator},
|
||||
};
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::{Context, Result, bail};
|
||||
|
||||
use super::{block_entity::BlockEntity, de, section::*};
|
||||
use crate::{
|
||||
|
@ -58,6 +58,8 @@ pub struct Chunk<'a> {
|
|||
inner: ChunkInner<'a>,
|
||||
/// Unprocessed block entities
|
||||
block_entities: &'a Vec<de::BlockEntity>,
|
||||
/// Chunk data version
|
||||
data_version: u32,
|
||||
}
|
||||
|
||||
impl<'a> Chunk<'a> {
|
||||
|
@ -87,6 +89,7 @@ impl<'a> Chunk<'a> {
|
|||
Chunk {
|
||||
inner,
|
||||
block_entities,
|
||||
data_version,
|
||||
},
|
||||
has_unknown,
|
||||
))
|
||||
|
@ -292,7 +295,11 @@ impl<'a> Chunk<'a> {
|
|||
.iter()
|
||||
.map(|block_entity| {
|
||||
let block_type = self.block_type_at_block_entity(block_entity)?;
|
||||
Ok(BlockEntity::new(block_entity, block_type))
|
||||
Ok(BlockEntity::new(
|
||||
block_entity,
|
||||
block_type,
|
||||
self.data_version,
|
||||
))
|
||||
})
|
||||
.collect::<Result<_>>()?;
|
||||
Ok(entities.into_iter().flatten().collect())
|
||||
|
@ -412,17 +419,17 @@ impl<'a> Iterator for SectionIter<'a> {
|
|||
}
|
||||
|
||||
fn last(mut self) -> Option<Self::Item> {
|
||||
self.with_iter(|iter| iter.last())
|
||||
self.next_back()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DoubleEndedIterator for SectionIter<'a> {
|
||||
impl DoubleEndedIterator for SectionIter<'_> {
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
self.with_iter(|iter| iter.next_back())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ExactSizeIterator for SectionIter<'a> {
|
||||
impl ExactSizeIterator for SectionIter<'_> {
|
||||
fn len(&self) -> usize {
|
||||
match &self.inner {
|
||||
SectionIterInner::V1_18 { iter } => iter.len(),
|
||||
|
@ -433,4 +440,4 @@ impl<'a> ExactSizeIterator for SectionIter<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> FusedIterator for SectionIter<'a> {}
|
||||
impl FusedIterator for SectionIter<'_> {}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::json_text::JSONText;
|
||||
use super::text_value::TextValue;
|
||||
|
||||
/// Element of the `palette` list of 1.18+ [block states](BlockStatesV1_18)
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -110,7 +110,7 @@ pub enum BiomesV0 {
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub struct BlockEntitySignV1_20Text {
|
||||
/// Lines of sign text
|
||||
pub messages: Vec<JSONText>,
|
||||
pub messages: Vec<TextValue>,
|
||||
/// Default text color
|
||||
pub color: Option<String>,
|
||||
}
|
||||
|
@ -125,13 +125,13 @@ pub enum BlockEntitySign {
|
|||
#[serde(rename_all = "PascalCase")]
|
||||
V0 {
|
||||
/// Line 1 of the sign text
|
||||
text1: JSONText,
|
||||
text1: TextValue,
|
||||
/// Line 2 of the sign text
|
||||
text2: JSONText,
|
||||
text2: TextValue,
|
||||
/// Line 3 of the sign text
|
||||
text3: JSONText,
|
||||
text3: TextValue,
|
||||
/// Line 4 of the sign text
|
||||
text4: JSONText,
|
||||
text4: TextValue,
|
||||
/// Default text color
|
||||
color: Option<String>,
|
||||
},
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
use std::num::NonZeroU16;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use bincode::{Decode, Encode};
|
||||
use indexmap::IndexSet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::chunk::{Chunk, SectionIterItem};
|
||||
use crate::{
|
||||
|
@ -13,7 +13,7 @@ use crate::{
|
|||
};
|
||||
|
||||
/// Height (Y coordinate) of a block
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)]
|
||||
pub struct BlockHeight(pub i32);
|
||||
|
||||
impl BlockHeight {
|
||||
|
@ -58,7 +58,7 @@ struct LayerEntry<'a> {
|
|||
depth: &'a mut Option<BlockHeight>,
|
||||
}
|
||||
|
||||
impl<'a> LayerEntry<'a> {
|
||||
impl LayerEntry<'_> {
|
||||
/// Returns true if the entry has not been filled yet (no opaque block has been encountered)
|
||||
///
|
||||
/// The depth value is filled separately when a non-water block is encountered after the block type
|
||||
|
@ -97,14 +97,14 @@ impl<'a> LayerEntry<'a> {
|
|||
|
||||
if self.is_empty() {
|
||||
*self.block = Some(block_type.block_color);
|
||||
if let Some(biome) = section.biomes.biome_at(section.y, coords)? {
|
||||
let (biome_index, _) = biome_list.insert_full(*biome);
|
||||
*self.biome = NonZeroU16::new(
|
||||
(biome_index + 1)
|
||||
.try_into()
|
||||
.expect("biome index not in range"),
|
||||
);
|
||||
}
|
||||
|
||||
let biome = section.biomes.biome_at(section.y, coords)?;
|
||||
let (biome_index, _) = biome_list.insert_full(*biome);
|
||||
*self.biome = NonZeroU16::new(
|
||||
(biome_index + 1)
|
||||
.try_into()
|
||||
.expect("biome index not in range"),
|
||||
);
|
||||
}
|
||||
|
||||
if block_type.block_color.is(BlockFlag::Water) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
pub mod block_entity;
|
||||
pub mod chunk;
|
||||
pub mod de;
|
||||
pub mod json_text;
|
||||
pub mod layer;
|
||||
pub mod section;
|
||||
pub mod sign;
|
||||
pub mod text_value;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use num_integer::div_rem;
|
||||
use tracing::debug;
|
||||
|
||||
|
@ -81,7 +81,7 @@ impl<'a> SectionV1_13<'a> {
|
|||
if let Some(block_states) = block_states {
|
||||
let expected_length = if aligned_blocks {
|
||||
let blocks_per_word = 64 / bits as usize;
|
||||
(4096 + blocks_per_word - 1) / blocks_per_word
|
||||
4096usize.div_ceil(blocks_per_word)
|
||||
} else {
|
||||
64 * bits as usize
|
||||
};
|
||||
|
@ -145,7 +145,7 @@ impl<'a> SectionV1_13<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Section for SectionV1_13<'a> {
|
||||
impl Section for SectionV1_13<'_> {
|
||||
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<&BlockType>> {
|
||||
let index = self.palette_index_at(coords);
|
||||
Ok(*self
|
||||
|
@ -188,7 +188,7 @@ impl<'a> SectionV0<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Section for SectionV0<'a> {
|
||||
impl Section for SectionV0<'_> {
|
||||
fn block_at(&self, coords: SectionBlockCoords) -> Result<Option<&BlockType>> {
|
||||
let offset = coords.offset();
|
||||
let block = self.blocks[offset] as u8;
|
||||
|
@ -208,7 +208,7 @@ impl<'a> Section for SectionV0<'a> {
|
|||
/// Trait for common functions of [BiomesV1_18] and [BiomesV0]
|
||||
pub trait Biomes: Debug {
|
||||
/// Returns the [Biome] at a coordinate tuple inside the chunk
|
||||
fn biome_at(&self, section: SectionY, coords: SectionBlockCoords) -> Result<Option<&Biome>>;
|
||||
fn biome_at(&self, section: SectionY, coords: SectionBlockCoords) -> Result<&Biome>;
|
||||
}
|
||||
|
||||
/// Minecraft v1.18+ section biome data
|
||||
|
@ -226,7 +226,7 @@ pub struct BiomesV1_18<'a> {
|
|||
/// to whole i64 values.
|
||||
biomes: Option<&'a [i64]>,
|
||||
/// Biome palette indexed by entries encoded in *biomes*
|
||||
palette: Vec<Option<&'a Biome>>,
|
||||
palette: Vec<&'a Biome>,
|
||||
/// Number of bits used for each entry in *biomes*
|
||||
bits: u8,
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ impl<'a> BiomesV1_18<'a> {
|
|||
|
||||
if let Some(biomes) = biomes {
|
||||
let biomes_per_word = 64 / bits as usize;
|
||||
let expected_length = (64 + biomes_per_word - 1) / biomes_per_word;
|
||||
let expected_length = 64usize.div_ceil(biomes_per_word);
|
||||
if biomes.len() != expected_length {
|
||||
bail!("Invalid section biome data");
|
||||
}
|
||||
|
@ -253,12 +253,11 @@ impl<'a> BiomesV1_18<'a> {
|
|||
let palette_types = palette
|
||||
.iter()
|
||||
.map(|entry| {
|
||||
let biome_type = biome_types.get(entry);
|
||||
if biome_type.is_none() {
|
||||
biome_types.get(entry).unwrap_or_else(|| {
|
||||
debug!("Unknown biome type: {}", entry);
|
||||
has_unknown = true;
|
||||
}
|
||||
biome_type
|
||||
biome_types.get_fallback()
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -294,8 +293,8 @@ impl<'a> BiomesV1_18<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Biomes for BiomesV1_18<'a> {
|
||||
fn biome_at(&self, _section: SectionY, coords: SectionBlockCoords) -> Result<Option<&Biome>> {
|
||||
impl Biomes for BiomesV1_18<'_> {
|
||||
fn biome_at(&self, _section: SectionY, coords: SectionBlockCoords) -> Result<&Biome> {
|
||||
let index = self.palette_index_at(coords);
|
||||
Ok(*self
|
||||
.palette
|
||||
|
@ -349,8 +348,8 @@ impl<'a> BiomesV0<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Biomes for BiomesV0<'a> {
|
||||
fn biome_at(&self, section: SectionY, coords: SectionBlockCoords) -> Result<Option<&Biome>> {
|
||||
impl Biomes for BiomesV0<'_> {
|
||||
fn biome_at(&self, section: SectionY, coords: SectionBlockCoords) -> Result<&Biome> {
|
||||
let id = match self.data {
|
||||
BiomesV0Data::IntArrayV15(data) => {
|
||||
let LayerBlockCoords { x, z } = coords.xz;
|
||||
|
@ -370,7 +369,10 @@ impl<'a> Biomes for BiomesV0<'a> {
|
|||
}
|
||||
BiomesV0Data::ByteArray(data) => data[coords.xz.offset()] as u8,
|
||||
};
|
||||
Ok(self.biome_types.get_legacy(id))
|
||||
Ok(self
|
||||
.biome_types
|
||||
.get_legacy(id)
|
||||
.unwrap_or(self.biome_types.get_fallback()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,10 +400,6 @@ impl<'a> BlockLight<'a> {
|
|||
let (offset, nibble) = div_rem(coords.offset(), 2);
|
||||
let byte = block_light[offset] as u8;
|
||||
|
||||
if nibble == 1 {
|
||||
byte >> 4
|
||||
} else {
|
||||
byte & 0xf
|
||||
}
|
||||
if nibble == 1 { byte >> 4 } else { byte & 0xf }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
//! Processing of sign text
|
||||
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
use std::fmt::Display;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use bincode::{Decode, Encode};
|
||||
use minedmap_resource::Color;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::{
|
||||
de,
|
||||
json_text::{FormattedText, FormattedTextList, JSONText},
|
||||
text_value::{FormattedText, FormattedTextList, TextValue},
|
||||
};
|
||||
|
||||
/// Version-independent reference to (front or back) sign text
|
||||
|
@ -16,17 +18,41 @@ pub struct RawSignText<'a> {
|
|||
///
|
||||
/// A regular sign always has 4 lines of text. The back of pre-1.20
|
||||
/// signs is represented as a [SignText] without any `messages`.
|
||||
pub messages: Vec<&'a JSONText>,
|
||||
pub messages: Vec<&'a TextValue>,
|
||||
/// Sign color
|
||||
///
|
||||
/// Defaults to "black".
|
||||
pub color: Option<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> RawSignText<'a> {
|
||||
/// The color to use for signs without a color attribute ("black")
|
||||
const DEFAULT_COLOR: Color = Color([0, 0, 0]);
|
||||
|
||||
/// Map of text colors associated with dyes (except for black)
|
||||
static DYE_COLORS: phf::Map<&'static str, Color> = phf::phf_map! {
|
||||
"white" => Color([255, 255, 255]),
|
||||
"orange" => Color([255, 104, 31]),
|
||||
"magenta" => Color([255, 0, 255]),
|
||||
"light_blue" => Color([154, 192, 205]),
|
||||
"yellow" => Color([255, 255, 0]),
|
||||
"lime" => Color([191, 255, 0]),
|
||||
"pink" => Color([255, 105, 180]),
|
||||
"gray" => Color([128, 128, 128]),
|
||||
"light_gray" => Color([211, 211, 211]),
|
||||
"cyan" => Color([0, 255, 255]),
|
||||
"purple" => Color([160, 32, 240]),
|
||||
"blue" => Color([0, 0, 255]),
|
||||
"brown" => Color([139, 69, 19]),
|
||||
"green" => Color([0, 255, 0]),
|
||||
"red" => Color([255, 0, 0]),
|
||||
};
|
||||
|
||||
impl RawSignText<'_> {
|
||||
/// Decodes the [RawSignText] into a [SignText]
|
||||
pub fn decode(&self) -> SignText {
|
||||
let color = self.color.map(|c| Arc::new(c.to_owned()));
|
||||
pub fn decode(&self, data_version: u32) -> SignText {
|
||||
let color = self
|
||||
.color
|
||||
.map(|c| DYE_COLORS.get(c).copied().unwrap_or(DEFAULT_COLOR));
|
||||
let parent = FormattedText {
|
||||
color,
|
||||
..Default::default()
|
||||
|
@ -34,7 +60,7 @@ impl<'a> RawSignText<'a> {
|
|||
SignText(
|
||||
self.messages
|
||||
.iter()
|
||||
.map(|message| message.deserialize().linearize(&parent))
|
||||
.map(|message| message.deserialize(data_version).linearize(&parent))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
@ -79,7 +105,7 @@ impl BlockEntitySignExt for de::BlockEntitySign {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, Default, Serialize, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
|
||||
/// Deserialized and linearized sign text
|
||||
pub struct SignText(pub Vec<FormattedTextList>);
|
||||
|
||||
|
|
|
@ -1,24 +1,28 @@
|
|||
//! Newtype and helper methods for handling Minecraft Raw JSON Text
|
||||
//! Newtype and helper methods for handling Minecraft text values
|
||||
|
||||
use std::{collections::VecDeque, fmt::Display, sync::Arc};
|
||||
use std::{collections::VecDeque, fmt::Display};
|
||||
|
||||
use bincode::{Decode, Encode};
|
||||
use minedmap_resource::Color;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A span of formatted text
|
||||
///
|
||||
/// A [JSONText] consists of a tree of [FormattedText] nodes (canonically
|
||||
/// A [TextValue] consists of a tree of [FormattedText] nodes (canonically
|
||||
/// represented as a [FormattedTextTree], but other kinds are possible with
|
||||
/// is handled by [DeserializedText].
|
||||
///
|
||||
/// Formatting that is not set in a node is inherited from the parent.
|
||||
#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(
|
||||
Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Encode, Decode,
|
||||
)]
|
||||
pub struct FormattedText {
|
||||
#[serde(default)]
|
||||
/// Text content
|
||||
pub text: String,
|
||||
/// Text color
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub color: Option<Arc<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none", with = "text_color")]
|
||||
pub color: Option<Color>,
|
||||
/// Bold formatting
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub bold: Option<bool>,
|
||||
|
@ -41,7 +45,7 @@ impl FormattedText {
|
|||
pub fn inherit(self, parent: &Self) -> Self {
|
||||
FormattedText {
|
||||
text: self.text,
|
||||
color: self.color.or_else(|| parent.color.clone()),
|
||||
color: self.color.or(parent.color),
|
||||
bold: self.bold.or(parent.bold),
|
||||
italic: self.italic.or(parent.italic),
|
||||
underlined: self.underlined.or(parent.underlined),
|
||||
|
@ -83,7 +87,7 @@ impl From<String> for FormattedTextTree {
|
|||
}
|
||||
|
||||
/// List of [FormattedText]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Encode, Decode)]
|
||||
pub struct FormattedTextList(pub Vec<FormattedText>);
|
||||
|
||||
impl FormattedTextList {
|
||||
|
@ -103,9 +107,9 @@ impl Display for FormattedTextList {
|
|||
}
|
||||
}
|
||||
|
||||
/// Raw deserialized [JSONText]
|
||||
/// Raw deserialized [TextValue]
|
||||
///
|
||||
/// A [JSONText] can contain various different JSON types.
|
||||
/// A [TextValue] can contain various different types serialized as JSON or NBT.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum DeserializedText {
|
||||
|
@ -165,13 +169,106 @@ impl Default for DeserializedText {
|
|||
}
|
||||
}
|
||||
|
||||
/// Minecraft Raw JSON Text
|
||||
/// Minecraft raw text value
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct JSONText(pub String);
|
||||
pub struct TextValue(pub fastnbt::Value);
|
||||
|
||||
impl JSONText {
|
||||
/// Deserializes a [JSONText] into a [DeserializedText]
|
||||
pub fn deserialize(&self) -> DeserializedText {
|
||||
serde_json::from_str(&self.0).unwrap_or_default()
|
||||
impl TextValue {
|
||||
/// Deserializes a [TextValue] into a [DeserializedText]
|
||||
pub fn deserialize(&self, data_version: u32) -> DeserializedText {
|
||||
// TODO: Improve error handling
|
||||
//
|
||||
// Unfortunately, there are a number of weird ways an empty sign coould
|
||||
// be encoded (for example a compound with an "" key), so for now we
|
||||
// simply interpret undecodable data as empty.
|
||||
if data_version < 4290 {
|
||||
let fastnbt::Value::String(json) = &self.0 else {
|
||||
return DeserializedText::default();
|
||||
};
|
||||
|
||||
serde_json::from_str(json).unwrap_or_default()
|
||||
} else {
|
||||
fastnbt::from_value(&self.0).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod text_color {
|
||||
//! Helpers for serializing and deserializing [FormattedText](super::FormattedText) colors
|
||||
|
||||
use minedmap_resource::Color;
|
||||
use serde::{
|
||||
Deserializer, Serializer,
|
||||
de::{self, Visitor},
|
||||
ser::Error as _,
|
||||
};
|
||||
|
||||
/// Named text colors
|
||||
static COLORS: phf::Map<&'static str, Color> = phf::phf_map! {
|
||||
"black" => Color([0x00, 0x00, 0x00]),
|
||||
"dark_blue" => Color([0x00, 0x00, 0xAA]),
|
||||
"dark_green" => Color([0x00, 0xAA, 0x00]),
|
||||
"dark_aqua" => Color([0x00, 0xAA, 0xAA]),
|
||||
"dark_red" => Color([0xAA, 0x00, 0x00]),
|
||||
"dark_purple" => Color([0xAA, 0x00, 0xAA]),
|
||||
"gold" => Color([0xFF, 0xAA, 0x00]),
|
||||
"gray" => Color([0xAA, 0xAA, 0xAA]),
|
||||
"dark_gray" => Color([0x55, 0x55, 0x55]),
|
||||
"blue" => Color([0x55, 0x55, 0xFF]),
|
||||
"green" => Color([0x55, 0xFF, 0x55]),
|
||||
"aqua" => Color([0x55, 0xFF, 0xFF]),
|
||||
"red" => Color([0xFF, 0x55, 0x55]),
|
||||
"light_purple" => Color([0xFF, 0x55, 0xFF]),
|
||||
"yellow" => Color([0xFF, 0xFF, 0x55]),
|
||||
"white" => Color([0xFF, 0xFF, 0xFF]),
|
||||
};
|
||||
|
||||
/// serde serialize function for [FormattedText::color](super::FormattedText::color)
|
||||
pub fn serialize<S>(color: &Option<Color>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let &Some(color) = color else {
|
||||
return Err(S::Error::custom("serialize called for None sign color"));
|
||||
};
|
||||
|
||||
let text = format!("#{:02x}{:02x}{:02x}", color.0[0], color.0[1], color.0[2]);
|
||||
serializer.serialize_str(&text)
|
||||
}
|
||||
|
||||
/// serde [Visitor] for use by [deserialize]
|
||||
struct ColorVisitor;
|
||||
|
||||
impl Visitor<'_> for ColorVisitor {
|
||||
type Value = Option<Color>;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
formatter.write_str("a string representing a color")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, color: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if let Some(hex) = color.strip_prefix("#") {
|
||||
if let Ok(value) = u32::from_str_radix(hex, 16) {
|
||||
return Ok(Some(Color([
|
||||
(value >> 16) as u8,
|
||||
(value >> 8) as u8,
|
||||
value as u8,
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(COLORS.get(color).copied())
|
||||
}
|
||||
}
|
||||
|
||||
/// serde deserialize function for [FormattedText::color](super::FormattedText::color)
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Color>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_str(ColorVisitor)
|
||||
}
|
||||
}
|
1
viewer/.dockerignore
Normal file
|
@ -0,0 +1 @@
|
|||
/data
|
3
viewer/Dockerfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
FROM docker.io/library/nginx:alpine-slim
|
||||
COPY . /usr/share/nginx/html
|
||||
# datadir should be mounted to: /usr/share/nginx/html/data
|
|
@ -73,7 +73,7 @@ function signIcon(material, kind) {
|
|||
}
|
||||
|
||||
const MinedMapLayer = L.TileLayer.extend({
|
||||
initialize: function (mipmaps, layer) {
|
||||
initialize: function (mipmaps, layer, tile_extension) {
|
||||
L.TileLayer.prototype.initialize.call(this, '', {
|
||||
detectRetina: true,
|
||||
tileSize: 512,
|
||||
|
@ -88,6 +88,7 @@ const MinedMapLayer = L.TileLayer.extend({
|
|||
|
||||
this.mipmaps = mipmaps;
|
||||
this.layer = layer;
|
||||
this.ext = tile_extension;
|
||||
},
|
||||
|
||||
createTile: function (coords, done) {
|
||||
|
@ -112,7 +113,7 @@ const MinedMapLayer = L.TileLayer.extend({
|
|||
return L.Util.emptyImageUrl;
|
||||
|
||||
|
||||
return 'data/'+this.layer+'/'+z+'/r.'+coords.x+'.'+coords.y+'.png';
|
||||
return `data/${this.layer}/${z}/r.${coords.x}.${coords.y}.${this.ext}`;
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -153,25 +154,6 @@ const parseHash = function () {
|
|||
return args;
|
||||
}
|
||||
|
||||
const colors = {
|
||||
black: '#000000',
|
||||
dark_blue: '#0000AA',
|
||||
dark_green: '#00AA00',
|
||||
dark_aqua: '#00AAAA',
|
||||
dark_red: '#AA0000',
|
||||
dark_purple: '#AA00AA',
|
||||
gold: '#FFAA00',
|
||||
gray: '#AAAAAA',
|
||||
dark_gray: '#555555',
|
||||
blue: '#5555FF',
|
||||
green: '#55FF55',
|
||||
aqua: '#55FFFF',
|
||||
red: '#FF5555',
|
||||
light_purple: '#FF55FF',
|
||||
yellow: '#FFFF55',
|
||||
white: '#FFFFFF',
|
||||
};
|
||||
|
||||
function formatSignLine(line) {
|
||||
const el = document.createElement('span');
|
||||
el.style.whiteSpace = 'pre';
|
||||
|
@ -180,7 +162,9 @@ function formatSignLine(line) {
|
|||
const child = document.createElement('span');
|
||||
child.textContent = span.text;
|
||||
|
||||
const color = colors[span.color ?? 'black'] || colors['black'];
|
||||
let color = span.color ?? '';
|
||||
if (color[0] !== '#')
|
||||
color = '#000000';
|
||||
|
||||
if (span.bold)
|
||||
child.style.fontWeight = 'bold';
|
||||
|
@ -349,6 +333,7 @@ window.createMap = function () {
|
|||
const res = await response.json();
|
||||
const {mipmaps, spawn} = res;
|
||||
const features = res.features || {};
|
||||
const tile_extension = res.tile_extension || 'png';
|
||||
|
||||
const updateParams = function () {
|
||||
const args = parseHash();
|
||||
|
@ -386,10 +371,10 @@ window.createMap = function () {
|
|||
|
||||
const overlayMaps = {};
|
||||
|
||||
const mapLayer = new MinedMapLayer(mipmaps, 'map');
|
||||
const mapLayer = new MinedMapLayer(mipmaps, 'map', tile_extension);
|
||||
mapLayer.addTo(map);
|
||||
|
||||
const lightLayer = new MinedMapLayer(mipmaps, 'light');
|
||||
const lightLayer = new MinedMapLayer(mipmaps, 'light', tile_extension);
|
||||
overlayMaps['Illumination'] = lightLayer;
|
||||
if (params.light)
|
||||
map.addLayer(lightLayer);
|
||||
|
|
BIN
viewer/images/bg/pale_oak_hanging_sign.png
Normal file
After Width: | Height: | Size: 318 B |
BIN
viewer/images/bg/pale_oak_hanging_wall_sign.png
Normal file
After Width: | Height: | Size: 222 B |
BIN
viewer/images/bg/pale_oak_sign.png
Normal file
After Width: | Height: | Size: 419 B |
BIN
viewer/images/bg/pale_oak_wall_sign.png
Normal file
After Width: | Height: | Size: 317 B |
BIN
viewer/images/icon/pale_oak_hanging_sign.png
Normal file
After Width: | Height: | Size: 258 B |
BIN
viewer/images/icon/pale_oak_hanging_wall_sign.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
viewer/images/icon/pale_oak_sign.png
Normal file
After Width: | Height: | Size: 281 B |
BIN
viewer/images/icon/pale_oak_wall_sign.png
Normal file
After Width: | Height: | Size: 223 B |