Created
January 31, 2016 07:57
-
-
Save davidjmerritt/c19e7fce1f14f7c91723 to your computer and use it in GitHub Desktop.
__main__.py for pymclevel integration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time, sys, json | |
import mclevel | |
def block_dict(): | |
with open("pymclevel/blocks.json") as f: | |
return json.load(f) | |
def load_world_data(world_path): | |
world = mclevel.fromFile(world_path) | |
return world | |
def get_player_coords(world_data,player="Player"): | |
return world_data.getPlayerPosition(player=player) | |
#playerSpawnPosition | |
def get_block(world_data): | |
chunkPositions = list(world_data.allChunks) | |
block_map = block_dict() | |
for chunkPos in chunkPositions: | |
chunk = world_data.getChunk(chunkPos[0],chunkPos[1]) | |
block_id = chunk.Blocks[0,0,64] | |
block_data = { | |
"block_id": block_id, | |
"coords":[chunkPos[0],chunkPos[1]] | |
} | |
for block_d in block_map: | |
if block_id == block_d[0]: | |
block_data["name"] = block_d[2] | |
print block_data | |
if __name__ == "__main__": | |
world_path = sys.argv[1].replace('\\','') | |
world_data = load_world_data(world_path) | |
print get_block(world_data) | |
# i = 0 | |
# while True: | |
# i += 1 | |
# world_data = load_world_data(world_path) | |
# print i, get_player_coords(world_data) | |
# time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment