Пример #1
0
    def process(self, coords):
        try:
            metadata = factory.world.sync_get_metadata(coords)
            # Is this sapling ready to grow into a big tree? We use a bit-trick to
            # check.
            if metadata >= 12:
                # Tree time!
                tree = self.trees[metadata % 4](pos=coords)
                tree.prepare(factory.world)
                tree.make_trunk(factory.world)
                tree.make_foliage(factory.world)
                # We can't easily tell how many chunks were modified, so we have
                # to flush all of them.
                factory.flush_all_chunks()
            else:
                # Increment metadata.
                metadata += 4
                factory.world.sync_set_metadata(coords, metadata)
                call = reactor.callLater(
                    randint(self.grow_step_min, self.grow_step_max), self.process,
                    coords)
                self.tracked.add(call)

            # Filter tracked set.
            self.tracked = set(i for i in self.tracked if i.active())
        except ChunkNotLoaded:
            pass
Пример #2
0
    def pre_build_hook(self, player, builddata):
        item, metadata, x, y, z, face = builddata

        # Make sure we're using a bone meal.
        # TODO: We need to check metadata, but it's not implemented yet.
        # Now all dyes will work as a fertilizer.
        if item.slot == items["bone-meal"].slot:
            # Find the block we're aiming for.
            block = yield factory.world.get_block((x,y,z))
            if block == blocks["sapling"].slot:
                # Make sure we can remove it from the inventory.
                if not player.inventory.consume(items["bone-meal"].key, player.equipped):
                    # If not, don't let bone meal get placed.
                    returnValue((False, builddata, False))

                # Select correct treee and coordinates, then build tree.
                tree = self.trees[metadata % 4](pos=(x, y, z))
                tree.prepare(factory.world)
                tree.make_trunk(factory.world)
                tree.make_foliage(factory.world)
                # We can't easily tell how many chunks were modified, so we have
                # to flush all of them.
                factory.flush_all_chunks()

        # Interrupt the processing here.
        returnValue((False, builddata, False))
Пример #3
0
    def pre_build_hook(self, player, builddata):
        item, metadata, x, y, z, face = builddata

        # Make sure we're using a bone meal.
        # TODO: We need to check metadata, but it's not implemented yet.
        # Now all dyes will work as a fertilizer.
        if item.slot == items["bone-meal"].slot:
            # Find the block we're aiming for.
            block = yield factory.world.get_block((x, y, z))
            if block == blocks["sapling"].slot:
                # Make sure we can remove it from the inventory.
                if not player.inventory.consume(items["bone-meal"].key,
                                                player.equipped):
                    # If not, don't let bone meal get placed.
                    returnValue((False, builddata, False))

                # Select correct treee and coordinates, then build tree.
                tree = self.trees[metadata % 4](pos=(x, y, z))
                tree.prepare(factory.world)
                tree.make_trunk(factory.world)
                tree.make_foliage(factory.world)
                # We can't easily tell how many chunks were modified, so we have
                # to flush all of them.
                factory.flush_all_chunks()

        # Interrupt the processing here.
        returnValue((False, builddata, False))
Пример #4
0
    def process(self, coords):
        try:
            metadata = factory.world.sync_get_metadata(coords)
            # Is this sapling ready to grow into a big tree? We use a bit-trick to
            # check.
            if metadata >= 12:
                # Tree time!
                tree = self.trees[metadata % 4](pos=coords)
                tree.prepare(factory.world)
                tree.make_trunk(factory.world)
                tree.make_foliage(factory.world)
                # We can't easily tell how many chunks were modified, so we have
                # to flush all of them.
                factory.flush_all_chunks()
            else:
                # Increment metadata.
                metadata += 4
                factory.world.sync_set_metadata(coords, metadata)
                call = reactor.callLater(
                    randint(self.grow_step_min, self.grow_step_max),
                    self.process, coords)
                self.tracked.add(call)

            # Filter tracked set.
            self.tracked = set(i for i in self.tracked if i.active())
        except ChunkNotLoaded:
            pass