예제 #1
0
    def light(self, lower: int = 0, upper: int = 15) -> SpawnBuilder:
        """Overright the light level of spawns created in this block."""
        if self._current_spawn:
            raise RuntimeError(
                "cannot change light level once a spawn is in progress")

        self._light = Range(lower, upper)
        try:
            yield self
        finally:
            self._light = None
예제 #2
0
    def altitude(self, lower: int = 0, upper: int = 256) -> SpawnBuilder:
        """Override the altitude of spawns created in this block."""
        if self._current_spawn:
            raise RuntimeError(
                "cannot change altitude once a spawn is in progress")

        self._altitude = Range(lower, upper)
        try:
            yield self
        finally:
            self._altitude = None
예제 #3
0
    def add(self, creature: Creature):
        """Add a new spawn to the list, applying any overrides currently in effect."""
        if self._current_spawn is None:
            raise RuntimeError("cannot add a creature without a spawn")

        active_periods = self._active_periods
        if active_periods is None:
            active_periods = [Range(0, 24000)]

        self._current_spawn.add_creature(
            creature.with_active_periods(*self._active_periods))
예제 #4
0
    def __init__(
        self,
        location: Location,
        *creatures: Iterable[Creature],
        light: Optional[Range] = None,
        limit: Optional[int] = None,
        cycle_length: Optional[int] = None,
        altitude: Optional[Range] = None,
    ):
        """
        Create a new spawn.

        Creatures from the given list are randomly spawned at the given rate until the limit is reached. The creatures
        are spawned in accordance with their group sizes, one group at a time, until that limit is reached.  As
        creatures disappear or are killed, they will be replenished at the given rate.

        Arguments:
            location: a Location where this spawn occurs
            creatures: the list of creatures to be spawned
            light: the amount of light permitted for this spawn
            limit: the maximum number of creatures which spawn will create at once. If none is given, then the upper
                limit of the largest creature group will be used
            cycle_length: the approximate number of seconds it should take a creature with a rarity of 1 to appear.
                Creatures with rarity `r` will appear in `1/r` this amount of time.

        """
        self.altitude = altitude
        self.creatures = creatures
        self.cycle_length = cycle_length if cycle_length is not None else DEFAULT_CYCLE_LENGTH
        self.light = light
        self.limit = limit
        self.location = location

        if self.altitude is None:
            self.altitude = Range(0, 256)

        if self.light is None:
            self.light = Range(0, 15)
예제 #5
0
    def __init__(
        self,
        entity_id: str,
        group_size: Range = None,
        active_periods: Iterable[Range] = None,
        rarity: int = 1,
        groups_allowed: int = 1,
        loot_list: Iterable[Loot] = None,
    ):
        """
        Define a new creature group.

        Arguments:
            entity_id: a str containing the in-game id of the entity (e.g., "minecraft:cow")
            group_size: a Range giving how many entities may appear in a single group
            active_periods: a list of Ranges giving the times of day when this creature is active (0=dawn, 12000=sunset)
            rarity: the chances out of 1000 that this creature will be select spawn on any tick. If the sum of rarity
                scores in a single spawn point exceeds 1000, the relative rarity of each creature will be weighed
                against the others when choosing the next group to spawn each tick
            groups_allowed: the number of filled groups which should be permitted to spawn at once
        """
        self.active_periods = active_periods
        self.entity_id = entity_id
        self.group_size = group_size
        self.groups_allowed = groups_allowed
        self.loot_list = loot_list
        self.rarity = rarity

        if self.active_periods is None:
            self.active_periods = [Range(0, 24000)]

        self.active_periods = [r.clone() for r in self.active_periods]

        if self.group_size is None:
            self.group_size = Range(1, 1)

        self.group_size = self.group_size.clone()
예제 #6
0
    def __init__(
        self,
        biomes: BiomeSet,
        altitude: Range = None,
        dimension: Optional[int] = None,
        structure: str = None,
        weather: str = None,
    ):
        """Create a new spawn location."""
        self.altitude = altitude
        self.biomes = biomes
        self.dimension = dimension
        self.structure = structure
        self.weather = weather

        if self.altitude is None:
            self.altitude = Range(0, 256)
예제 #7
0
    def __init__(
        self,
        item_id: str,
        output_range: Optional[Range] = None,
        chance: Optional[float] = None,
    ):
        """Create a new crop yield."""
        super().__init__()

        if output_range is None:
            output_range = Range(1, 1)

        if chance is None:
            chance = 0.9

        self.item_id = item_id
        self.output_range = output_range
        self.chance = chance
예제 #8
0
    def __init__(self, mod: Mod, plant_id: str):
        """Create a new plant."""
        self.id = plant_id
        self.mod = mod

        self.growth_bonus = 0.025
        self.growth_chance = 0.9
        self.light_range = Range(10, 16)
        self.soils = ["farmland_soil"]

        self.crop_yield = None
        self.name = None
        self.parent_a = None
        self.parent_b = None
        self.path = None
        self.qualified_id = None
        self.seed_item_id = None
        self.seed_name = None
        self.seed_texture = None
예제 #9
0
"""Define the entity generation settings for Brunel 3."""

from packconfig import Range
from packconfig.mobgen import BiomeSet, ConfigFileSet, Loot, SpawnBuilder, Creature, Location
from packconfig.oregen import Ore, OreList
from packconfig.oregen.data import vanilla as mc

# Activity Ranges ######################################################################################################

ANY = [Range(0, 24000)]
DAY = [Range(23500, 24000), Range(0, 12500)]
NIGHT = [Range(11500, 24000), Range(0, 500)]
DAWN = [Range(11000, 13000)]
DUSK = [Range(0, 1000), Range(23000, 24000)]

TWILIGHT = DAWN + DUSK

# Group Size Presets ###################################################################################################

LONER = Range(1, 1)
PAIR = Range(1, 2)
CLUSTER = Range(2, 3)
TROOP = Range(3, 6)
HERD = Range(6, 10)
SWARM = Range(10, 20)

# Spawn Block Sets #####################################################################################################

AERIAL = OreList(mc.air)
AQUATIC = OreList(mc.water)
CARPETED = OreList(mc.grass, mc.dirt, mc.sand)
예제 #10
0
class Creature(object):
    """Creature defines the placement of a cluster of a single kind of creature."""

    def __init__(
        self,
        entity_id: str,
        group_size: Range = None,
        active_periods: Iterable[Range] = None,
        rarity: int = 1,
        groups_allowed: int = 1,
        loot_list: Iterable[Loot] = None,
    ):
        """
        Define a new creature group.

        Arguments:
            entity_id: a str containing the in-game id of the entity (e.g., "minecraft:cow")
            group_size: a Range giving how many entities may appear in a single group
            active_periods: a list of Ranges giving the times of day when this creature is active (0=dawn, 12000=sunset)
            rarity: the chances out of 1000 that this creature will be select spawn on any tick. If the sum of rarity
                scores in a single spawn point exceeds 1000, the relative rarity of each creature will be weighed
                against the others when choosing the next group to spawn each tick
            groups_allowed: the number of filled groups which should be permitted to spawn at once
        """
        self.active_periods = active_periods
        self.entity_id = entity_id
        self.group_size = group_size
        self.groups_allowed = groups_allowed
        self.loot_list = loot_list
        self.rarity = rarity

        if self.active_periods is None:
            self.active_periods = [Range(0, 24000)]

        self.active_periods = [r.clone() for r in self.active_periods]

        if self.group_size is None:
            self.group_size = Range(1, 1)

        self.group_size = self.group_size.clone()

    # Properties ###################################################################################

    @property
    def is_always_active(self) -> bool:
        """Return whether this creature is active at all times of day."""
        if len(self.active_periods) == 0:
            return True

        if len(self.active_periods) == 1:
            period = self.active_periods[0]
            if period.lower == 0 and period.upper == 24000:
                return True

        return False

    @property
    def max_individuals(self) -> int:
        """Get the maximum number of individuals which should be permitted based upon group size and count."""
        return self.group_size.upper * self.groups_allowed

    # Public Methods ###############################################################################

    def clone(self) -> Creature:
        """Return a new Creature with a different rarity score."""
        return Creature(
            active_periods=self.active_periods,
            entity_id=self.entity_id,
            group_size=self.group_size,
            groups_allowed=self.groups_allowed,
            loot_list=self.loot_list,
            rarity=self.rarity,
        )

    def configure(
        self,
        rarity: Optional[int] = None,
        groups_allowed: Optional[int] = None,
        group_size: Optional[Range] = None,
    ):
        """Create a copy of this creature with a set of changes."""
        result = self.clone()
        result.group_size = group_size if group_size is not None else self.group_size
        result.groups_allowed = groups_allowed if groups_allowed is not None else self.groups_allowed
        result.rarity = rarity if rarity is not None else self.rarity
        return result

    def with_active_periods(self, *active_periods: Iterable[Range]) -> Creature:
        """Create a new creature with a different set of activity periods."""
        result = self.clone()
        result.active_periods = [r.clone() for r in active_periods]
        return result

    def with_group_size(self, lower: int = 1, upper: int = 1) -> Creature:
        """Return a new Creature with a different group size."""
        result = self.clone()
        result.group_size = Range(lower, upper)
        return result

    def with_groups_allowed(self, groups_allowed: int) -> Creature:
        """Return a new creature with a different number of groups allowed."""
        result = self.clone()
        result.groups_allowed = groups_allowed
        return result

    def with_rarity(self, rarity: int) -> Creature:
        """Return a new Creature with a different rarity score."""
        result = self.clone()
        result.rarity
        return result
예제 #11
0
 def with_group_size(self, lower: int = 1, upper: int = 1) -> Creature:
     """Return a new Creature with a different group size."""
     result = self.clone()
     result.group_size = Range(lower, upper)
     return result