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
28 changes: 12 additions & 16 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

blocks indexed by id

### blocksByName
### blocks_name

blocks indexed by name

### blocksArray
### blocks_list

unindexed blocks

Expand All @@ -20,11 +20,11 @@ unindexed blocks

items indexed by id

### itemsByName
### items_name

items indexed by name

### itemsArray
### items_list

unindexed items

Expand All @@ -34,7 +34,7 @@ unindexed items

biomes indexed by id

### biomesArray
### biomes_list

unindexed biomes

Expand All @@ -50,7 +50,7 @@ recipes indexed by id

instruments indexed by id

### instrumentsArray
### instruments_list

unindexed instruments

Expand All @@ -66,11 +66,11 @@ materials indexed by name

entities indexed by id

### entitiesByName
### entities_name

entities indexed by name

### entitiesArray
### entities_list

unindexed entities

Expand All @@ -86,20 +86,16 @@ the minecraft protocol

windows indexed by id

### windowsByName
### windows_name

windows indexed by name

### windowsArray
### windows_list

unindexed windows

## Functions

### findItemOrBlockById
### find_item_or_block

find a block or an item by its id

### findItemOrBlockByName

find a block or an item by its name
find a block or an item by its id or name
5 changes: 4 additions & 1 deletion doc/history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.0
* changed function names to follow pep8

## 0.2.0
* add windows
* update protocol schema
Expand All @@ -8,4 +11,4 @@

## 0.1.0
* provide : id-indexed data, name-indexed data, unindexed data and two functions to find items or blocks


18 changes: 9 additions & 9 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from minecraft_data.v1_8 import recipes
from minecraft_data.v1_8 import find_item_or_block

print(recipes["5"][0])
print(find_item_or_block(1))

from minecraft_data.v1_9 import recipes as recipes2
print(find_item_or_block("stone"))

print(recipes2["5"][0])
from minecraft_data.v1_8 import recipes

from minecraft_data.v1_8 import findItemOrBlockById, findItemOrBlockByName
print(recipes["5"][0])

print(findItemOrBlockById(1))
from minecraft_data.v1_8 import windows as windows

print(findItemOrBlockByName("stone"))
print(windows["minecraft:brewing_stand"])

from minecraft_data.v1_8 import windows as windows
from minecraft_data.v1_9 import recipes as recipes2

print(windows["minecraft:brewing_stand"])
print(recipes2["5"][0])
51 changes: 25 additions & 26 deletions minecraft_data/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
def convert(dir):
data = _grabdata(dir)
ret = {
'blocks': _byId(data['blocks']),
'blocksByName': _byName(data['blocks']),
'blocksArray': data['blocks'],
'items': _byId(data['items']),
'itemsByName': _byName(data['items']),
'itemsArray': data['items'],
'biomes': _byId(data['biomes']),
'biomesArray': data['biomes'],
'blocks': _by_id(data['blocks']),
'blocks_name': _by_name(data['blocks']),
'blocks_list': data['blocks'],
'items': _by_id(data['items']),
'items_name': _by_name(data['items']),
'items_list': data['items'],
'biomes': _by_id(data['biomes']),
'biomes_list': data['biomes'],
'recipes': data['recipes'],
'instruments': _byId(data['instruments']),
'intrumentsArray': data['instruments'],
'instruments': _by_id(data['instruments']),
'instruments_list': data['instruments'],
'materials': data['materials'],
'entities': _byId(data['entities']),
'entitiesByName': _byName(data['entities']),
'entitiesArray': data['entities'],
'entities': _by_id(data['entities']),
'entities_name': _by_name(data['entities']),
'entities_list': data['entities'],
'protocol': data['protocol'],
'windows': _byId(data['windows']),
'windowsByName': _byName(data['windows']),
'windowsArray': data['windows'],
'windows': _by_id(data['windows']),
'windows_name': _by_name(data['windows']),
'windows_list': data['windows'],
}
def findItemOrBlockById(id):
return findBy(id, ret['items'], ret['blocks'])

def findItemOrBlockByName(name):
return findBy(name, ret['itemsByName'], ret['blocksByName'])
def find_item_or_block(find):
if isinstance(find, int): # by id
return find_by(find, ret['items'], ret['blocks'])
else: # by name
return find_by(find, ret['items_name'], ret['blocks_name'])

ret['findItemOrBlockById'] = findItemOrBlockById
ret['findItemOrBlockByName'] = findItemOrBlockByName
ret['find_item_or_block'] = find_item_or_block

return ret

Expand All @@ -48,21 +48,20 @@ def _grabdata(dir):
return data


def _byId(data):
def _by_id(data):
return _by('id', data)


def _byName(data):
def _by_name(data):
return _by('name', data)


def _by(key, data):
return {item[key]: item for item in data}


def findBy(key, *args):
def find_by(key, *args):
for arg in args:
if key in arg:
return arg[key]
return None

1 change: 0 additions & 1 deletion minecraft_data/v1_8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@

for name, data in convert(_dir).items():
setattr(sys.modules[__name__], name, data)

1 change: 0 additions & 1 deletion minecraft_data/v1_9/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@

for name, data in convert(_dir).items():
setattr(sys.modules[__name__], name, data)

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
description='Provide easy access to minecraft data in python',
license='MIT',
long_description=open('README.rst').read(),
version='0.2.0',
version='0.3.0',
maintainer='Romain Beaumont',
maintainer_email='romain.rom1@gmail.com',
url='https://github.com/rom1504/python-minecraft-data',
Expand Down