<commit_before># Imports, sorted alphabetically.

# Python packages
import random

# Third-party packages
# Nothing for now...

# Modules from this project
from blocks import *


class Trunk(object):
    block = None
    height_range = 4, 8

    def __init__(self, position, block=None, height_range=None):
        if block is not None:
            self.block = block
        if height_range is not None:
            self.height_range = height_range

        x, y, z = position

        self.height = random.randint(*self.height_range)
        self.blocks = {}
        for dy in range(1, self.height):
            self.blocks[(x, y + dy, z)] = self.block


class Tree(object):
    trunk_block = None
    leaf_block = None
    trunk_height_range = 4, 8
    grows_on = grass_block, dirt_block, snowgrass_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.add_block(*item, force=False)

        x, y, z = position
        height = trunk.height
        treetop = y + height

        # Leaves generation
        d = height / 3 + 1
        for xl in range(x - d, x + d):
            dx = abs(xl - x)
            for yl in range(treetop - d, treetop + d):
                for zl in range(z - d, z + d):
                    # Don't replace existing blocks
                    if (xl, yl, zl) in world:
                        continue
                    # Avoids orphaned leaves
                    if not world.has_neighbors((xl, yl, zl),
                                               (cls.trunk_block,
                                                cls.leaf_block)):
                        continue
                    dz = abs(zl - z)
                    # The farther we are (horizontally) from the trunk,
                    # the least leaves we can find.
                    if random.uniform(0, dx + dz) > 0.6:
                        continue
                    world.add_block((xl, yl, zl), cls.leaf_block, force=False)


class OakTree(Tree):
    trunk_block = oakwood_block
    leaf_block = oakleaf_block


class JungleTree(Tree):
    trunk_block = junglewood_block
    leaf_block = jungleleaf_block
    trunk_height_range = 8, 12


class BirchTree(Tree):
    trunk_block = birchwood_block
    leaf_block = birchleaf_block
    trunk_height_range = 5, 7



class Cactus(object):
    trunk_block = cactus_block
    trunk_height_range = 1, 4
    grows_on = sand_block, sandstone_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class TallCactus(object):
    trunk_block = tallcactus_block
    trunk_height_range = 1, 10
    grows_on = sand_block, sandstone_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class WaterMelon(object):
    trunk_block = melon_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block, snowgrass_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Pumpkin(object):
    trunk_block = pumpkin_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block, snowgrass_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class YFlowers(object):
    trunk_block = yflowers_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Potato(object):
    trunk_block = potato_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Carrot(object):
    trunk_block = carrot_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Reed(object):
    trunk_block = yflowers_block
    trunk_height_range = 1, 4
    grows_on = sand_block, dirt_block<commit_msg>fixed nature.py / reeds. reed can grow on reed.<commit_after># Imports, sorted alphabetically.

# Python packages
import random

# Third-party packages
# Nothing for now...

# Modules from this project
from blocks import *


class Trunk(object):
    block = None
    height_range = 4, 8

    def __init__(self, position, block=None, height_range=None):
        if block is not None:
            self.block = block
        if height_range is not None:
            self.height_range = height_range

        x, y, z = position

        self.height = random.randint(*self.height_range)
        self.blocks = {}
        for dy in range(1, self.height):
            self.blocks[(x, y + dy, z)] = self.block


class Tree(object):
    trunk_block = None
    leaf_block = None
    trunk_height_range = 4, 8
    grows_on = grass_block, dirt_block, snowgrass_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.add_block(*item, force=False)

        x, y, z = position
        height = trunk.height
        treetop = y + height

        # Leaves generation
        d = height / 3 + 1
        for xl in range(x - d, x + d):
            dx = abs(xl - x)
            for yl in range(treetop - d, treetop + d):
                for zl in range(z - d, z + d):
                    # Don't replace existing blocks
                    if (xl, yl, zl) in world:
                        continue
                    # Avoids orphaned leaves
                    if not world.has_neighbors((xl, yl, zl),
                                               (cls.trunk_block,
                                                cls.leaf_block)):
                        continue
                    dz = abs(zl - z)
                    # The farther we are (horizontally) from the trunk,
                    # the least leaves we can find.
                    if random.uniform(0, dx + dz) > 0.6:
                        continue
                    world.add_block((xl, yl, zl), cls.leaf_block, force=False)


class OakTree(Tree):
    trunk_block = oakwood_block
    leaf_block = oakleaf_block


class JungleTree(Tree):
    trunk_block = junglewood_block
    leaf_block = jungleleaf_block
    trunk_height_range = 8, 12


class BirchTree(Tree):
    trunk_block = birchwood_block
    leaf_block = birchleaf_block
    trunk_height_range = 5, 7



class Cactus(object):
    trunk_block = cactus_block
    trunk_height_range = 1, 4
    grows_on = sand_block, sandstone_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class TallCactus(object):
    trunk_block = tallcactus_block
    trunk_height_range = 1, 10
    grows_on = sand_block, sandstone_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class WaterMelon(object):
    trunk_block = melon_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block, snowgrass_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Pumpkin(object):
    trunk_block = pumpkin_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block, snowgrass_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class YFlowers(object):
    trunk_block = yflowers_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Potato(object):
    trunk_block = potato_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Carrot(object):
    trunk_block = carrot_block
    trunk_height_range = 1, 2
    grows_on = grass_block, dirt_block

    @classmethod
    def add_to_world(cls, world, position):
        trunk = Trunk(position, block=cls.trunk_block,
                      height_range=cls.trunk_height_range)

        for item in trunk.blocks.items():
            world.init_block(*item)

class Reed(object):
    trunk_block = reed_block
    trunk_height_range = 1, 4
    grows_on = sand_block, dirt_block, reed_block
{'fraction_non_alphanumeric': 0.08269049858889935, 'fraction_numerical': 0.006020696142991533, 'mean_word_length': 2.081449275362319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6141885', 'n_tokens_mistral': 3329, 'n_tokens_neox': 3226, 'n_words': 775}