Rename data module to mcdata

This commit is contained in:
Tanner Collin 2020-12-14 05:40:17 +00:00
parent b754a4746d
commit 6c0688b759
10 changed files with 52 additions and 33 deletions

2
.gitignore vendored
View File

@ -102,4 +102,4 @@ ENV/
*.swp *.swp
*.swo *.swo
mcdata/ minecraft_data/

View File

@ -1,14 +1,14 @@
import json import json
import importlib import importlib
import data import mcdata
importlib.reload(data) importlib.reload(mcdata)
MCD_BLOCKS = {} MCD_BLOCKS = {}
for d in data.mcd.blocks.values(): for d in mcdata.mcd.blocks.values():
MCD_BLOCKS[d['name']] = d 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) JSON_BLOCKS = json.load(f)
BLOCKS = {} BLOCKS = {}
@ -237,14 +237,6 @@ SAPLINGS = [
'dark_oak_sapling', 'dark_oak_sapling',
] ]
CHESTS = [
'chest',
]
TRAPPED_CHESTS = [
'trapped_chest',
]
INDEXED = [ INDEXED = [
'chest', 'chest',
'trapped_chest', 'trapped_chest',
@ -278,12 +270,12 @@ for block_name in LEAVES:
LEAF_IDS.add(state['id']) LEAF_IDS.add(state['id'])
CHEST_IDS = set() CHEST_IDS = set()
for block_name in CHESTS: for block_name in ['chest']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']: for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
CHEST_IDS.add(state['id']) CHEST_IDS.add(state['id'])
TRAPPED_CHEST_IDS = set() 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']: for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
TRAPPED_CHEST_IDS.add(state['id']) TRAPPED_CHEST_IDS.add(state['id'])

11
bot.py
View File

@ -36,6 +36,8 @@ import path
importlib.reload(path) importlib.reload(path)
import jobs import jobs
importlib.reload(jobs) importlib.reload(jobs)
import mcdata
importlib.reload(mcdata)
last_tick = time.time() last_tick = time.time()
@ -211,7 +213,7 @@ def bot(global_state):
g = global_state g = global_state
if not g.mcdata: if not g.mcdata:
g.mcdata = DataManager('./mcdata') g.mcdata = DataManager('./minecraft_data')
if not g.connection: if not g.connection:
auth_token = authentication.AuthenticationToken() auth_token = authentication.AuthenticationToken()
@ -262,3 +264,10 @@ def bot(global_state):
g.connection.early_outgoing_packet_listeners = [] g.connection.early_outgoing_packet_listeners = []
print('Bot module loaded.') print('Bot module loaded.')
print(mcdata.mcd.blockCollisionShapes['blocks']['brewing_stand'])
print(mcdata.mcd.blockCollisionShapes['shapes']['107'])

View File

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
VERSION="1.16.2" VERSION="1.16.4"
wget -O/tmp/mcdata.zip https://apimon.de/mcdata/$VERSION/$VERSION.zip wget -O/tmp/mcdata.zip https://apimon.de/mcdata/$VERSION/$VERSION.zip
rm -rf mcdata rm -rf minecraft_data
mkdir mcdata mkdir minecraft_data
unzip /tmp/mcdata.zip -d mcdata unzip /tmp/mcdata.zip -d minecraft_data
rm /tmp/mcdata.zip rm /tmp/mcdata.zip

27
game.py
View File

@ -33,8 +33,8 @@ import blocks
importlib.reload(blocks) importlib.reload(blocks)
import items import items
importlib.reload(items) importlib.reload(items)
import data import mcdata
importlib.reload(data) importlib.reload(mcdata)
import mobs import mobs
importlib.reload(mobs) importlib.reload(mobs)
@ -588,6 +588,23 @@ class Game:
tree = next(self.g.world.find_trees(pos, 50)) tree = next(self.g.world.find_trees(pos, 50))
reply = str(tree)[1:-1] 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 ########################## ################# Specific commands ##########################
if for_me: if for_me:
@ -993,7 +1010,7 @@ class Game:
player.y += packet.delta_y / 4096.0 player.y += packet.delta_y / 4096.0
player.z += packet.delta_z / 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): def handle_entity_position_rotation(self, packet):
mob = self.g.mobs.get(packet.entity_id, None) mob = self.g.mobs.get(packet.entity_id, None)
@ -1008,7 +1025,7 @@ class Game:
player.y += packet.delta_y / 4096.0 player.y += packet.delta_y / 4096.0
player.z += packet.delta_z / 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): def handle_entity_teleport(self, packet):
mob = self.g.mobs.get(packet.entity_id, None) mob = self.g.mobs.get(packet.entity_id, None)
@ -1023,7 +1040,7 @@ class Game:
player.y = packet.y player.y = packet.y
player.z = packet.z 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): def handle_entity_velocity(self, packet):
obj = self.g.objects.get(packet.entity_id, None) obj = self.g.objects.get(packet.entity_id, None)

View File

@ -1,6 +1,6 @@
import json import json
with open('mcdata/registries.json') as f: with open('minecraft_data/registries.json') as f:
ITEMS = json.load(f)['minecraft:item']['entries'] ITEMS = json.load(f)['minecraft:item']['entries']
BEDS = [ BEDS = [

View File

@ -19,8 +19,8 @@ import blocks
importlib.reload(blocks) importlib.reload(blocks)
import items import items
importlib.reload(items) importlib.reload(items)
import data import mcdata
importlib.reload(data) importlib.reload(mcdata)
import mobs import mobs
importlib.reload(mobs) importlib.reload(mobs)
@ -722,7 +722,7 @@ class CacheItemsStates:
if self.g.item_lock: return if self.g.item_lock: return
w = self.g.window 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 w_inventory_slots = w_info.inventory
slot_list = [] slot_list = []

View File

@ -5,7 +5,7 @@ import minecraft_data
mcd = minecraft_data('1.16.4') 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) DATA = json.load(f)
SINGLE_CHEST = 2 SINGLE_CHEST = 2

View File

@ -1,6 +1,6 @@
import json 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'] MOBS = json.load(f)['minecraft:entity_type']['entries']
EVIL = [ EVIL = [

View File

@ -4,7 +4,8 @@ from math import floor, ceil, sqrt, hypot
import blocks import blocks
importlib.reload(blocks) importlib.reload(blocks)
import data import mcdata
importlib.reload(mcdata)
TICK = 0.05 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'] can_harvest = 'harvestTools' not in block_data or str(held_item) in block_data['harvestTools']
material = block_data.get('material', 'n/a') 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 is_best_tool = held_item in tool_multipliers
time = block_data['hardness'] time = block_data['hardness']