From 6c0688b75932454f5ec69f347013e8116ffcb8fe Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 14 Dec 2020 05:40:17 +0000 Subject: [PATCH] Rename data module to mcdata --- .gitignore | 2 +- blocks.py | 20 ++++++-------------- bot.py | 11 ++++++++++- download_mcdata.sh | 8 ++++---- game.py | 27 ++++++++++++++++++++++----- items.py | 2 +- jobs.py | 6 +++--- data.py => mcdata.py | 2 +- mobs.py | 2 +- utils.py | 5 +++-- 10 files changed, 52 insertions(+), 33 deletions(-) rename data.py => mcdata.py (89%) diff --git a/.gitignore b/.gitignore index 28d346b..c1bc3c2 100644 --- a/.gitignore +++ b/.gitignore @@ -102,4 +102,4 @@ ENV/ *.swp *.swo -mcdata/ +minecraft_data/ diff --git a/blocks.py b/blocks.py index 99a41f5..000ab4a 100644 --- a/blocks.py +++ b/blocks.py @@ -1,14 +1,14 @@ import json import importlib -import data -importlib.reload(data) +import mcdata +importlib.reload(mcdata) MCD_BLOCKS = {} -for d in data.mcd.blocks.values(): +for d in mcdata.mcd.blocks.values(): MCD_BLOCKS[d['name']] = d -with open('mcdata/blocks.json') as f: +with open('minecraft_data/blocks.json') as f: JSON_BLOCKS = json.load(f) BLOCKS = {} @@ -237,14 +237,6 @@ SAPLINGS = [ 'dark_oak_sapling', ] -CHESTS = [ - 'chest', -] - -TRAPPED_CHESTS = [ - 'trapped_chest', -] - INDEXED = [ 'chest', 'trapped_chest', @@ -278,12 +270,12 @@ for block_name in LEAVES: LEAF_IDS.add(state['id']) CHEST_IDS = set() -for block_name in CHESTS: +for block_name in ['chest']: for state in JSON_BLOCKS['minecraft:' + block_name]['states']: CHEST_IDS.add(state['id']) TRAPPED_CHEST_IDS = set() -for block_name in TRAPPED_CHESTS: +for block_name in ['trapped_chest']: for state in JSON_BLOCKS['minecraft:' + block_name]['states']: TRAPPED_CHEST_IDS.add(state['id']) diff --git a/bot.py b/bot.py index f85c2be..0ee4698 100644 --- a/bot.py +++ b/bot.py @@ -36,6 +36,8 @@ import path importlib.reload(path) import jobs importlib.reload(jobs) +import mcdata +importlib.reload(mcdata) last_tick = time.time() @@ -211,7 +213,7 @@ def bot(global_state): g = global_state if not g.mcdata: - g.mcdata = DataManager('./mcdata') + g.mcdata = DataManager('./minecraft_data') if not g.connection: auth_token = authentication.AuthenticationToken() @@ -262,3 +264,10 @@ def bot(global_state): g.connection.early_outgoing_packet_listeners = [] print('Bot module loaded.') + +print(mcdata.mcd.blockCollisionShapes['blocks']['brewing_stand']) +print(mcdata.mcd.blockCollisionShapes['shapes']['107']) + + + + diff --git a/download_mcdata.sh b/download_mcdata.sh index 9190ed7..8853328 100644 --- a/download_mcdata.sh +++ b/download_mcdata.sh @@ -1,10 +1,10 @@ #!/bin/sh -VERSION="1.16.2" +VERSION="1.16.4" wget -O/tmp/mcdata.zip https://apimon.de/mcdata/$VERSION/$VERSION.zip -rm -rf mcdata -mkdir mcdata -unzip /tmp/mcdata.zip -d mcdata +rm -rf minecraft_data +mkdir minecraft_data +unzip /tmp/mcdata.zip -d minecraft_data rm /tmp/mcdata.zip diff --git a/game.py b/game.py index e97664e..d1b9bc4 100644 --- a/game.py +++ b/game.py @@ -33,8 +33,8 @@ import blocks importlib.reload(blocks) import items importlib.reload(items) -import data -importlib.reload(data) +import mcdata +importlib.reload(mcdata) import mobs importlib.reload(mobs) @@ -588,6 +588,23 @@ class Game: tree = next(self.g.world.find_trees(pos, 50)) reply = str(tree)[1:-1] + if command == 'block': + try: + data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ') + x1, y1, z1 = [int(x) for x in data.split()] + except (AttributeError, ValueError): + reply = 'usage: !block x1 y1 z1' + + if not reply: + coord = (x1, y1, z1) + block = self.g.world.block_at(*coord) + + if not reply and block is None: + reply = 'first coord out of range' + + if not reply: + reply = blocks.BLOCKS[block] + ':' + str(block) + ################# Specific commands ########################## if for_me: @@ -993,7 +1010,7 @@ class Game: player.y += packet.delta_y / 4096.0 player.z += packet.delta_z / 4096.0 - if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) + #if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) def handle_entity_position_rotation(self, packet): mob = self.g.mobs.get(packet.entity_id, None) @@ -1008,7 +1025,7 @@ class Game: player.y += packet.delta_y / 4096.0 player.z += packet.delta_z / 4096.0 - if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) + #if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) def handle_entity_teleport(self, packet): mob = self.g.mobs.get(packet.entity_id, None) @@ -1023,7 +1040,7 @@ class Game: player.y = packet.y player.z = packet.z - if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) + #if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) def handle_entity_velocity(self, packet): obj = self.g.objects.get(packet.entity_id, None) diff --git a/items.py b/items.py index 9a23f6a..a2bd6e1 100644 --- a/items.py +++ b/items.py @@ -1,6 +1,6 @@ import json -with open('mcdata/registries.json') as f: +with open('minecraft_data/registries.json') as f: ITEMS = json.load(f)['minecraft:item']['entries'] BEDS = [ diff --git a/jobs.py b/jobs.py index 63fa843..64fb3e6 100644 --- a/jobs.py +++ b/jobs.py @@ -19,8 +19,8 @@ import blocks importlib.reload(blocks) import items importlib.reload(items) -import data -importlib.reload(data) +import mcdata +importlib.reload(mcdata) import mobs importlib.reload(mobs) @@ -722,7 +722,7 @@ class CacheItemsStates: if self.g.item_lock: return w = self.g.window - w_info = data.WINDOWS[w.data.window_type] + w_info = mcdata.WINDOWS[w.data.window_type] w_inventory_slots = w_info.inventory slot_list = [] diff --git a/data.py b/mcdata.py similarity index 89% rename from data.py rename to mcdata.py index 9c90fa1..812e81c 100644 --- a/data.py +++ b/mcdata.py @@ -5,7 +5,7 @@ import minecraft_data mcd = minecraft_data('1.16.4') -with open('mcdata/registries.json') as f: +with open('minecraft_data/registries.json') as f: DATA = json.load(f) SINGLE_CHEST = 2 diff --git a/mobs.py b/mobs.py index 5c91dfc..7c1e6e4 100644 --- a/mobs.py +++ b/mobs.py @@ -1,6 +1,6 @@ import json -with open('mcdata/registries.json') as f: +with open('minecraft_data/registries.json') as f: MOBS = json.load(f)['minecraft:entity_type']['entries'] EVIL = [ diff --git a/utils.py b/utils.py index b6e5a51..ba71b77 100644 --- a/utils.py +++ b/utils.py @@ -4,7 +4,8 @@ from math import floor, ceil, sqrt, hypot import blocks importlib.reload(blocks) -import data +import mcdata +importlib.reload(mcdata) TICK = 0.05 @@ -86,7 +87,7 @@ def break_time(block_id, held_item=0, in_water=False, on_ground=True, enchantmen can_harvest = 'harvestTools' not in block_data or str(held_item) in block_data['harvestTools'] material = block_data.get('material', 'n/a') - tool_multipliers = data.mcd.materials.get(material, []) + tool_multipliers = mcdata.mcd.materials.get(material, []) is_best_tool = held_item in tool_multipliers time = block_data['hardness']