Exemplo n.º 1
0
    def run(self, time_to_wait=0.4):
        with self.bot.lock:
            self.bot.say('Mining {}. It is {}'.format(
                self.target, self.bot.world.get_block(*self.target)))

            packet = DiggingPacket()
            packet.location = Position(x=self.target[0],
                                       y=self.target[1],
                                       z=self.target[2])
            packet.status = 0
            packet.face = 1
            self.bot.connection.write_packet(packet)

            while self.bot.world.get_block(*self.target) != 0:
                packet = DiggingPacket()
                packet.location = Position(x=self.target[0],
                                           y=self.target[1],
                                           z=self.target[2])
                packet.status = 2
                packet.face = 1
                self.bot.connection.write_packet(packet)

                sleep(0.05)

                if self.bot.break_event.isSet():
                    self.bot.break_event.clear()
                    self.bot.say('Stopped', 1)
                    return

            self.bot.say('Finished mining')

        return True
Exemplo n.º 2
0
 def write(self, socket, compression_threshold=None):
     packet_buffer = PacketBuffer()
     (x, y, z) = self.location
     Position.send(x, y, z, packet_buffer)
     blockData = ((self.blockId << 4) | (self.blockMeta & 0xF))
     VarInt.send(blockData)
     self._write_buffer(socket, packet_buffer, compression_threshold)
Exemplo n.º 3
0
 def write_fields(self, packet_buffer):
     if self.context.protocol_later_eq(351):
         VarInt.send(self.transaction_id, packet_buffer)
     String.send(self.text, packet_buffer)
     if self.context.protocol_earlier_eq(350):
         if self.context.protocol_later_eq(95):
             Boolean.send(self.assume_command, packet_buffer)
         Boolean.send(self.looked_at_block is not None, packet_buffer)
         if self.looked_at_block is not None:
             Position.send(self.looked_at_block, packet_buffer)
Exemplo n.º 4
0
def pianoTuner():
    '''
	x x x x x
	x x x x x
	x x o x x
	x x x x x
	x x x x x
	"x" = noteblock
	"o" = player, standing directly on top of a noteblock
	'''
    origin = {**pos}

    for z in range(5):
        newZ = int(round(origin["z"])) + z - 2
        for x in range(5):
            newX = int(round(origin["x"])) + x - 2

            tune = z * 5 + x
            #print("Setting {}, {} to {}".format(newX, newZ, tune))
            for i in range(tune):
                dj.write_packet(
                    serverbound.play.PlayerBlockPlacementPacket(
                        hand=0,
                        location=Position(x=newX, y=int(pos["y"]) - 1, z=newZ),
                        face=1,
                        x=0.5,
                        y=1.0,
                        z=0.5,
                        inside_block=False))
            time.sleep(0.05)
Exemplo n.º 5
0
 def read(self, file_object):
     self.location = Position.read(file_object)
     blockData = VarInt.read(file_object)
     if self.context.protocol_version >= 347:
         # See comments on MultiBlockChangePacket.OpaqueRecord.
         self.blockStateId = blockData
     else:
         self.blockId = (blockData >> 4)
         self.blockMeta = (blockData & 0xF)
Exemplo n.º 6
0
 def read(self, file_object):
     self.transaction_id = VarInt.read(file_object) \
         if self.context.protocol_later_eq(351) else None
     self.text = String.read(file_object)
     if self.context.protocol_earlier_eq(350):
         self.assume_command = Boolean.read(file_object) \
             if self.context.protocol_later_eq(95) else None
         has_position = Boolean.read(file_object)
         if has_position:
             self.looked_at_block = Position.read(file_object)
Exemplo n.º 7
0
    def test_exceptions(self):
        base_type = Type()
        with self.assertRaises(NotImplementedError):
            base_type.read(None)

        with self.assertRaises(NotImplementedError):
            base_type.read_with_context(None, None)

        with self.assertRaises(NotImplementedError):
            base_type.send(None, None)

        with self.assertRaises(NotImplementedError):
            base_type.send_with_context(None, None, None)

        with self.assertRaises(TypeError):
            Position.read(None)

        with self.assertRaises(TypeError):
            Position.send(None, None)

        empty_socket = PacketBuffer()
        with self.assertRaises(Exception):
            VarInt.read(empty_socket)
Exemplo n.º 8
0
def _playNote(xOffset=0, zOffset=0, tune=None):
    # tune is 0-24 (25 unique noises)
    if tune is not None:
        xOffset = tune % 5
        zOffset = tune // 5

    if xOffset < 0 or xOffset > 24 or zOffset < 0 or zOffset > 24:
        return None

    # -2 because player is standing in the middle of the 5x5 array of noteblocks
    # just like pianoTuner()
    location = Position(x=int(pos["x"] - 2 + xOffset),
                        y=int(pos["y"] - 1),
                        z=int(pos["z"] - 2 + zOffset))
    # start digging
    dj.write_packet(PlayerDiggingPacket(status=0, location=location, face=1))
    # cancel digging
    dj.write_packet(PlayerDiggingPacket(status=1, location=location, face=1))
Exemplo n.º 9
0
 def test_repr(self):
     self.assertEqual(str(Vector(1, 2, 3)), 'Vector(1, 2, 3)')
     self.assertEqual(str(Position(1, 2, 3)), 'Position(1, 2, 3)')
Exemplo n.º 10
0
 def test_repr(self):
     self.assertEqual(str(Vector(1, 2, 3)), "Vector(1, 2, 3)")
     self.assertEqual(str(Position(1, 2, 3)), "Position(1, 2, 3)")
Exemplo n.º 11
0
 def read(self, file_object):
     self.location = Position.read(file_object)
     blockData = VarInt.read(file_object)
     self.blockId = (blockData >> 4)
     self.blockMeta = (blockData & 0xF)