def __init__(self, packet_handlers = []): packet_handlers += [ handlers.Connection(self), handlers.PositionLook(self), handlers.Blocks(self), handlers.Slot(self), handlers.Window(self) ] self.__socket = net.mcsocket() self.__sender = _Sender(self.__socket) self.__receiver = _Receiver(self.__socket, packet_handlers) self.__workers = [ self.__receiver, self.__sender, ] self.on_ground = True self.position = {"x": None, "y": None, "z": None} self.look = {"yaw": None, "pitch": None} self.entities = [] self.inventory = [] self.holds = [] self.window_id = 0 self.window_type = -1 self.other_size = 0 self.main_inventory = None self.held_slot = 0 self.map = map.World() # self._slots = None self._mouse_hold = {"id": -1} self._tid = 1
def ping(host, port): socket = net.mcsocket() socket.connect((host, port)) socket.sendmc(server_list_ping()) packet = socket.recvmc() if packet.name()=="disconnect": description, user_num, slot_num = packet.reason.split(u"\xa7") print description, "{}/{}".format(user_num, slot_num) else: raise ValueError