Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.

Support for Biomes & Everything 1.18 #34

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0f6859e
add Enum for biome definitions
0xTiger Jan 19, 2022
ad4a88e
add Chunk.get_biome method
0xTiger Jan 22, 2022
3da587f
add set_biome methods
0xTiger Jan 22, 2022
b53bfb4
add fill_biome function
0xTiger Jan 22, 2022
1cf8f77
update README & setup.py version
0xTiger Jan 22, 2022
4d2e7f3
Update requirements.txt
bee-boii Mar 16, 2022
3740065
Added support for 1.18 within get_block only
bee-boii Mar 17, 2022
c6fa64f
Further updated for 1.18
bee-boii Mar 17, 2022
982a434
Changed version number from 0.10.0 to 0.10.1
bee-boii Mar 17, 2022
71ecd6f
Made things more flexible. Catches air blocks now.
bee-boii Apr 2, 2022
426d79e
Merge pull request #2 from bee-boii/master
0xTiger Jun 6, 2022
acf498e
small refactor
0xTiger Jun 6, 2022
bd67441
fix: make stream_blocks and stream_chunk 1.19 compatible
0xTiger Jun 7, 2022
220c283
refactor: add _.._from_section fns
0xTiger Jun 7, 2022
cda7c84
feat: add support for >1.17.1 tile entities
0xTiger Jun 7, 2022
87fa699
refactor: use range and stream_chunk in correct order
0xTiger Jun 7, 2022
8103662
refactor: simplify Block.from_palette
0xTiger Jun 7, 2022
cd329a2
refactor: greedily add 2**64 to states
0xTiger Jun 7, 2022
ddbfff6
feat: add 1.18 biome support
0xTiger Jun 16, 2022
e77b717
chore: update README & version
0xTiger Jun 16, 2022
a10bc40
fix: set_biome works with new Biome class
0xTiger Jun 16, 2022
1c6b750
fix: set_biome works with new Biome class
0xTiger Jun 16, 2022
1e3d329
Merge branch 'master' of https://github.com/0xTiger/anvil-parser
0xTiger Jun 16, 2022
f94f0e6
fix: solve failing tests with _get_legacy_biome_id
0xTiger Jun 17, 2022
27544bb
fix: include missing legacy_biomes.json
0xTiger Jun 18, 2022
63740dc
change version constant for top level tile_entity nbt tag from 1.17.1…
kiwirm Aug 11, 2023
670ba69
Merge pull request #3 from ryan-mooore/tile_entity_1.18
0xTiger Sep 22, 2023
c7cb5dd
Update Minecraft Wiki links to new domain after fork
misode Sep 26, 2023
123a788
Update gamepedia links
misode Sep 26, 2023
72ecab8
Update requirements.txt
Ableytner Nov 10, 2023
d52e22a
Update requirements.txt
Feb 21, 2024
4b5730e
fix older mc versions
Feb 21, 2024
3729c7c
add venv to .gitignore
Feb 23, 2024
ee4e069
Merge pull request #4 from misode/patch-1
0xTiger Feb 24, 2024
0ea1454
Merge pull request #5 from Ableytner/bump-frozendict-version
0xTiger Feb 24, 2024
844b395
Merge remote-tracking branch 'upstream/master' into fix-1.7.10
Mar 4, 2024
a68dbfd
update fandom links
Mar 4, 2024
0405089
refactor: move version constants to separate file
Nyveon Mar 5, 2024
d03e661
feat: 1.18+ region saving support
Nyveon Mar 5, 2024
e91938b
Merge pull request #7 from Nyveon/master
0xTiger Mar 10, 2024
c8e5526
chore: bump patch version due to writing region fixed by Nyveon
0xTiger Mar 10, 2024
2533ff1
refactor: use -1 as _VERSION_PRE_15w32a and remove None checks from v…
0xTiger Mar 10, 2024
925a18d
Merge branch 'Ableytner-fix-1.7.10'
0xTiger Mar 10, 2024
42df175
feat: publish to PyPI
0xTiger Jul 21, 2024
94575d7
chore: rename everywhere to anvil-parser2 & update github urls
0xTiger Jul 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi
- name: Test with pytest
run: |
pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ build/
.vscode/
docs/_build/
examples/test_112.py
venv
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ python:
version: 3.7
install:
- requirements: docs/requirements.txt
- requirements: requirements.txt
- requirements: tests/requirements.txt
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include anvil/legacy_blocks.json
include anvil/legacy_blocks.json
include anvil/legacy_biomes.json
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# anvil-parser

[![CodeFactor](https://www.codefactor.io/repository/github/matcool/anvil-parser/badge/master)](https://www.codefactor.io/repository/github/matcool/anvil-parser/overview/master)
# anvil-parser2
[![Documentation Status](https://readthedocs.org/projects/anvil-parser/badge/?version=latest)](https://anvil-parser.readthedocs.io/en/latest/?badge=latest)
[![Tests](https://github.com/matcool/anvil-parser/actions/workflows/run-pytest.yml/badge.svg)](https://github.com/matcool/anvil-parser/actions/workflows/run-pytest.yml)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/anvil-parser)](https://pypi.org/project/anvil-parser/)
[![Tests](https://github.com/0xTiger/anvil-parser/actions/workflows/run-pytest.yml/badge.svg)](https://github.com/0xTiger/anvil-parser/actions/workflows/run-pytest.yml)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/anvil-parser)](https://pypi.org/project/anvil-parser2/)

Simple parser for the [Minecraft anvil file format](https://minecraft.gamepedia.com/Anvil_file_format)
A parser for the [Minecraft anvil file format](https://minecraft.wiki/w/Anvil_file_format). This package was forked from [matcool's anvil-parser](https://github.com/matcool/anvil-parser) in order to additionally support minecraft versions 1.18 and above.
# Installation
This project is available on [PyPI](https://pypi.org/project/anvil-parser/) and can be installed with pip
```
pip install anvil-parser
```
or directly from github
```
pip install git+https://github.com/matcool/anvil-parser.git
pip install anvil-parser2
```

# Usage
## Reading
```python
Expand Down Expand Up @@ -57,9 +51,10 @@ region.save('r.0.0.mca')
# Todo
*things to do before 1.0.0*
- [x] Proper documentation
- [ ] Biomes
- [x] Biomes
- [x] CI
- [ ] More tests
- [ ] Tests for 20w17a+ BlockStates format
# Note
Testing done in 1.14.4 and 1.15.2, should work fine for other versions.
Testing done in 1.14.4 - 1.19, should work fine for other versions.
Writing chunks and regions is broken from 1.16 onwards
1 change: 1 addition & 0 deletions anvil/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .chunk import Chunk
from .block import Block, OldBlock
from .biome import Biome
from .region import Region
from .empty_region import EmptyRegion
from .empty_chunk import EmptyChunk
Expand Down
75 changes: 75 additions & 0 deletions anvil/biome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from .legacy import LEGACY_BIOMES_ID_MAP

class Biome:
"""
Represents a minecraft biome.

Attributes
----------
namespace: :class:`str`
Namespace of the biome, most of the time this is ``minecraft``
id: :class:`str`
ID of the biome, for example: forest, warm_ocean, etc...
"""
__slots__ = ('namespace', 'id')

def __init__(self, namespace: str, biome_id: str=None):
"""
Parameters
----------
namespace
Namespace of the biome. If no biome_id is given, assume this is ``biome_id`` and set namespace to ``"minecraft"``
biome_id
ID of the biome
"""
if biome_id is None:
self.namespace = 'minecraft'
self.id = namespace
else:
self.namespace = namespace
self.id = biome_id

def name(self) -> str:
"""
Returns the biome in the ``minecraft:biome_id`` format
"""
return self.namespace + ':' + self.id

def __repr__(self):
return f'Biome({self.name()})'

def __eq__(self, other):
if not isinstance(other, Biome):
return False
return self.namespace == other.namespace and self.id == other.id

def __hash__(self):
return hash(self.name())

@classmethod
def from_name(cls, name: str):
"""
Creates a new Biome from the format: ``namespace:biome_id``

Parameters
----------
name
Biome in said format
"""
namespace, biome_id = name.split(':')
return cls(namespace, biome_id)

@classmethod
def from_numeric_id(cls, biome_id: int):
"""
Creates a new Biome from the numeric biome_id format

Parameters
----------
biome_id
Numeric ID of the biome
"""
if biome_id not in LEGACY_BIOMES_ID_MAP:
raise KeyError(f'Biome {biome_id} not found')
name = LEGACY_BIOMES_ID_MAP[biome_id]
return cls('minecraft', name)
9 changes: 4 additions & 5 deletions anvil/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def from_palette(cls, tag: nbt.TAG_Compound):
Raw tag from a section's palette
"""
name = tag['Name'].value
properties = tag.get('Properties')
if properties:
properties = dict(properties)
properties = dict(tag.get('Properties', dict()))
return cls.from_name(name, properties=properties)

@classmethod
Expand All @@ -96,14 +94,15 @@ def from_numeric_id(cls, block_id: int, data: int=0):
data
Numeric data, used to represent variants of the block
"""
# See https://minecraft.gamepedia.com/Java_Edition_data_value/Pre-flattening
# and https://minecraft.gamepedia.com/Java_Edition_data_value for current values
# See https://minecraft.wiki/w/Java_Edition_data_value/Pre-flattening
# and https://minecraft.wiki/w/Java_Edition_data_value for current values
key = f'{block_id}:{data}'
if key not in LEGACY_ID_MAP:
raise KeyError(f'Block {key} not found')
name, properties = LEGACY_ID_MAP[key]
return cls('minecraft', name, properties=properties)


class OldBlock:
"""
Represents a pre 1.13 minecraft block, with a numeric id.
Expand Down
Loading