Decorator
Decorators in Deco are special annotations that provide additional functionality to functions. They are marked with the @ symbol and placed before function definitions. Decorators allow you to bind functions to specific Minecraft events or tags, simplifying datapack development.
Using Decorators
The basic syntax for a decorator is:
Where:
@decoratorName: The name of the decorator, starting with@(arguments): Optional parameters, some decorators require argumentsfunc functionName { ... }: The decorated function
For example, the following code uses the @load decorator to mark a function that will execute when the datapack is loaded:
Multiple Decorators
A single function can have multiple decorators applied to it by listing them before the function definition:
This function will run both when the datapack is loaded and when you run function #custom:init.
Decorator Arguments
Some decorators need arguments to specify their behavior. Arguments are provided in parentheses after the decorator name:
How Decorators Work
During compilation, Deco automatically generates the necessary function tag files and event handling code based on the decorators:
@loadand@tickdecorators add your functions to Minecraft's built-inminecraft:loadandminecraft:ticktags@tagadds your function to the specified custom tag@onPlaceBlockcreates an advanced detection system using advancements and functions to detect when specific blocks are placed- ...
This automatic generation saves you from having to manually create these structures, making your datapack development more efficient and your code more readable.
Available Decorators
Deco currently supports the following decorators:
@load
The @load decorator registers a function to run when the datapack is loaded.
After compilation, this function will be automatically added to the minecraft:load function tag, causing it to run whenever the datapack is loaded.
@tick
The @tick decorator registers a function to run every game tick.
After compilation, this function will be automatically added to the minecraft:tick function tag, causing it to run every game tick.
@tag
The @tag decorator allows you to add a function to a specific function tag.
After compilation, this function will be added to the specified function tag, in this case custom:example.
@onPlaceBlock
The @onPlaceBlock decorator binds a function to the event of a player placing a specific block.
When a player places a diamond block, the function will be triggered, displaying a message to all players and giving a diamond to the player who placed the block.