Port over job sleeping
This commit is contained in:
parent
58458a561f
commit
f2e0b162f9
43
game.py
43
game.py
|
@ -8,7 +8,7 @@ from panda3d.core import LPoint3f
|
|||
|
||||
from minecraft.networking.packets import Packet, clientbound, serverbound
|
||||
|
||||
from protocol.packets import TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket, BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket
|
||||
from protocol.packets import TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket, BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket, HeldItemChangePacket, PickItemPacket
|
||||
|
||||
import utils
|
||||
importlib.reload(utils)
|
||||
|
@ -16,6 +16,8 @@ import path
|
|||
importlib.reload(path)
|
||||
import blocks
|
||||
importlib.reload(blocks)
|
||||
import items
|
||||
importlib.reload(items)
|
||||
|
||||
class MCWorld:
|
||||
def __init__(self, global_state):
|
||||
|
@ -97,7 +99,7 @@ class MCWorld:
|
|||
def find_bed_areas(self, center, distance):
|
||||
air = []
|
||||
for i in range(5):
|
||||
check = utils.padd(center, alternate(i, 1))
|
||||
check = utils.padd(center, utils.alternate(i, 1))
|
||||
air.extend(self.find_blocks(check, distance, [0], 200))
|
||||
|
||||
areas = []
|
||||
|
@ -128,7 +130,7 @@ class MCWorld:
|
|||
def find_sand(self, center, distance, origin):
|
||||
sand = []
|
||||
for i in range(10):
|
||||
check = utils.padd(center, alternate(i, 1))
|
||||
check = utils.padd(center, utils.alternate(i, 1))
|
||||
sand.extend(self.find_blocks(check, distance, [66], 20))
|
||||
|
||||
safe_sand = []
|
||||
|
@ -267,6 +269,22 @@ class Game:
|
|||
self.g.job.state = self.g.job.lumberjack
|
||||
reply = 'ok'
|
||||
|
||||
if reply:
|
||||
for i in self.g.inv.values():
|
||||
print(i.item_id)
|
||||
if i.item_id in items.BED_IDS:
|
||||
break
|
||||
else:
|
||||
reply += ', I need a bed'
|
||||
|
||||
if command == 'inv':
|
||||
for i in self.g.inv.values():
|
||||
if i.present:
|
||||
print(items.ITEM_NAMES[i.item_id], 'x', i.item_count)
|
||||
|
||||
if command == 'time':
|
||||
reply = str(self.g.time)
|
||||
|
||||
if reply:
|
||||
print(reply)
|
||||
self.g.chat.send(reply)
|
||||
|
@ -316,7 +334,7 @@ class Game:
|
|||
def place_block(self, location, face):
|
||||
packet = serverbound.play.PlayerBlockPlacementPacket()
|
||||
packet.hand = 0
|
||||
packet.location = pos
|
||||
packet.location = location
|
||||
packet.face = face
|
||||
packet.x = 0.5
|
||||
packet.y = 0.5
|
||||
|
@ -324,6 +342,23 @@ class Game:
|
|||
packet.inside_block = False
|
||||
self.g.connection.write_packet(packet)
|
||||
|
||||
def pick(self, slot):
|
||||
packet = PickItemPacket()
|
||||
packet.slot_to_use = slot
|
||||
self.g.connection.write_packet(packet)
|
||||
|
||||
def hold(self, slot):
|
||||
packet = HeldItemChangePacket()
|
||||
packet.slot = slot
|
||||
self.g.connection.write_packet(packet)
|
||||
|
||||
def choose_slot(self, slot):
|
||||
if slot >= 36:
|
||||
slot -= 36
|
||||
self.hold(slot)
|
||||
else:
|
||||
self.pick(slot)
|
||||
|
||||
def tick(self):
|
||||
if self.g.breaking:
|
||||
self.animate()
|
||||
|
|
31
items.py
Normal file
31
items.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import json
|
||||
|
||||
with open('mcdata/registries.json') as f:
|
||||
ITEMS = json.load(f)['minecraft:item']['entries']
|
||||
|
||||
BEDS = [
|
||||
'white_bed',
|
||||
'orange_bed',
|
||||
'magenta_bed',
|
||||
'light_blue_bed',
|
||||
'yellow_bed',
|
||||
'lime_bed',
|
||||
'pink_bed',
|
||||
'gray_bed',
|
||||
'light_gray_bed',
|
||||
'cyan_bed',
|
||||
'purple_bed',
|
||||
'blue_bed',
|
||||
'brown_bed',
|
||||
'green_bed',
|
||||
'red_bed',
|
||||
'black_bed',
|
||||
]
|
||||
|
||||
BED_IDS = set()
|
||||
for item_name in BEDS:
|
||||
BED_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id'])
|
||||
|
||||
ITEM_NAMES = {}
|
||||
for item_name, item in ITEMS.items():
|
||||
ITEM_NAMES[ITEMS[item_name]['protocol_id']] = item_name.replace('minecraft:', '')
|
15
jobs.py
15
jobs.py
|
@ -13,6 +13,8 @@ import path
|
|||
importlib.reload(path)
|
||||
import blocks
|
||||
importlib.reload(blocks)
|
||||
import items
|
||||
importlib.reload(items)
|
||||
|
||||
|
||||
class LumberjackStates:
|
||||
|
@ -310,22 +312,22 @@ class SleepWithBedStates:
|
|||
if item.item_id in items.BED_IDS:
|
||||
print('Found bed in slot', slot)
|
||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||
choose_slot(self.connection, slot)
|
||||
self.g.game.choose_slot(slot)
|
||||
self.state = self.place_bed
|
||||
break
|
||||
else: # for
|
||||
say(self.connection, 'I need a bed')
|
||||
self.g.chat.send('I need a bed')
|
||||
self.state = self.cleanup
|
||||
|
||||
def place_bed(self):
|
||||
place_block(self.connection, self.area, BlockFace.TOP)
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
self.state = self.use_bed
|
||||
|
||||
def use_bed(self):
|
||||
if self.g.time >= 12542:
|
||||
print('Sleeping')
|
||||
place_block(self.connection, self.area, BlockFace.TOP)
|
||||
say(self.connection, 'zzz')
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
self.g.chat.send('zzz')
|
||||
self.state = self.sleep_bed
|
||||
|
||||
def sleep_bed(self):
|
||||
|
@ -399,7 +401,6 @@ class JobStates:
|
|||
s.state = s.init
|
||||
# check time, etc
|
||||
|
||||
if self.survive:
|
||||
self.prev_state = self.gather_sand
|
||||
self.state = self.sleep_with_bed
|
||||
return
|
||||
|
@ -414,7 +415,6 @@ class JobStates:
|
|||
s.state = s.init
|
||||
# check time, etc
|
||||
|
||||
if self.survive:
|
||||
self.prev_state = self.lumberjack
|
||||
self.state = self.sleep_with_bed
|
||||
return
|
||||
|
@ -435,7 +435,6 @@ class JobStates:
|
|||
self.lumberjack_states = LumberjackStates(self.g)
|
||||
self.gather_sand_states = GatherSandStates(self.g)
|
||||
self.sleep_with_bed_states = SleepWithBedStates(self.g)
|
||||
self.survive = False
|
||||
|
||||
def tick(self):
|
||||
self.state()
|
||||
|
|
3
utils.py
3
utils.py
|
@ -68,7 +68,8 @@ def break_time(block_id, held_item=0, in_water=False, on_ground=True, enchantmen
|
|||
data = blocks.get(block_id)
|
||||
|
||||
can_harvest = 'harvestTools' not in data or str(held_item) in data['harvestTools']
|
||||
tool_multipliers = blocks.mcd.materials.get(data['material'], [])
|
||||
material = data.get('material', 'n/a')
|
||||
tool_multipliers = blocks.mcd.materials.get(material, [])
|
||||
is_best_tool = held_item in tool_multipliers
|
||||
time = data['hardness']
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user