Compare commits

..

2 Commits

Author SHA1 Message Date
6c9f228862 Add a job for farming nether wart 2020-12-14 06:21:50 +00:00
6c0688b759 Rename data module to mcdata 2020-12-14 05:40:17 +00:00
10 changed files with 181 additions and 34 deletions

2
.gitignore vendored
View File

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

View File

@ -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,15 +270,20 @@ 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'])
NETHERWART_IDS = set()
for block_name in ['nether_wart']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
NETHERWART_IDS.add(state['id'])
INDEXED_IDS = set()
for block_name in INDEXED:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:

11
bot.py
View File

@ -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'])

View File

@ -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

30
game.py
View File

@ -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:
@ -622,6 +639,9 @@ class Game:
elif data == 'sand':
self.g.job.state = self.g.job.farm_sand
reply = 'ok'
elif data == 'wart':
self.g.job.state = self.g.job.farm_wart
reply = 'ok'
if reply:
for i in self.g.inv.values():
@ -993,7 +1013,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 +1028,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 +1043,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)

View File

@ -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 = [
@ -62,5 +62,7 @@ GAPPLE_ID = set([ITEMS['minecraft:enchanted_golden_apple']['protocol_id']])
SAND_ID = set([ITEMS['minecraft:sand']['protocol_id']])
NETHERWART_ID = set([ITEMS['minecraft:nether_wart']['protocol_id']])
NEEDED_ITEMS = BED_IDS | CHEST_ID
WANTED_ITEMS = SAPLING_IDS
WANTED_ITEMS = SAPLING_IDS | NETHERWART_ID

124
jobs.py
View File

@ -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)
@ -124,6 +124,113 @@ class FindGappleStates:
self.state()
class GatherWartStates:
def idle(self):
return None
def init(self):
self.g.chopped_tree = False
self.state = self.find_new_wart
def find_new_wart(self):
print('Finding new tree...')
w = self.g.world
p = utils.pint(self.g.pos)
mature_wart = max(blocks.NETHERWART_IDS)
for wart in w.find_blocks_3d(p, [mature_wart], 100):
print('Found wart:', wart)
if wart not in self.bad_warts:
break
else: # for
print('No good warts left, aborting.')
self.state = self.cleanup
return
self.wart = wart
self.state = self.nav_to_wart
def nav_to_wart(self):
w = self.g.world
p = utils.pint(self.g.pos)
navpath = w.path_to_place(p, self.wart)
if navpath:
self.g.path = navpath
self.g.look_at = utils.padd(self.wart, path.BLOCK_BELOW)
self.state = self.going_to_wart
else:
self.bad_warts.append(wart)
self.state = self.find_new_wart
def going_to_wart(self):
if utils.pint(self.g.pos) == self.wart:
print('At the wart')
self.state = self.break_wart
def break_wart(self):
self.g.game.break_block(self.wart)
self.wait_time = 0.5
self.state = self.wait
def wait(self):
# wait for the item
if self.wait_time > 0:
self.wait_time -= utils.TICK
else:
self.state = self.select_wart
def select_wart(self):
p = utils.pint(self.g.pos)
if self.g.game.select_item(items.NETHERWART_ID):
self.state = self.wait_select
self.wait_time = 0.5
else:
print('Aborting planting, no wart')
self.state = self.cleanup
def wait_select(self):
# wait a bit to select
if self.wait_time > 0:
self.wait_time -= utils.TICK
else:
self.state = self.place_wart
def place_wart(self):
p = utils.pint(self.g.pos)
self.g.game.place_block(p, BlockFace.TOP)
print('Placed wart')
self.state = self.wait_place
self.wait_time = 0.5
def wait_place(self):
# wait a bit for chunk data to update
if self.wait_time > 0:
self.wait_time -= utils.TICK
else:
self.state = self.cleanup
def cleanup(self):
self.g.look_at = None
self.state = self.done
def done(self):
# never gets ran, placeholder
return None
def __init__(self, global_state):
self.g = global_state
self.state = self.idle
self.wart = None
self.bad_warts = []
self.wait_time = 0
def run(self):
self.state()
class GatherWoodStates:
def bair(self, p):
return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS
@ -722,7 +829,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 = []
@ -1325,6 +1432,7 @@ class JobStates:
self.grab_sand_states = GrabSandStates(self.g)
self.fill_blocks_states = FillBlocksStates(self.g)
self.check_threats_states = CheckThreatsStates(self.g)
self.gather_wart_states = GatherWartStates(self.g)
def run_machines(self, machines):
for m in machines:
@ -1393,6 +1501,16 @@ class JobStates:
self.cache_items_states.silent = True
return machines
def farm_wart(self):
machines = [
self.gather_wart_states,
self.sleep_with_bed_states,
self.cache_items_states,
]
self.sleep_with_bed_states.silent = True
self.cache_items_states.silent = True
return machines
def fill_blocks(self):
machines = [
self.fill_blocks_states,

View File

@ -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

View File

@ -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 = [

View File

@ -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']