-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Instead of giving direct access to "luafy:shared" on all entities, we'd have a more declarative, safe way of interacting with custom entity data.
Pseudo-code/unfinalized:
funny_pack/luafy/display.ts
const display_data = Luafy.entity_component.create<{ foo: string, bar: NBTInteger }>('item_display', 'display_data', true /* read-only, defaults to false */)
export default function spawn_display() {
const display = Luafy.spawn_entity('item_display', '{item:{id:"dirt"}}', [ display_data.init({ foo: 'baz', bar: NBT`69` }) ])
const bar: NBTInteger = display.components.get(display_data).bar
display.components.modify(display_data).foo = 'funny' // errors at TS compile time & at runtime
display.components.set(display_data, "anything else") // errors at TS compile time & at runtime, if `display_data` was not read-only, this would only be a TS compile error
}# Entity Data:
{item:{id:"dirt"},"luafy:shared":{"funny_pack:display_data":{foo:"baz",bar:69}}}Entity type enum:
Luafy.entity_component.entity_types.ALL
Luafy.entity_component.entity_types.LIVING
Luafy.entity_component.entity_types.MOB
Luafy.entity_component.entity_types.PROJECTILE
Luafy.entity_component.entity_types.BREEDABLEcreate's first argument supports entity type integer enum values, entity ids, or # prefixed entity registry/group tags.
create returns a LuafyEntityComponentObject, which has an id method that returns the hexId for the object. This can then be added to data storage to share with other packs.