Track name, dimension, add addressable commands
This commit is contained in:
parent
f2cb61c4bc
commit
d86c21fead
237
game.py
237
game.py
|
@ -309,6 +309,7 @@ class Game:
|
|||
self.g = global_state
|
||||
|
||||
register = self.g.connection.register_packet_listener
|
||||
register(self.handle_login_success, clientbound.login.LoginSuccessPacket)
|
||||
register(self.handle_block_change, clientbound.play.BlockChangePacket)
|
||||
register(self.handle_join_game, clientbound.play.JoinGamePacket)
|
||||
register(self.handle_position_and_look, clientbound.play.PlayerPositionAndLookPacket)
|
||||
|
@ -325,17 +326,23 @@ class Game:
|
|||
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
||||
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
||||
register(self.handle_spawn_player, SpawnPlayerPacket)
|
||||
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
||||
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket)
|
||||
|
||||
#register(self.handle_packet, Packet, early=True)
|
||||
|
||||
self.g.chat.set_handler(self.handle_chat)
|
||||
|
||||
def handle_login_success(self, packet):
|
||||
print(packet)
|
||||
self.g.name = packet.Username
|
||||
|
||||
def handle_join_game(self, packet):
|
||||
print('Connected.')
|
||||
print(packet)
|
||||
self.g.info = packet
|
||||
self.g.eid = packet.entity_id
|
||||
self.g.dimension = packet.world_name.replace('minecraft:', '')
|
||||
|
||||
def handle_block_change(self, packet):
|
||||
if packet.block_state_id == blocks.SOUL_TORCH:
|
||||
|
@ -390,10 +397,11 @@ class Game:
|
|||
source, text = message
|
||||
reply = None
|
||||
private = False
|
||||
for_me = False
|
||||
authed = False
|
||||
|
||||
if source == 'SYSTEM':
|
||||
self.g.command_lock = False
|
||||
return
|
||||
|
||||
if text == 'You are now AFK.':
|
||||
self.g.afk = True
|
||||
|
@ -410,9 +418,17 @@ class Game:
|
|||
else:
|
||||
return
|
||||
|
||||
if sender == 'tanner6':
|
||||
authed = True
|
||||
|
||||
if text.startswith('zzz'):
|
||||
text = '!zzz'
|
||||
|
||||
bot_num = self.g.name[-1]
|
||||
|
||||
if text.startswith(bot_num):
|
||||
text = text[1:]
|
||||
for_me = True
|
||||
if text.startswith('! '):
|
||||
text = text[2:]
|
||||
elif text.startswith('!'):
|
||||
|
@ -428,23 +444,25 @@ class Game:
|
|||
data = None
|
||||
|
||||
try:
|
||||
|
||||
################# Public commands ########################
|
||||
|
||||
if command == 'ping':
|
||||
reply = 'pong'
|
||||
|
||||
if command == 'echo' and data:
|
||||
reply = data
|
||||
|
||||
if command == 'respawn':
|
||||
packet = serverbound.play.ClientStatusPacket()
|
||||
packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN
|
||||
self.g.connection.write_packet(packet)
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'pos':
|
||||
reply = str(utils.pint(self.g.pos))[1:-1]
|
||||
|
||||
if command == 'afk':
|
||||
reply = '/afk'
|
||||
if not self.g.afk:
|
||||
reply = '/afk'
|
||||
|
||||
if command == 'unafk':
|
||||
if self.g.afk:
|
||||
reply = '/afk'
|
||||
|
||||
if command == 'error':
|
||||
reply = 'ok'
|
||||
|
@ -454,43 +472,6 @@ class Game:
|
|||
self.break_block(blocks.TEST_BLOCK)
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'gather' and data:
|
||||
if data == 'wood':
|
||||
self.g.job.state = self.g.job.gather_wood
|
||||
reply = 'ok'
|
||||
elif data == 'sand':
|
||||
self.g.job.state = self.g.job.gather_sand
|
||||
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 == 'farm' and data:
|
||||
if data == 'wood':
|
||||
self.g.job.state = self.g.job.farm_wood
|
||||
reply = 'ok'
|
||||
elif data == 'sand':
|
||||
self.g.job.state = self.g.job.farm_sand
|
||||
reply = 'ok'
|
||||
|
||||
if reply:
|
||||
for i in self.g.inv.values():
|
||||
if i.item_id in items.BED_IDS:
|
||||
break
|
||||
else:
|
||||
reply += ', I need a bed'
|
||||
|
||||
if command == 'stop':
|
||||
self.g.job.stop()
|
||||
self.g.path = []
|
||||
self.g.look_at = None
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'inv':
|
||||
inv_list = []
|
||||
for i in self.g.inv.values():
|
||||
|
@ -500,27 +481,9 @@ class Game:
|
|||
result = '\n'.join(inv_list)
|
||||
print(result or 'Empty')
|
||||
|
||||
if command == 'drop':
|
||||
self.drop_stack()
|
||||
|
||||
if command == 'time':
|
||||
reply = str(self.g.time)
|
||||
|
||||
if command == 'select' and data:
|
||||
item = int(data)
|
||||
if self.select_item([item]):
|
||||
reply = 'ok'
|
||||
else:
|
||||
reply = 'not found'
|
||||
|
||||
if command == 'dump' and data:
|
||||
item = int(data)
|
||||
if self.count_items([item]):
|
||||
self.g.dumping = item
|
||||
reply = 'ok'
|
||||
else:
|
||||
reply = 'not found'
|
||||
|
||||
if command == 'count' and data:
|
||||
item = int(data)
|
||||
reply = str(self.count_items([item]))
|
||||
|
@ -549,12 +512,6 @@ class Game:
|
|||
if command == 'loaded':
|
||||
reply = str(self.g.chunks.get_loaded_area())
|
||||
|
||||
if command == 'gapple':
|
||||
self.g.job.state = self.g.job.find_gapple
|
||||
if data:
|
||||
self.g.job.find_gapple_states.count = int(data)
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'objects':
|
||||
if data == 'clear':
|
||||
self.g.objects = {}
|
||||
|
@ -594,12 +551,6 @@ class Game:
|
|||
print(str(t.entity_id) + ':', t, mobs.MOB_NAMES[t.type])
|
||||
reply = str(len(threats)) + ' threats'
|
||||
|
||||
if command == 'cache':
|
||||
self.g.job.state = self.g.job.cache_items
|
||||
self.g.job.cache_items_states.minimum = 0
|
||||
self.g.job.cache_items_states.silent = True
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'spiral' and data:
|
||||
for i in range(int(data)):
|
||||
print(utils.spiral(i))
|
||||
|
@ -609,43 +560,125 @@ class Game:
|
|||
reply = str(result)
|
||||
|
||||
if command == 'zzz':
|
||||
if not self.g.afk:
|
||||
if not self.g.afk and self.g.dimension == 'overworld':
|
||||
if self.g.path:
|
||||
travel_time = int(len(self.g.path) * 0.4) + 2
|
||||
reply = 'give me ' + str(travel_time) + ' secs, moving'
|
||||
reply = 'gimme ' + str(travel_time) + ' secs, moving'
|
||||
self.g.queue_afk = True
|
||||
else:
|
||||
reply = '/afk'
|
||||
|
||||
if command == 'print' and sender == 'tanner6':
|
||||
data = data.replace('^', '.')
|
||||
reply = str(eval(data))
|
||||
|
||||
if command == 'fill':
|
||||
try:
|
||||
data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
||||
x1, y1, z1, x2, y2, z2 = [int(x) for x in data.split()]
|
||||
except (AttributeError, ValueError):
|
||||
reply = 'usage: !fill x1 y1 z1 x2 y2 z2'
|
||||
################# Specific commands ##########################
|
||||
if for_me:
|
||||
pass
|
||||
|
||||
if not reply:
|
||||
coord1 = (x1, y1, z1)
|
||||
coord2 = (x2, y2, z2)
|
||||
block = self.g.world.block_at(*coord1)
|
||||
if command == 'respawn':
|
||||
packet = serverbound.play.ClientStatusPacket()
|
||||
packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN
|
||||
self.g.connection.write_packet(packet)
|
||||
reply = 'ok'
|
||||
|
||||
if not reply and y1 > y2:
|
||||
reply = 'can only fill upwards'
|
||||
if command == 'gather' and data:
|
||||
if data == 'wood':
|
||||
self.g.job.state = self.g.job.gather_wood
|
||||
reply = 'ok'
|
||||
elif data == 'sand':
|
||||
self.g.job.state = self.g.job.gather_sand
|
||||
reply = 'ok'
|
||||
|
||||
if not reply and block is None:
|
||||
reply = 'first coord out of range'
|
||||
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 not reply and block == 0:
|
||||
reply = 'can\'t fill with air'
|
||||
if command == 'farm' and data:
|
||||
if data == 'wood':
|
||||
self.g.job.state = self.g.job.farm_wood
|
||||
reply = 'ok'
|
||||
elif data == 'sand':
|
||||
self.g.job.state = self.g.job.farm_sand
|
||||
reply = 'ok'
|
||||
|
||||
if not reply:
|
||||
self.g.filling = Munch(coord1=coord1, coord2=coord2, block=block)
|
||||
self.g.job.state = self.g.job.fill_blocks
|
||||
reply = 'filling ' + str(utils.pvolume(coord1, coord2)) + ' with ' + blocks.BLOCKS[block]
|
||||
if reply:
|
||||
for i in self.g.inv.values():
|
||||
if i.item_id in items.BED_IDS:
|
||||
break
|
||||
else:
|
||||
reply += ', I need a bed'
|
||||
|
||||
if command == 'stop':
|
||||
self.g.job.stop()
|
||||
self.g.path = []
|
||||
self.g.look_at = None
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'drop':
|
||||
self.drop_stack()
|
||||
|
||||
if command == 'select' and data:
|
||||
item = int(data)
|
||||
if self.select_item([item]):
|
||||
reply = 'ok'
|
||||
else:
|
||||
reply = 'not found'
|
||||
|
||||
if command == 'dump' and data:
|
||||
item = int(data)
|
||||
if self.count_items([item]):
|
||||
self.g.dumping = item
|
||||
reply = 'ok'
|
||||
else:
|
||||
reply = 'not found'
|
||||
|
||||
if command == 'gapple':
|
||||
self.g.job.state = self.g.job.find_gapple
|
||||
if data:
|
||||
self.g.job.find_gapple_states.count = int(data)
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'cache':
|
||||
self.g.job.state = self.g.job.cache_items
|
||||
self.g.job.cache_items_states.minimum = 0
|
||||
self.g.job.cache_items_states.silent = True
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'fill':
|
||||
try:
|
||||
data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
||||
x1, y1, z1, x2, y2, z2 = [int(x) for x in data.split()]
|
||||
except (AttributeError, ValueError):
|
||||
reply = 'usage: !fill x1 y1 z1 x2 y2 z2'
|
||||
|
||||
if not reply:
|
||||
coord1 = (x1, y1, z1)
|
||||
coord2 = (x2, y2, z2)
|
||||
block = self.g.world.block_at(*coord1)
|
||||
|
||||
if not reply and y1 > y2:
|
||||
reply = 'can only fill upwards'
|
||||
|
||||
if not reply and block is None:
|
||||
reply = 'first coord out of range'
|
||||
|
||||
if not reply and block == 0:
|
||||
reply = 'can\'t fill with air'
|
||||
|
||||
if not reply:
|
||||
self.g.filling = Munch(coord1=coord1, coord2=coord2, block=block)
|
||||
self.g.job.state = self.g.job.fill_blocks
|
||||
reply = 'filling ' + str(utils.pvolume(coord1, coord2)) + ' with ' + blocks.BLOCKS[block]
|
||||
|
||||
|
||||
################# Authorized commands ##########################
|
||||
if authed:
|
||||
|
||||
if command == 'print':
|
||||
data = data.replace('^', '.')
|
||||
reply = str(eval(data))
|
||||
|
||||
|
||||
except BaseException as e:
|
||||
|
@ -932,6 +965,10 @@ class Game:
|
|||
packet.jump_boost = 0
|
||||
self.g.connection.write_packet(packet)
|
||||
|
||||
def handle_respawn(self, packet):
|
||||
print(packet)
|
||||
self.g.dimension = packet.world_name.replace('minecraft:', '')
|
||||
|
||||
|
||||
def tick(self):
|
||||
if self.g.breaking:
|
||||
|
|
12
jobs.py
12
jobs.py
|
@ -480,11 +480,17 @@ class SleepWithBedStates:
|
|||
return None
|
||||
|
||||
def init(self):
|
||||
if self.g.time >= 12000:
|
||||
self.state = self.select_bed
|
||||
else:
|
||||
if self.g.time < 12000:
|
||||
print('Aborting sleep, not night')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
if self.g.dimension != 'overworld':
|
||||
print('Aborting sleep, not in overworld')
|
||||
self.state = self.cleanup
|
||||
return
|
||||
|
||||
self.state = self.select_bed
|
||||
|
||||
def select_bed(self):
|
||||
if self.g.game.select_item(items.BED_IDS):
|
||||
|
|
Loading…
Reference in New Issue
Block a user