Compare commits
No commits in common. "b754a4746da8c4aba4a8ccbfa9cb5483cfd28fcb" and "beb4c31f5eb7bab420e072d541c0755e57e29c10" have entirely different histories.
b754a4746d
...
beb4c31f5e
2
data.py
2
data.py
|
@ -3,7 +3,7 @@ from munch import Munch
|
|||
|
||||
import minecraft_data
|
||||
|
||||
mcd = minecraft_data('1.16.4')
|
||||
mcd = minecraft_data('1.16.2')
|
||||
|
||||
with open('mcdata/registries.json') as f:
|
||||
DATA = json.load(f)
|
||||
|
|
119
game.py
119
game.py
|
@ -20,7 +20,7 @@ from protocol.packets import (
|
|||
ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket,
|
||||
ClientWindowConfirmationPacket, EntityMetadataPacket,
|
||||
SpawnLivingEntityPacket, EntityPositionRotationPacket, DestroyEntitiesPacket,
|
||||
EntityActionPacket, EntityTeleport,
|
||||
EntityActionPacket, SpawnPlayerPacket,
|
||||
)
|
||||
|
||||
from protocol.types import Slot
|
||||
|
@ -97,35 +97,30 @@ class MCWorld:
|
|||
# crawl to the bottom log
|
||||
while self.block_at(*utils.padd(log, path.BLOCK_BELOW)) in blocks.LOG_IDS:
|
||||
log = utils.padd(log, path.BLOCK_BELOW)
|
||||
base = log
|
||||
|
||||
if base in found_trees:
|
||||
continue
|
||||
|
||||
# make sure we are on the ground
|
||||
if self.block_at(*utils.padd(base, path.BLOCK_BELOW)) in blocks.NON_SOLID_IDS:
|
||||
if self.block_at(*utils.padd(log, path.BLOCK_BELOW)) in blocks.NON_SOLID_IDS:
|
||||
continue
|
||||
|
||||
# crawl to the top log to count and check leaves
|
||||
# crawl to the top log to count
|
||||
log_count = 1
|
||||
good_leaves = False
|
||||
while self.block_at(*utils.padd(log, path.BLOCK_ABOVE)) in blocks.LOG_IDS:
|
||||
log = utils.padd(log, path.BLOCK_ABOVE)
|
||||
log_count += 1
|
||||
|
||||
for offset in path.CHECK_DIRECTIONS:
|
||||
if self.block_at(*utils.padd(log, offset)) not in blocks.LEAF_IDS:
|
||||
break
|
||||
else: # for:
|
||||
good_leaves = True
|
||||
|
||||
# make sure it's a good tree
|
||||
if not good_leaves or log_count < 3:
|
||||
if self.block_at(*utils.padd(log, path.BLOCK_ABOVE)) not in blocks.LEAF_IDS or log_count < 3:
|
||||
continue
|
||||
|
||||
found_trees.append(base)
|
||||
# crawl back to the bottom log
|
||||
while self.block_at(*utils.padd(log, path.BLOCK_BELOW)) in blocks.LOG_IDS:
|
||||
log = utils.padd(log, path.BLOCK_BELOW)
|
||||
|
||||
yield base
|
||||
if log in found_trees:
|
||||
continue
|
||||
found_trees.append(log)
|
||||
|
||||
yield log
|
||||
|
||||
def find_tree_openings(self, tree):
|
||||
# returns coords in a cardinal direction where we can stand by tree
|
||||
|
@ -330,10 +325,8 @@ class Game:
|
|||
register(self.handle_entity_position, clientbound.play.EntityPositionDeltaPacket)
|
||||
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
||||
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
||||
register(self.handle_spawn_player, clientbound.play.SpawnPlayerPacket)
|
||||
register(self.handle_spawn_player, SpawnPlayerPacket)
|
||||
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
||||
register(self.handle_player_list, clientbound.play.PlayerListItemPacket)
|
||||
register(self.handle_entity_teleport, EntityTeleport)
|
||||
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket)
|
||||
|
||||
#register(self.handle_packet, Packet, early=True)
|
||||
|
@ -461,7 +454,7 @@ class Game:
|
|||
reply = data
|
||||
|
||||
if command == 'pos':
|
||||
reply = str(utils.pint(self.g.pos))[1:-1] + ', ' + self.g.dimension
|
||||
reply = str(utils.pint(self.g.pos))[1:-1]
|
||||
|
||||
if command == 'afk':
|
||||
if not self.g.afk:
|
||||
|
@ -519,14 +512,6 @@ class Game:
|
|||
if command == 'loaded':
|
||||
reply = str(self.g.chunks.get_loaded_area())
|
||||
|
||||
if command == 'players':
|
||||
if data == 'clear':
|
||||
self.g.players = {}
|
||||
reply = 'ok'
|
||||
else:
|
||||
for k, v in self.g.players.items():
|
||||
print(str(k) + ':', v, self.g.player_names[v.player_uuid])
|
||||
|
||||
if command == 'objects':
|
||||
if data == 'clear':
|
||||
self.g.objects = {}
|
||||
|
@ -583,11 +568,6 @@ class Game:
|
|||
else:
|
||||
reply = '/afk'
|
||||
|
||||
if command == 'tree':
|
||||
pos = utils.pint(self.g.pos)
|
||||
tree = next(self.g.world.find_trees(pos, 50))
|
||||
reply = str(tree)[1:-1]
|
||||
|
||||
|
||||
################# Specific commands ##########################
|
||||
if for_me:
|
||||
|
@ -692,37 +672,6 @@ class Game:
|
|||
self.g.job.state = self.g.job.fill_blocks
|
||||
reply = 'filling ' + str(utils.pvolume(coord1, coord2)) + ' with ' + blocks.BLOCKS[block]
|
||||
|
||||
if command == 'here':
|
||||
try:
|
||||
sender_uuid = self.g.player_names[sender]
|
||||
except KeyError:
|
||||
reply = 'can\'t find your uuid'
|
||||
|
||||
if not reply:
|
||||
for p in self.g.players.values():
|
||||
if p.player_uuid == sender_uuid:
|
||||
player = p
|
||||
break
|
||||
else: # for
|
||||
reply = 'can\'t find you'
|
||||
|
||||
if not reply:
|
||||
pos = utils.pint(self.g.pos)
|
||||
goal = utils.pint((p.x, p.y, p.z))
|
||||
start = time.time()
|
||||
navpath = self.g.world.path_to_place(pos, goal)
|
||||
|
||||
if navpath:
|
||||
self.g.path = navpath
|
||||
if self.g.job:
|
||||
self.g.job.stop()
|
||||
print(len(navpath))
|
||||
print(navpath)
|
||||
print(round(time.time() - start, 3), 'seconds')
|
||||
reply = 'ok'
|
||||
else:
|
||||
reply = 'no path'
|
||||
|
||||
|
||||
################# Authorized commands ##########################
|
||||
if authed:
|
||||
|
@ -918,7 +867,7 @@ class Game:
|
|||
print(packet)
|
||||
self.g.players[packet.entity_id] = Munch(
|
||||
entity_id=packet.entity_id,
|
||||
player_uuid=packet.player_UUID,
|
||||
player_uuid=packet.player_uuid,
|
||||
x=packet.x,
|
||||
y=packet.y,
|
||||
z=packet.z,
|
||||
|
@ -987,14 +936,6 @@ class Game:
|
|||
mob.y += packet.delta_y / 4096.0
|
||||
mob.z += packet.delta_z / 4096.0
|
||||
|
||||
player = self.g.players.get(packet.entity_id, None)
|
||||
if player:
|
||||
player.x += packet.delta_x / 4096.0
|
||||
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)
|
||||
|
||||
def handle_entity_position_rotation(self, packet):
|
||||
mob = self.g.mobs.get(packet.entity_id, None)
|
||||
if mob:
|
||||
|
@ -1002,29 +943,6 @@ class Game:
|
|||
mob.y += packet.delta_y / 4096.0
|
||||
mob.z += packet.delta_z / 4096.0
|
||||
|
||||
player = self.g.players.get(packet.entity_id, None)
|
||||
if player:
|
||||
player.x += packet.delta_x / 4096.0
|
||||
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)
|
||||
|
||||
def handle_entity_teleport(self, packet):
|
||||
mob = self.g.mobs.get(packet.entity_id, None)
|
||||
if mob:
|
||||
mob.x = packet.x
|
||||
mob.y = packet.y
|
||||
mob.z = packet.z
|
||||
|
||||
player = self.g.players.get(packet.entity_id, None)
|
||||
if player:
|
||||
player.x = packet.x
|
||||
player.y = packet.y
|
||||
player.z = packet.z
|
||||
|
||||
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)
|
||||
if obj:
|
||||
|
@ -1039,8 +957,6 @@ class Game:
|
|||
del self.g.objects[eid]
|
||||
if eid in self.g.mobs:
|
||||
del self.g.mobs[eid]
|
||||
if eid in self.g.players:
|
||||
del self.g.players[eid]
|
||||
|
||||
def leave_bed(self):
|
||||
packet = EntityActionPacket()
|
||||
|
@ -1053,11 +969,6 @@ class Game:
|
|||
print(packet)
|
||||
self.g.dimension = packet.world_name.replace('minecraft:', '')
|
||||
|
||||
def handle_player_list(self, packet):
|
||||
for action in packet.actions:
|
||||
if isinstance(action, packet.AddPlayerAction):
|
||||
self.g.player_names[action.uuid] = action.name
|
||||
self.g.player_names[action.name] = action.uuid # porque no los dos?
|
||||
|
||||
def tick(self):
|
||||
if self.g.breaking:
|
||||
|
|
1
main.py
1
main.py
|
@ -24,7 +24,6 @@ g.inv = {}
|
|||
g.objects = {}
|
||||
g.mobs = {}
|
||||
g.players = {}
|
||||
g.player_names = {}
|
||||
g.window = None
|
||||
g.job = None
|
||||
g.correction_count = 0
|
||||
|
|
|
@ -11,13 +11,20 @@ def get_packets(old_get_packets):
|
|||
mc_packets.add(packets.AcknowledgePlayerDiggingPacket)
|
||||
mc_packets.add(packets.BlockBreakAnimationPacket)
|
||||
mc_packets.add(packets.SetSlotPacket)
|
||||
#mc_packets.add(packets.PlayerDiggingPacket)
|
||||
#mc_packets.add(packets.PickItemPacket)
|
||||
#mc_packets.add(packets.HeldItemChangePacket)
|
||||
mc_packets.add(packets.OpenWindowPacket)
|
||||
#mc_packets.add(packets.CloseWindowPacket)
|
||||
#mc_packets.add(packets.ClickWindowPacket)
|
||||
mc_packets.add(packets.ClientWindowConfirmationPacket)
|
||||
#mc_packets.add(packets.ServerWindowConfirmationPacket)
|
||||
mc_packets.add(packets.EntityMetadataPacket)
|
||||
mc_packets.add(packets.SpawnLivingEntityPacket)
|
||||
mc_packets.add(packets.EntityPositionRotationPacket)
|
||||
mc_packets.add(packets.DestroyEntitiesPacket)
|
||||
mc_packets.add(packets.EntityTeleport)
|
||||
#mc_packets.add(packets.EntityActionPacket)
|
||||
mc_packets.add(packets.SpawnPlayerPacket)
|
||||
|
||||
|
||||
return mc_packets
|
||||
|
|
|
@ -330,23 +330,6 @@ class SpawnLivingEntityPacket(Packet):
|
|||
{'velocity_z': Short},
|
||||
]
|
||||
|
||||
class EntityTeleport(Packet):
|
||||
# Sent by the server when an entity moves more than 8 blocks
|
||||
# https://wiki.vg/Protocol#Entity_Teleport
|
||||
|
||||
id = 0x56
|
||||
packet_name = 'entity teleport'
|
||||
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
{'x': Double},
|
||||
{'y': Double},
|
||||
{'z': Double},
|
||||
{'yaw': Angle},
|
||||
{'pitch': Angle},
|
||||
{'on_ground': Boolean},
|
||||
]
|
||||
|
||||
class EntityPositionRotationPacket(Packet):
|
||||
# Sent by the server when an entity rotates and moves
|
||||
# https://wiki.vg/Protocol#Entity_Position_and_Rotation
|
||||
|
@ -391,3 +374,19 @@ class EntityActionPacket(Packet):
|
|||
{'action_id': VarInt},
|
||||
{'jump_boost': VarInt},
|
||||
]
|
||||
|
||||
class SpawnPlayerPacket(Packet):
|
||||
# https://wiki.vg/Protocol#Spawn_Player
|
||||
|
||||
id = 0x04
|
||||
packet_name = 'spawn player'
|
||||
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
{'player_uuid': UUID},
|
||||
{'x': Double},
|
||||
{'y': Double},
|
||||
{'z': Double},
|
||||
{'yaw': Angle},
|
||||
{'pitch': Angle},
|
||||
]
|
||||
|
|
|
@ -1,40 +1,23 @@
|
|||
appdirs==1.4.3
|
||||
astar==0.92
|
||||
CacheControl==0.12.6
|
||||
certifi==2020.6.20
|
||||
cffi==1.14.2
|
||||
chardet==3.0.4
|
||||
click==7.1.2
|
||||
colorama==0.4.3
|
||||
contextlib2==0.6.0
|
||||
cryptography==3.1
|
||||
distlib==0.3.0
|
||||
distro==1.4.0
|
||||
Flask==1.1.2
|
||||
html5lib==1.0.1
|
||||
idna==2.10
|
||||
ipaddr==2.2.0
|
||||
itsdangerous==1.1.0
|
||||
Jinja2==2.11.2
|
||||
lockfile==0.12.2
|
||||
MarkupSafe==1.1.1
|
||||
minecraft-data==2.70.1
|
||||
msgpack==0.6.2
|
||||
minecraft-data==2.67.0
|
||||
munch==2.5.0
|
||||
packaging==20.3
|
||||
panda3d==1.10.6.post2
|
||||
pathtools==0.1.2
|
||||
pep517==0.8.2
|
||||
progress==1.5
|
||||
pycparser==2.20
|
||||
pyCraft==0.7.0
|
||||
pyCraft @ git+https://github.com/ammaraskar/pyCraft.git@2813d02ae7fb8182c3e5227a73de2240b09878d9
|
||||
PyNBT==3.0.0
|
||||
pyparsing==2.4.6
|
||||
pytoml==0.1.21
|
||||
requests==2.24.0
|
||||
retrying==1.3.3
|
||||
six==1.15.0
|
||||
urllib3==1.25.10
|
||||
watchdog==0.10.3
|
||||
webencodings==0.5.1
|
||||
Werkzeug==1.0.1
|
||||
|
|
Loading…
Reference in New Issue
Block a user