-
Notifications
You must be signed in to change notification settings - Fork 0
Rusted‐Office
Rusted-Office is a custom component extension designed for simple, data-driven creation of custom components with minimal syntax. It offers an easy and flexible way to add custom functionality to your blocks.
To install this filter, first make sure you have Cargo installed then, navigate to a Regolith project and run:
regolith install github.com/akashic-records-of-the-abyss/rusted-filters/tetanus
Ensure it runs before any filters that modify the TypeScript (TS), as it will break if not placed before them!
If you would like a full example of Rusted Office working check out the example project! It is quite a simple process!
Here’s an example of a basic component:
interface ComponentConfig {
count: number;
};
// The component must be exported, regardless of the method used.
// @Generate(id: my_very_first_component, type: block)
export class SomeComponent implements BlockCustomComponent {
constructor(config: ComponentConfig) {
console.warn(config.count);
}
onTick(arg: BlockComponentTickEvent) {
world.sendMessage("TICKED");
}
}
To apply the component to a block:
{
"format_version": "1.21.40",
"minecraft:block": {
"description": {...},
"components": {
"my_very_first_component": {"count": 200}
...
}
}
}
Run Regolith run
to apply the component to the block!
Name | Function | Required | type |
---|---|---|---|
id | Sets the id used to add this component to an object | yes | string |
type | Specifies what object types this component can be added too. There are 3 valid types.item, block, and both |
yes | string |
passId | Specifies if the component should be told the ID of the object who added the component | no | bool |
pureData | Specifies if the component is a data only component. If this is true the component will not be registed into the games component list but will still be constructed. This allows for you to add attributes to your blocks without clogging them with tags | no | bool |
// @Generate(id: my_component, type: block, passId: true)
export class AnotherComponent implements BlockCustomComponent {
readonly ownerId: string;
constructor(emptyObject: {}, ownerId: string) {
this.ownerId = ownerId;
this.onTick = this.onTick.bind(this);
}
onTick(arg: BlockComponentTickEvent) {
world.sendMessage(`Ticked by owner: ${this.ownerId}`);
}
}
const instances: string[] = [];
// @InitFunction
export function InitPureData() {
system.runInterval(() => {
for (const r of instances) {
console.info(r);
}
}, 5);
}
// @Generate(id: my_data_component, type: block, passId: true, pureData: true)
export class AnotherAnotherComponent {
constructor(emptyObject: {}, ownerId: string) {
instances.push(ownerId);
}
}
Initialization functions are standalone exported functions marked with the // @InitFunction
comment. These functions initialize systems required for components to register correctly.
// @InitFunction
export function someSetup() {...}
This code runs before any components are constructed. It must be exported, and its name must not conflict with a component or another initialization function; otherwise, compiler errors will occur. Future iterations will include detection and handling for these cases.
Only free-floating functions are valid:
// @InitFunction
export function something() {...}
Class methods, even if static, will not work:
export class Something {
// @InitFunction
static something() {...}
}