class Advancement(MCDict):
    display: Display = mc_basic('display', Display)
    parent: str = mc_basic('parent', str)
    criteria: Dict[str, Criteria] = mc_dict('criteria', Criteria.create)
    requirements: List[List[str]] = mc_list('requirements', list)
    rewards: Rewards = mc_basic('rewards', Rewards)

    @staticmethod
    def populate(criteria: Dict[str, Criteria],
                 display: Display = None,
                 parent: str = None,
                 requirements: List[str] = None,
                 rewards: Rewards = None):
        adv = Advancement()
        adv.criteria = criteria
        if display is not None:
            adv.display = display
        if parent is not None:
            adv.parent = parent
        if requirements is not None:
            adv.requirements = requirements
        if rewards is not None:
            adv.rewards = rewards

        return adv
예제 #2
0
class Icon(MCDict):
    item: str = mc_basic('item', str)
    nbt: str = mc_basic('nbt', str)

    @staticmethod
    def populate(item: str = ''):
        icon = Icon()
        icon.item = item

        return icon
예제 #3
0
class Display(MCDict):
    icon: Icon = mc_basic('icon', Icon)
    title: TextComponent = mc_basic('title', TextComponent)
    frame: eFrame = mc_basic('frame', eFrame)
    background: str = mc_basic('background', str)
    description: TextComponent = mc_basic('description', TextComponent)
    show_toast: bool = mc_basic('show_toast', bool)
    announce_to_chat: bool = mc_basic('announce_to_chat', bool)
    hidden: bool = mc_basic('hidden', bool)

    @staticmethod
    def populate(icon: str,
                 title: str,
                 description: str,
                 frame: str = None,
                 background: str = None,
                 show: bool = None,
                 announce: bool = None,
                 hidden: bool = None):
        display = Display()
        display.icon = Icon.populate(icon)
        display.title = TextComponent.populate(title)
        display.description = TextComponent.populate(description)
        if frame is not None:
            display.frame = eFrame(frame)
        if background is not None:
            display.background = background
        if show is not None:
            display.show_toast = show
        if announce is not None:
            display.announce_to_chat = announce
        if hidden is not None:
            display.hidden = hidden

        return display
class Entry(MCDict, MCInteractable):
    conditions: List[Condition] = mc_list('conditions', Condition.create)
    typ: eEntry = mc_basic('type', eEntry)
    weight: int = mc_basic('weight', int)
    quality: int = mc_basic('quality', int)

    def interact(self, info: MCActionInfo):
        if info.item_type == eItemType.Entry and 'children' in self:
            interact_with_items(self, 'children', info)

        elif info.item_type == eItemType.Condition:
            if 'conditions' in self:
                interact_with_items(self, 'conditions', info)
            if 'children' in self:
                interact_with_subitems(self['children'], info)
                if info.action_type is eActionType.Delete and self.typ is eEntry.alternatives and not any(
                        'conditions' in child for child in self['children']):
                    self.typ = eEntry.group
            if 'functions' in self:
                interact_with_subitems(self['functions'], info)

    @staticmethod
    def create(json_body):
        typ = json_body['type']

        if typ == eEntry.item:
            return ItemEntry(json_body)

        elif typ == eEntry.tag:
            return TagEntry(json_body)

        elif typ == eEntry.loot_table:
            return LootTableEntry(json_body)

        elif typ == eEntry.group:
            return GroupEntry(json_body)

        elif typ == eEntry.alternatives:
            return AlternativesEntry(json_body)

        elif typ == eEntry.sequence:
            return SequenceEntry(json_body)

        elif typ == eEntry.dynamic:
            return DynamicEntry(json_body)

        else:
            return Entry(json_body)
class LootTable(MCDict, MCInteractable):
	typ:	eLootTable = mc_basic('type', eLootTable)
	pools:	List[Pool] = mc_list('pools', Pool)

	def interact(self, info: MCActionInfo):
		if 'pools' in self:
			interact_with_subitems(self.pools, info)
예제 #6
0
class Pool(MCDict, MCInteractable):
    conditions: List[Condition] = mc_list('conditions', Condition.create)
    rolls: Union[IntRange, int] = mc_basic('rolls', init_int_or_range)
    bonus_rolls: Union[FloatRange, float] = mc_basic('bonus_rolls',
                                                     init_float_or_range)
    entries: List[Entry] = mc_list('entries', Entry.create)

    def interact(self, info: MCActionInfo):
        if info.item_type == eItemType.Entry and 'entries' in self:
            interact_with_items(self, 'entries', info)

        elif info.item_type == eItemType.Condition:
            if 'conditions' in self:
                interact_with_items(self, 'conditions', info)
            if 'entries' in self:
                interact_with_subitems(self.entries, info)
class AdvItem(dict):
	selector:		str				= mc_basic('selector', str)
	item_selector:	str				= mc_basic('item_selector', str)
	adv_item_type:	eAdvItemType	= mc_basic('adv_item_type', eAdvItemType)
	title:			str				= mc_basic('title', str)
	description:	str				= mc_basic('description', str)

	@staticmethod
	def populate(selector: str, adv_item_type: eAdvItemType, item_selector: str = None, title: str = None, description: str = None):
		adv_item = AdvItem()
		adv_item.selector = selector
		adv_item.adv_item_type = adv_item_type
		adv_item.item_selector = selector if item_selector is None else item_selector
		adv_item.title = title
		adv_item.description = description
		return adv_item
예제 #8
0
class TextComponent(MCDict):
    text: str = mc_basic('text', str)

    @staticmethod
    def populate(text: str = ''):
        tc = TextComponent()
        tc.text = text

        return tc
class Criteria(MCDict):
    trigger_type: eTrigger = mc_basic('trigger', eTrigger)
    conditions: TriggerConditions = mc_basic('conditions', TriggerConditions)

    @staticmethod
    def create(json_dict: dict):
        criteria = Criteria(json_dict)
        if 'conditions' in json_dict:
            criteria.conditions = switch(criteria.trigger_type,
                                         json_dict['conditions'])
        return criteria

    @staticmethod
    def populate(trigger_type: eTrigger, conditions: TriggerConditions = None):
        criteria = Criteria()
        criteria.trigger_type = trigger_type
        if conditions is not None:
            criteria.conditions = conditions

        return criteria
예제 #10
0
class Function(MCDict, MCInteractable):
    function: eFunction = mc_basic('function', eFunction)
    conditions: List[Condition] = mc_list('conditions', Condition.create)

    def interact(self, info: MCActionInfo):
        if info.item_type == eItemType.Condition and 'conditions' in self:
            interact_with_items(self, 'conditions', info)

    @staticmethod
    def create(json_dict):
        return Function(json_dict)
예제 #11
0
class Item(MCDict):
	count:			Union[IntRange, int]	= mc_basic('count', init_int_or_range)
	durability:		Union[IntRange, int]	= mc_basic('durability', init_int_or_range)
	enchantments:	List[Enchantment]		= mc_list('enchantments', Enchantment)
	item_id:		str						= mc_basic('item', str)
	nbt:			str						= mc_basic('nbt', str)
	potion:			str						= mc_basic('potion', str)
	tag:			str						= mc_basic('tag', str)

	@staticmethod
	def populate(count: Union[IntRange, int] = None, durability: Union[IntRange, int] = None, enchantments: List[Enchantment] = None, item_id: str = None, nbt: str = None, potion: str = None, tag: str = None):
		item = Item()
		if count is not None:
			item.count = count
		if durability is not None:
			item.durability = durability
		if enchantments is not None:
			item.enchantments = enchantments
		if item is not None:
			item.item_id = item_id
		if nbt is not None:
			item.nbt = nbt
		if potion is not None:
			item.potion = potion
		if tag is not None:
			item.tag = tag

		return item
class CraftingShaped(Recipe):
    pattern: List[str] = mc_list('pattern', str)
    key: Dict[str, Union[Ingredient,
                         List[Ingredient]]] = mc_dict('key',
                                                      init_ingredient_or_list)
    result: Result = mc_basic('result', Result)
class ConstructBeacon(TriggerConditions):
    level: Union[IntRange, int] = mc_basic('level', init_int_or_range)
class Ingredient(MCDict):
    item: str = mc_basic('item', str)
    tag: str = mc_basic('tag', str)
class Recipe(MCDict):
    typ: eRecipe = mc_basic('type', eRecipe)
    group: str = mc_basic('group', str)
class EnterBlock(TriggerConditions):
    block: str = mc_basic('block', str)
    state: dict = mc_basic('state', dict)
class Result(MCDict):
    count: int = mc_basic('count', int)
    item: str = mc_basic('item', str)
class CuredZombieVillager(TriggerConditions):
    villager: Entity = mc_basic('villager', Entity)
    zombie: Entity = mc_basic('zombie', Entity)
예제 #19
0
class Enchantment(MCDict):
    enchantment: eEnchantment = mc_basic('enchantment', eEnchantment)
    levels: Union[IntRange, int] = mc_basic('levels', init_int_or_range)
class InventoryChanged(TriggerConditions):
    req_items: List[Item] = mc_list('items', Item)
    slots: dict = mc_basic('slots', dict)
class PlayerKilledEntity(TriggerConditions):
    entity: Entity = mc_basic('entity', Entity)
    killing_blow: dict = mc_basic('killing_blow', dict)
class EffectsChanged(TriggerConditions):
    effects: dict = mc_basic('effect', dict)
class FilledBucket(TriggerConditions):
    item: Item = mc_basic('item', Item)
class EntityHurtPlayer(TriggerConditions):
    damage: dict = mc_basic('damage', dict)
class ChanneledLightning(TriggerConditions):
    victims: Entity = mc_basic('victims', Entity)
class Rewards(MCDict):
    recipes: List[str] = mc_list('recipes', str)
    loot: List[str] = mc_list('loot', str)
    experience: int = mc_basic('experience', int)
    function: str = mc_basic('function', str)
class ChangedDimension(TriggerConditions):
    frm: eDimension = mc_basic('from', eDimension)
    to: eDimension = mc_basic('to', eDimension)
class ConsumeItem(TriggerConditions):
    item: Item = mc_basic('item', Item)
class FishingRodHooked(TriggerConditions):
    entity: Entity = mc_basic('entity', Entity)
    item: Item = mc_basic('item', Item)
    rod: Item = mc_basic('item', Item)
class EnchantedItem(TriggerConditions):
    item: Item = mc_basic('item', Item)
    levels: Union[IntRange, int] = mc_basic('levels', init_int_or_range)