Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@

print(mcd_pe.version)
print(mcd_pe.find_item_or_block('stone'))

# Query common data. E.g. to map the protocol version to a minecraft version
protocol_version = 754 # example protocol version
for version in minecraft_data.common().protocolVersions:
if version["version"] == protocol_version:
print(version["minecraftVersion"]) # 1.16.5
break
8 changes: 7 additions & 1 deletion minecraft_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys

from minecraft_data.tools import convert
from minecraft_data.tools import convert, commondata


class mod(sys.modules[__name__].__class__):
Expand All @@ -11,5 +11,11 @@ def __call__(self, version, edition = 'pc'):
)
return type(version, (object,), convert(_dir, version, edition))

def common(self, edition = 'pc'):
_dir = os.path.join(
os.path.dirname(__file__), "data/data/"
)
return type('common', (object,), commondata(_dir, edition))


sys.modules[__name__].__class__ = mod
11 changes: 11 additions & 0 deletions minecraft_data/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def find_item_or_block(find):
return ret


def commondata(_dir, edition = 'pc'):
ret = {}
common_path = os.path.join(_dir, edition, 'common')
for common_file in os.listdir(common_path):
key = common_file.split('.', 1)[0]
with open(os.path.join(common_path, common_file)) as f:
data = json.load(f)
ret.update({key: data})
return ret


def _grabdata(_dir, datapaths):
data = {}
for category, folder in datapaths.items():
Expand Down