Example #1
0
    def chat_command(self, username, parameters):
        data = self.factory.world.serializer.load_plugin_data("warps")
        warps = get_locations(data)
        if len(parameters) == 0:
            yield "Usage: /warp <warpname>"
            return
        location = parameters[0]
        if location in warps:
            yield "Teleporting you to %s" % location
            protocol = self.factory.protocols[username]

            # An explanation might be necessary.
            # We are changing the location of the player, but we must
            # immediately send a new location packet in order to force the
            # player to appear at the new location. However, before we can do
            # that, we need to get the chunk loaded for them. This ends up
            # being the same sequence of events as the initial chunk and
            # location setup, so we call send_initial_chunk_and_location()
            # instead of update_location().
            l = protocol.player.location
            x, y, z, yaw, pitch = warps[location]
            l.pos = Position.from_player(x, y, z)
            l.ori = Orientation.from_degs(yaw, pitch)
            protocol.send_initial_chunk_and_location()
            yield "Teleportation successful!"
        else:
            yield "No warp location %s available" % parameters
Example #2
0
    def load_player(self, username):
        fp = self.folder.child("players").child("%s.dat" % username)
        if not fp.exists():
            raise SerializerReadException("%r doesn't exist!" % username)

        tag = self._read_tag(fp)
        if not tag:
            raise SerializerReadException("%r (in %s) is corrupt!" %
                    (username, fp.path))

        try:
            player = Player(username=username)
            x, y, z = [i.value for i in tag["Pos"].tags]
            player.location.pos = Position(x, y, z)

            yaw = tag["Rotation"].tags[0].value
            pitch = tag["Rotation"].tags[1].value
            player.location.ori = Orientation.from_degs(yaw, pitch)

            if "Inventory" in tag:
                self._load_inventory_from_tag(player.inventory,
                        tag["Inventory"])
        except KeyError, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (player, e))
Example #3
0
    def orientation(self, container):
        """
        Hook for orientation packets.
        """

        self.grounded(container.grounded)

        old_orientation = self.location.ori
        orientation = Orientation.from_degs(container.orientation.rotation,
                container.orientation.pitch)
        self.location.ori = orientation

        if old_orientation != orientation:
            self.orientation_changed()
Example #4
0
    def _load_entity_from_tag(self, tag):
        position = tag["Pos"].tags
        rotation = tag["Rotation"].tags
        location = Location()
        location.pos = Position(position[0].value, position[1].value, position[2].value)
        location.ori = Orientation.from_degs(rotation[0].value, rotation[1].value)

        location.grounded = bool(tag["OnGround"])

        entity = entities[tag["id"].value](location=location)

        self._entity_loaders[entity.name](entity, tag)

        return entity
Example #5
0
    def chat_command(self, username, parameters):
        data = self.factory.world.serializer.load_plugin_data("homes")
        homes = get_locations(data)

        protocol = self.factory.protocols[username]
        l = protocol.player.location
        if username in homes:
            yield "Teleporting %s home" % username
            x, y, z, yaw, pitch = homes[username]
        else:
            yield "Teleporting %s to spawn" % username
            x, y, z = self.factory.world.level.spawn
            yaw, pitch = 0, 0

        l.pos = Position.from_player(x, y, z)
        l.ori = Orientation.from_degs(yaw, pitch)
        protocol.send_initial_chunk_and_location()
        yield "Teleportation successful!"
Example #6
0
 def test_to_fracs_rounding(self):
     o = Orientation.from_degs(180, 0)
     self.assertEqual(o.to_fracs(), (127, 0))
Example #7
0
 def test_to_degs_rounding(self):
     o = Orientation(1, 1)
     self.assertEqual(o.to_degs(), (57, 57))
Example #8
0
 def test_from_degs_wrap_negative(self):
     o = Orientation.from_degs(-90, 0)
     self.assertAlmostEqual(o.theta, math.pi * 3 / 2)
Example #9
0
 def test_from_degs_wrap(self):
     o = Orientation.from_degs(450, 0)
     self.assertAlmostEqual(o.theta, math.pi / 2)
Example #10
0
 def test_from_degs(self):
     o = Orientation.from_degs(90, 180)
     self.assertAlmostEqual(o.theta, math.pi / 2)
     self.assertAlmostEqual(o.phi, math.pi)
Example #11
0
    def test_in_front_of_yaw(self):
        self.l.ori = Orientation.from_degs(90, 0)
        other = self.l.in_front_of(1)

        self.assertEqual(other.pos.x, -32)
        self.assertEqual(other.pos.z, 0)