Compare commits
3 Commits
324ad41bf7
...
261684ea90
Author | SHA1 | Date | |
---|---|---|---|
261684ea90 | |||
09b09b3f96 | |||
4d2d358175 |
|
@ -23,7 +23,7 @@ class Commands:
|
||||||
|
|
||||||
def handle_chat(self, message):
|
def handle_chat(self, message):
|
||||||
source, sender, text = message
|
source, sender, text = message
|
||||||
reply = None
|
reply = ''
|
||||||
private = False
|
private = False
|
||||||
for_me = False
|
for_me = False
|
||||||
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
|
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
|
||||||
|
@ -244,23 +244,67 @@ class Commands:
|
||||||
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]
|
||||||
|
|
||||||
## !block x y z - replies what block is at (x, y, z)
|
## !info [query] - replies with info on a coordinate, block, item, or player
|
||||||
if command == 'block':
|
if command == 'info':
|
||||||
try:
|
if not reply:
|
||||||
data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
try:
|
||||||
x1, y1, z1 = [int(x) for x in data.split()]
|
check = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
||||||
except (AttributeError, ValueError):
|
x1, y1, z1 = [int(x) for x in check.split()]
|
||||||
reply = 'usage: !block x1 y1 z1'
|
coord = (x1, y1, z1)
|
||||||
|
block = self.g.world.block_at(*coord)
|
||||||
|
|
||||||
|
if not reply and block is None:
|
||||||
|
reply = 'coord out of range'
|
||||||
|
|
||||||
|
if not reply:
|
||||||
|
reply = 'Block: ' + blocks.BLOCKS[block] + ':' + str(block)
|
||||||
|
if blocks.PROPS[block]:
|
||||||
|
reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()])
|
||||||
|
except (AttributeError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
if not reply:
|
if not reply:
|
||||||
coord = (x1, y1, z1)
|
try:
|
||||||
block = self.g.world.block_at(*coord)
|
check = int(data)
|
||||||
|
|
||||||
if not reply and block is None:
|
if check in blocks.BLOCKS:
|
||||||
reply = 'first coord out of range'
|
block = check
|
||||||
|
reply += 'Block: ' + blocks.BLOCKS[block] + ':' + str(block)
|
||||||
|
if blocks.PROPS[block]:
|
||||||
|
reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()])
|
||||||
|
|
||||||
if not reply:
|
if check in blocks.BLOCKS and check in items.ITEM_NAMES:
|
||||||
reply = blocks.BLOCKS[block] + ':' + str(block)
|
reply += ' / '
|
||||||
|
|
||||||
|
if check in items.ITEM_NAMES:
|
||||||
|
item = check
|
||||||
|
reply += 'Item: ' + items.ITEM_NAMES[item] + ':' + str(item)
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
check = data.lower()
|
||||||
|
if not reply and check in self.g.player_names:
|
||||||
|
uuid = self.g.player_names[check]
|
||||||
|
|
||||||
|
for p in self.g.players.values():
|
||||||
|
if p.player_uuid == uuid:
|
||||||
|
player = p
|
||||||
|
break
|
||||||
|
else: # for
|
||||||
|
reply = 'player out of range'
|
||||||
|
|
||||||
|
if not reply:
|
||||||
|
reply += 'Player: '
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for k, v in player.items():
|
||||||
|
try:
|
||||||
|
results.append('{}:{}'.format(k, int(v)))
|
||||||
|
except ValueError:
|
||||||
|
results.append('{}:{}'.format(k, str(v)))
|
||||||
|
|
||||||
|
reply += ', '.join(results)
|
||||||
|
|
||||||
|
|
||||||
################# Specific commands ##########################
|
################# Specific commands ##########################
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Game:
|
||||||
register(self.handle_spawn_living, SpawnLivingEntityPacket)
|
register(self.handle_spawn_living, SpawnLivingEntityPacket)
|
||||||
register(self.handle_entity_position, clientbound.play.EntityPositionDeltaPacket)
|
register(self.handle_entity_position, clientbound.play.EntityPositionDeltaPacket)
|
||||||
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
||||||
|
register(self.handle_entity_look, clientbound.play.EntityLookPacket)
|
||||||
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
||||||
register(self.handle_spawn_player, clientbound.play.SpawnPlayerPacket)
|
register(self.handle_spawn_player, clientbound.play.SpawnPlayerPacket)
|
||||||
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
||||||
|
@ -442,8 +443,14 @@ class Game:
|
||||||
player.x += packet.delta_x / 4096.0
|
player.x += packet.delta_x / 4096.0
|
||||||
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
|
||||||
|
player.yaw = packet.yaw
|
||||||
|
player.pitch = packet.pitch
|
||||||
|
|
||||||
#if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet)
|
def handle_entity_look(self, packet):
|
||||||
|
player = self.g.players.get(packet.entity_id, None)
|
||||||
|
if player:
|
||||||
|
player.yaw = packet.yaw
|
||||||
|
player.pitch = packet.pitch
|
||||||
|
|
||||||
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)
|
||||||
|
@ -493,7 +500,8 @@ class Game:
|
||||||
for action in packet.actions:
|
for action in packet.actions:
|
||||||
if isinstance(action, packet.AddPlayerAction):
|
if isinstance(action, packet.AddPlayerAction):
|
||||||
self.g.player_names[action.uuid] = action.name
|
self.g.player_names[action.uuid] = action.name
|
||||||
self.g.player_names[action.name] = action.uuid # porque no los dos?
|
self.g.player_names[action.name] = action.uuid
|
||||||
|
self.g.player_names[action.name.lower()] = action.uuid # porque no los dos?
|
||||||
|
|
||||||
def handle_update_health(self, packet):
|
def handle_update_health(self, packet):
|
||||||
print(packet)
|
print(packet)
|
||||||
|
|
|
@ -15,6 +15,11 @@ for name, data in JSON_BLOCKS.items():
|
||||||
for state in data['states']:
|
for state in data['states']:
|
||||||
BLOCKS[state['id']] = name.replace('minecraft:', '')
|
BLOCKS[state['id']] = name.replace('minecraft:', '')
|
||||||
|
|
||||||
|
PROPS = {}
|
||||||
|
for name, data in JSON_BLOCKS.items():
|
||||||
|
for state in data['states']:
|
||||||
|
PROPS[state['id']] = state.get('properties', {})
|
||||||
|
|
||||||
BREAK_DISTANCE = 6
|
BREAK_DISTANCE = 6
|
||||||
|
|
||||||
AIR = 0
|
AIR = 0
|
||||||
|
|
|
@ -139,7 +139,15 @@ class SleepWithBedStates:
|
||||||
print('Placing bed')
|
print('Placing bed')
|
||||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||||
self.my_bed = True
|
self.my_bed = True
|
||||||
self.state = self.use_bed
|
self.wait_time = 0.5
|
||||||
|
self.state = self.wait_use
|
||||||
|
|
||||||
|
def wait_use(self):
|
||||||
|
# wait to use the bed
|
||||||
|
if self.wait_time > 0:
|
||||||
|
self.wait_time -= utils.TICK
|
||||||
|
else:
|
||||||
|
self.state = self.use_bed
|
||||||
|
|
||||||
def use_bed(self):
|
def use_bed(self):
|
||||||
w = self.g.world
|
w = self.g.world
|
||||||
|
|
|
@ -280,13 +280,13 @@ class World:
|
||||||
|
|
||||||
def check_bed_occupied(self, bed):
|
def check_bed_occupied(self, bed):
|
||||||
# returns true if the bed is occupied by a player
|
# returns true if the bed is occupied by a player
|
||||||
print('Checking bed occupancy:', bed)
|
bid = self.g.chunks.get_block_at(*bed)
|
||||||
for player in self.g.players.values():
|
if blocks.PROPS[bid]['occupied'] == 'true':
|
||||||
ppos = utils.pint((player.x, player.y, player.z))
|
print('Checking bed occupancy:', bed, '-> occupied')
|
||||||
if utils.phyp(bed, ppos) <= 1 and player.y - int(player.y) == 0.6875:
|
return True
|
||||||
print('Bed is occupied by:', player, self.g.player_names[player.player_uuid])
|
else:
|
||||||
return True
|
print('Checking bed occupancy:', bed, '-> free')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def find_cache_openings(self, area):
|
def find_cache_openings(self, area):
|
||||||
return self.find_bed_openings(area)
|
return self.find_bed_openings(area)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user