コード例 #1
0
ファイル: tracks.py プロジェクト: JDShu/bravo
 def dig_hook(self, chunk, x, y, z, block):
     """
     Whenever a block is dug out, destroy descending tracks next to the block
     or tracks on top of the block.
     """
     world = factory.world
     # Block coordinates
     x = chunk.x * 16 + x
     z = chunk.z * 16 + z
     for (dx, dy, dz) in ((1, 0, 0), (0, 0, 1), (-1, 0, 0), (0, 0, -1),
                          (0, 1, 0)):
         # Get affected chunk
         coords = (x + dx, y + dy, z + dz)
         if world.get_block(coords) != blocks["tracks"].slot:
             continue
         # Check if descending
         metadata = world.get_metadata(coords)
         if dx == 1 and metadata != ASCEND_N:
             continue
         elif dx == -1 and metadata != ASCEND_S:
             continue
         elif dz == 1 and metadata != ASCEND_E:
             continue
         elif dz == -1 and metadata != ASCEND_W:
             continue
         # Remove track and metadata
         world.destroy(coords)
         # Drop track on ground - needs pixel coordinates
         pixcoords = ((x + dx) * 32 + 16, (y + 1) * 32, (z + dz) * 32 + 16)
         factory.give(pixcoords, (blocks["tracks"].slot, 0), 1)
コード例 #2
0
ファイル: common.py プロジェクト: EntityReborn/bravo
    def chat_command(self, username, parameters):
        if len(parameters) == 0:
            return ("Usage: /{0} {1}".format(self.name, self.usage),)
        elif len(parameters) == 1:
            block = parameters[0]
            count = 1
        elif len(parameters) == 2:
            block = parameters[0]
            count = parameters[1]
        else:
            block = " ".join(parameters[:-1])
            count = parameters[-1]

        player = parse_player(factory, username)
        block = parse_block(block)
        count = parse_int(count)

        # Get a location two blocks in front of the player.
        dest = player.player.location.in_front_of(2)
        dest.y += 1

        coords = int(dest.x * 32), int(dest.y * 32), int(dest.z * 32)

        factory.give(coords, block, count)

        # Return an empty tuple for iteration
        return tuple()
コード例 #3
0
ファイル: tracks.py プロジェクト: JDShu/bravo
 def dig_hook(self, chunk, x, y, z, block):
     """
     Whenever a block is dug out, destroy descending tracks next to the block
     or tracks on top of the block.
     """
     world = factory.world
     # Block coordinates
     x = chunk.x * 16 + x
     z = chunk.z * 16 + z
     for (dx, dy, dz) in ((1, 0, 0), (0, 0, 1), (-1, 0, 0), (0, 0, -1),
                          (0, 1, 0)):
         # Get affected chunk
         coords = (x + dx, y + dy, z + dz)
         if world.get_block(coords) != blocks["tracks"].slot:
             continue
         # Check if descending
         metadata = world.get_metadata(coords)
         if dx == 1 and metadata != ASCEND_N:
             continue
         elif dx == -1 and metadata != ASCEND_S:
             continue
         elif dz == 1 and metadata != ASCEND_E:
             continue
         elif dz == -1 and metadata != ASCEND_W:
             continue
         # Remove track and metadata
         world.destroy(coords)
         # Drop track on ground - needs pixel coordinates
         pixcoords = ((x + dx) * 32 + 16, (y + 1) * 32, (z + dz) * 32 + 16)
         factory.give(pixcoords, (blocks["tracks"].slot, 0), 1)
コード例 #4
0
ファイル: dig_hooks.py プロジェクト: EntityReborn/bravo
    def dig_hook(self, chunk, x, y, z, block):
        """
        Whenever a block is dug out, destroy any torches attached to the
        block, and drop pickups for them.
        """

        world = factory.world
        # Block coordinates
        x = chunk.x * 16 + x
        z = chunk.z * 16 + z
        for dx, dy, dz, dmetadata in (
            (1,  0,  0, 0x1),
            (-1, 0,  0, 0x2),
            (0,  0,  1, 0x3),
            (0,  0, -1, 0x4),
            (0,  1,  0, 0x5)):
            # Check whether the attached block is a torch.
            coords = (x + dx, y + dy, z + dz)
            dblock = yield world.get_block(coords)
            if dblock not in (blocks["torch"].slot,
                blocks["redstone-torch"].slot):
                continue

            # Check whether this torch is attached to the block being dug out.
            metadata = yield world.get_metadata(coords)
            if dmetadata != metadata:
                continue

            # Destroy torches! Mwahahaha!
            world.destroy(coords)

            # Drop torch on ground - needs pixel coordinates
            pixcoords = ((x + dx) * 32 + 16, (y + 1) * 32, (z + dz) * 32 + 16)
            factory.give(pixcoords, blocks[dblock].key, 1)
コード例 #5
0
ファイル: dig_hooks.py プロジェクト: JDShu/bravo
    def dig_hook(self, chunk, x, y, z, block):
        """
        Whenever a block is dug out, destroy any torches attached to the
        block, and drop pickups for them.
        """

        world = factory.world
        # Block coordinates
        x = chunk.x * 16 + x
        z = chunk.z * 16 + z
        for dx, dy, dz, dmetadata in ((1, 0, 0, 0x1), (-1, 0, 0, 0x2),
                                      (0, 0, 1, 0x3), (0, 0, -1,
                                                       0x4), (0, 1, 0, 0x5)):
            # Check whether the attached block is a torch.
            coords = (x + dx, y + dy, z + dz)
            dblock = yield world.get_block(coords)
            if dblock not in (blocks["torch"].slot,
                              blocks["redstone-torch"].slot):
                continue

            # Check whether this torch is attached to the block being dug out.
            metadata = yield world.get_metadata(coords)
            if dmetadata != metadata:
                continue

            # Destroy torches! Mwahahaha!
            world.destroy(coords)

            # Drop torch on ground - needs pixel coordinates
            pixcoords = ((x + dx) * 32 + 16, (y + 1) * 32, (z + dz) * 32 + 16)
            factory.give(pixcoords, blocks[dblock].key, 1)
コード例 #6
0
ファイル: paintings.py プロジェクト: RyanED/bravo
    def use_hook(self, player, target, button):
        # Block coordinates.
        x, y, z = target.location.x, target.location.y, target.location.z

        # Offset coords according to direction. A painting does not
        # occupy a block, therefore we drop the pickup right in front of the
        # block it is attached to.
        face = direction_to_face[target.direction]
        if face == "-x":
            x -= 1
        elif face == "+x":
            x += 1
        elif face == "-z":
            z -= 1
        elif face == "+z":
            z += 1

        # Pixel coordinates.
        coords = (x * 32 + 16, y * 32, z * 32 + 16)

        factory.destroy_entity(target)
        factory.give(coords, (items["paintings"].slot, 0), 1)

        packet = make_packet("destroy", eid=target.eid)
        factory.broadcast(packet)

        # Force the chunk (with its entities) to be saved to disk.
        factory.world.mark_dirty((x, y, z))
コード例 #7
0
    def chat_command(self, username, parameters):
        if len(parameters) == 0:
            return ("Usage: /{0} {1}".format(self.name, self.usage),)
        elif len(parameters) == 1:
            block = parameters[0]
            count = 1
        elif len(parameters) == 2:
            block = parameters[0]
            count = parameters[1]
        else:
            block = " ".join(parameters[:-1])
            count = parameters[-1]

        player = parse_player(factory, username)
        block = parse_block(block)
        count = int(count)

        # Get a location two blocks in front of the player.
        dest = player.player.location.in_front_of(2)
        dest.y += 1

        coords = int(dest.x * 32), int(dest.y * 32), int(dest.z * 32)

        factory.give(coords, block, count)

        # Return an empty tuple for iteration
        return tuple()
コード例 #8
0
ファイル: dig_hooks.py プロジェクト: EntityReborn/bravo
    def dig_hook(self, chunk, x, y, z, block):
        if block.drop == blocks["air"].slot:
            return

        # Block coordinates...
        x = chunk.x * 16 + x
        z = chunk.z * 16 + z

        # ...and pixel coordinates.
        coords = (x * 32 + 16, y * 32, z * 32 + 16)

        # Drop a block, according to the block's drop ratio. It's important to
        # remember that, for most blocks, the drop ratio is 1, so we should
        # have a short-circuit for those cases.
        if block.ratio == 1 or random.random() <= block.ratio:
            factory.give(coords, (block.drop, 0), block.quantity)
コード例 #9
0
ファイル: dig_hooks.py プロジェクト: JDShu/bravo
    def dig_hook(self, chunk, x, y, z, block):
        if block.drop == blocks["air"].key:
            return

        # Block coordinates...
        x = chunk.x * 16 + x
        z = chunk.z * 16 + z

        # ...and pixel coordinates.
        coords = (x * 32 + 16, y * 32, z * 32 + 16)

        # Drop a block, according to the block's drop ratio. It's important to
        # remember that, for most blocks, the drop ratio is 1, so we should
        # have a short-circuit for those cases.
        if block.ratio == 1 or random.random() <= block.ratio:
            factory.give(coords, block.drop, block.quantity)
コード例 #10
0
ファイル: window_hooks.py プロジェクト: JDShu/bravo
def drop_items(location, items, y_offset = 0):
    """
    Loop over items and drop all of them

    :param location: Location() or tuple (x, y, z)
    :param items: list of items
    """

    # XXX why am I polymorphic? :T
    if type(location) == Location:
        x, y, z = location.x, location.y, location.z
    else:
        x, y, z = location
    y += y_offset
    coords = (int(x * 32) + 16, int(y * 32) + 16, int(z * 32) + 16)
    for item in items:
        if item is None:
            continue
        factory.give(coords, (item[0], item[1]), item[2])
コード例 #11
0
    def use_hook(self, player, target, button):
        # Block coordinates.
        x, y, z = target.location.x, target.location.y, target.location.z

        # Offset coords according to direction. A painting does not
        # occupy a block, therefore we drop the pickup right in front of the
        # block it is attached to.
        face = direction_to_face[target.direction]
        x, y, z = adjust_coords_for_face((x, y, z), face)

        # Pixel coordinates.
        coords = (x * 32 + 16, y * 32, z * 32 + 16)

        factory.destroy_entity(target)
        factory.give(coords, (items["paintings"].slot, 0), 1)

        packet = make_packet("destroy", eid=target.eid)
        factory.broadcast(packet)

        # Force the chunk (with its entities) to be saved to disk.
        factory.world.mark_dirty((x, y, z))