Skip to main content

A collection of beet and bolt plugins

Project description

ps_beet_bolt

A collection of my beet and bolt plugins

bolt-item

To be able to use on_equip, on_unequip, on_attack, on_attacked, on_consume or on_tick, you have to require the specific plugin in your beet json/yaml/yml file.

You also need to add the respecive library for on_attack and on_attacked (argon) or on_equip and on_unequip (tungsten) to work

require:
  - bolt
  - ps_beet_bolt.register.bolt_item # on_consume, on_tick
  - ps_beet_bolt.register.tungsten # on_equip, on_unequip
  - ps_beet_bolt.register.argon # on_attack, on_attacked

data_pack:
  load:
    - libraries/mc-tungsten* # on_equip, on_unequip
    - libraries/mc-argon* # on_attack, on_attacked
    - src

Example code with explanations:

from ps_beet_bolt.bolt_item import transformer, custom_component, event_decorator
from tungsten:decorators import on_equip, on_unequip
from argon:decorators import on_attack, on_attacked
from bolt_item:decorators import on_consume, on_tick


@event_decorator
def on_block_interact(func, item):
    """
    You can use the @event_decorator to add any functionality you like. You can modify
    the items components, and read any information.
    """
    path = f'{item.namespace}:bolt-item/item/{item.id}/on_block_interact/{func.__name__}'
    advancement path { "criteria": { "criteria": {
        "trigger": "minecraft:item_used_on_block",
        "conditions": { "location": [{
            "condition": "minecraft:match_tool",
            "predicate": {
                "items": item.base_item,
                "components": {
                    "custom_data": {
                        "bolt-item": { "id": f'{item.namespace}:{item.id}' }
                    }
                }
            }}]
        }}},
        "rewards": { "function": path }
    }
    function path:
        advancement revoke @s only path
        func()

class ParentItem:
    """
    All the special decorators, vanilla components and custom components get
    inherited, even if the parent class is not an item itself.
    """
    lore = [{"text":"MyPack","color":"blue"}]

    @transformer(component = "item_name")
    def item_name_transformer(item, item_name):
        """
        A @transformer takes the previous value of a components and sets it to the return value.
        You can chain as many transformer after each other as you like.
        They are applied from parent to child, from top to bottom.
        """
        return {"text":item_name,"color":"red"}

@item
class ActualItem(ParentItem):
    """
    Any classes with the @item decorator are treated as item and get a .components and a .base_item
    attribute set. Those can be used to create loot tables or other stuff.
    """
    item_name = "Awesome Item"
    story = "This item special"
    consumable = {}
    equippable = {"slot":"head"}

    @on_block_interact
    def say_hi_it_interacted_with_block():
        """
        This is the custom event decorator added earlier in the file, for more examples look through
        this libraries bolt code.
        """
        say I INTERACTED WITH THE BLOCK USING THIS ITEM

    @custom_component(component = "story")
    def story_handler(item, story):
        """
        @custom_component handlers take an attribute and can modify the item's components based on
        that input.
        """
        item.lore = [{"text":story, "color":"gray"}] + item.get("lore", [])

    @on_consume(return_item = True)
    def infinitely_eddible():
        """
        @on_consume runs when the item is consumed. If return_item is set to True, the item stays in
        the players inventory. This can be used for right click abilities with cooldown provided by
        the use_cooldown component.
        """
        say THIS ITEM WAS CONSUMED, THIS ITEM IS NOT REMOVED FROM THE INVENTORY HOWEVER SINCE RETURN ITEM IS TRUE, THIS CAN BE USED TO TRIGGER A COOL DOWN ON RIGHT CLICK

    @on_tick(interval = "10s", full_slot = "armor.head")
    def yap_every_10_seconds():
        """
        This uses schedules to run this command in the given interval when it's equipped on the given slot.
        """
        say ANOTHER 10 SECONDS HAVE PASSED AND I AM WEARING THIS ITEM ON MY HEAD

    @on_equip(slot = "head")
    def add_resistance():
        """
        @on_unequip requires tungsten. This function runs when a player unequips this item from the given slot.
        """
        effect give @s resistance infinite 1

    @on_unequip(slot = "head")
    def remove_resistance():
        """
        @on_equip requires tungsten. This function runs when a player equips this item in the given slot.
        """
        effect clear @s resistance

    @on_attack(slot = "mainhand")
    def attack_my_enemies():
        """
        @on_attack requires argon. This function runs when a player attacks an enemy with this item in
        the given slot. @s is enemy; on attacker is player.
        """
        say I AM AN ATTACKED ENEMY
        on attacker say I AM THE PLAYER WHO ATTACKED THE ENEMY WITH THIS ITEM IN THEIR MAINHAND

    @on_attacked(full_slot = "weapon.mainhand")
    def attacked_by_enemies():
        """
        @on_attacked requires argon. This function runs when a player is attacked with this item in
        the given slot. @s is player; on attacker is enemy.
        """
        say I AM THE PLAYER WHO GOT ATTACKED WHILE HOLDING THIS ITEM IN MY MAINHAND
        on attacker say I AM THE ENEMY WHO DID IT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ps_beet_bolt-0.4.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ps_beet_bolt-0.4.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file ps_beet_bolt-0.4.0.tar.gz.

File metadata

  • Download URL: ps_beet_bolt-0.4.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for ps_beet_bolt-0.4.0.tar.gz
Algorithm Hash digest
SHA256 dece8960378d519d4a09fa8218bea62fcae4a9e2882f59e0fad640040e5ce1b0
MD5 fd533b687c75c544c6c53b3fd7fce9fa
BLAKE2b-256 dc96f6a3c3b84415b850311714a10c92ffea42687b44090e618a476049c5fbec

See more details on using hashes here.

File details

Details for the file ps_beet_bolt-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: ps_beet_bolt-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for ps_beet_bolt-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5f2b307cd18f98d747d8b40ee0cc41433a7a47fdd2a61e81271781409636681
MD5 4ae6f8e9dd2024cae7723237b79bf16a
BLAKE2b-256 19871c67f2e99415b952562b78aa03e0701b974d9b3b24bc7867c2fb3b3f89aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page