Add state machine for eating food
This commit is contained in:
@@ -336,6 +336,7 @@ class Game:
|
||||
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
||||
register(self.handle_player_list, clientbound.play.PlayerListItemPacket)
|
||||
register(self.handle_entity_teleport, EntityTeleport)
|
||||
register(self.handle_update_health, clientbound.play.UpdateHealthPacket)
|
||||
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket)
|
||||
|
||||
#register(self.handle_packet, Packet, early=True)
|
||||
@@ -477,10 +478,6 @@ class Game:
|
||||
reply = 'ok'
|
||||
raise
|
||||
|
||||
if command == 'break':
|
||||
self.break_block(blocks.TEST_BLOCK)
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'inv':
|
||||
inv_list = []
|
||||
for i in self.g.inv.values():
|
||||
@@ -497,27 +494,6 @@ class Game:
|
||||
item = int(data)
|
||||
reply = str(self.count_items([item]))
|
||||
|
||||
if command == 'open':
|
||||
self.open_container(blocks.TEST_BLOCK)
|
||||
|
||||
if command == 'close':
|
||||
if self.g.window:
|
||||
self.close_window()
|
||||
else:
|
||||
reply = 'nothing open'
|
||||
|
||||
if command == 'click' and data:
|
||||
if self.g.window:
|
||||
slot, button, mode = [int(x) for x in data.split(' ')]
|
||||
try:
|
||||
item = self.g.window.contents[slot]
|
||||
except KeyError:
|
||||
item = Slot(present=False, item_id=None, item_count=None, nbt=None)
|
||||
print(item)
|
||||
self.click_window(slot, button, mode, item)
|
||||
else:
|
||||
reply = 'nothing open'
|
||||
|
||||
if command == 'loaded':
|
||||
reply = str(self.g.chunks.get_loaded_area())
|
||||
|
||||
@@ -651,6 +627,10 @@ class Game:
|
||||
else:
|
||||
reply += ', I need a bed'
|
||||
|
||||
if command == 'loiter':
|
||||
self.g.job.state = self.g.job.loiter
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'stop':
|
||||
bot.init(self.g)
|
||||
reply = 'ok'
|
||||
@@ -745,6 +725,33 @@ class Game:
|
||||
else:
|
||||
reply = 'no path'
|
||||
|
||||
if command == 'break':
|
||||
self.break_block(blocks.TEST_BLOCK)
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'open':
|
||||
self.open_container(blocks.TEST_BLOCK)
|
||||
|
||||
if command == 'close':
|
||||
if self.g.window:
|
||||
self.close_window()
|
||||
else:
|
||||
reply = 'nothing open'
|
||||
|
||||
if command == 'click' and data:
|
||||
if self.g.window:
|
||||
slot, button, mode = [int(x) for x in data.split(' ')]
|
||||
try:
|
||||
item = self.g.window.contents[slot]
|
||||
except KeyError:
|
||||
item = Slot(present=False, item_id=None, item_count=None, nbt=None)
|
||||
print(item)
|
||||
self.click_window(slot, button, mode, item)
|
||||
else:
|
||||
reply = 'nothing open'
|
||||
|
||||
if command == 'use':
|
||||
self.use_item(0)
|
||||
|
||||
################# Authorized commands ##########################
|
||||
if authed:
|
||||
@@ -1081,6 +1088,16 @@ class Game:
|
||||
self.g.player_names[action.uuid] = action.name
|
||||
self.g.player_names[action.name] = action.uuid # porque no los dos?
|
||||
|
||||
def handle_update_health(self, packet):
|
||||
print(packet)
|
||||
self.g.health = packet.health
|
||||
self.g.food = packet.food
|
||||
|
||||
def use_item(self, hand):
|
||||
packet = serverbound.play.UseItemPacket()
|
||||
packet.hand = hand
|
||||
self.g.connection.write_packet(packet)
|
||||
|
||||
def tick(self):
|
||||
if self.g.breaking:
|
||||
self.animate()
|
||||
|
||||
Reference in New Issue
Block a user