Skip to content

Repository files navigation

stylish

npm version

Stylish is a decorator library aimed at simplifying development for the Minecraft Bedrock Script API. It focuses on automatic registration of custom components and convenience helpers for method binding.

Features

  • @ItemComponent - automatically registers a custom item component.
  • @BlockComponent - automatically registers a custom block component.
  • @CustomCmd - automatically registers a custom command.
  • @BindThis - binds a method to its instance when accessed.
  • @OnStartup - runs decorated methods when the pack starts.
  • @OnWorldLoad - runs decorated methods when the world is loaded.
  • @On<Event> / @OnBefore<Event> - a strongly typed decorator for every world/system event in @minecraft/server (e.g. @OnPlayerJoin, @OnEntityDie, @OnBeforeItemUse, @OnScriptEventReceive). Supports native filter options where the API does: @OnEntityHurt({ entityTypes: ['example:boss'] }). See docs/events.md for the full list.
  • @ScriptEvent('example:my_event') - routes /scriptevent commands by id over a single namespace-filtered subscription.
  • @Interval(ticks) / @Timeout(ticks) / @OnTick - runs methods on a tick schedule, starting at startup.
  • @WorldProperty('example:key', default) - backs a class field with a world dynamic property (cached reads, write-through).
  • @RegisterEvents - auto-registers instance event methods (like @OnStartup) on construction.

Installation

  1. Install the package:
npm install @bedrock-oss/stylish
  1. Enable decorators in your tsconfig.json:
{
  "compilerOptions": {
    "experimentalDecorators": true
  }
}

Usage

Register a custom item component:

ExampleComponent.ts:

import { ItemComponentUseEvent } from '@minecraft/server';
import { ItemComponent, BindThis } from '@bedrock-oss/stylish';

@ItemComponent
class ExampleComponent {
  static componentId = 'example:component';
  message = 'Hello world!';

  @BindThis
  onUse(event: ItemComponentUseEvent) {
    event.source.sendMessage(this.message);
  }
}

main.ts:

import { init } from '@bedrock-oss/stylish';
export * from './ExampleComponent';

init(); // Registers all decorated components and wires events
// Alternatively, you can register your own event handler and call registerAllComponents()

Important

When splitting components into multiple files, remember to import/export the file containing the component class.

Documentation

See the docs folder for details on decorators:

Contributing

Feel free to raise an issue or submit a pull request if you have any improvements or features to suggest.

License

This project is licensed under the MIT License.

About

No description or website provided.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages