Skip to content
标签
AttributeSystem
字数
162 字
阅读时间
1 分钟

读取格式拓展

Kotlin

kotlin
    @AutoRegister
    object MyReadPattern : ReadPattern<Any>("my_read_pattern"){
        override fun read(string: String, attribute: Attribute, entity: LivingEntity?, slot: String?): Status<Any>? {
            //code
        }

        override fun readNBT(map: Map<String, Any>, attribute: Attribute): Status<Any>? {
            //code
        }

        override fun placeholder(key: String, attribute: Attribute, status: Status<*>, entity: LivingEntity?): Any? {
            //code
        }

        override fun stat(attribute: Attribute, status: Status<*>, entity: LivingEntity?): TellrawJson {
            //code
        }

    }

用法

属性定义处指定读取格式

YAML

yaml
ExampleAttr:
  names:
    - "示例属性"
  #读取格式
  read-pattern: my_read_pattern

JavaScript

javascript
//@Awake(Active)
function regAtt() {
  var Attribute = find("com.skillw.attsystem.api.attribute.Attribute");
  var ReadPattern = AttributeSystem.readPatternManager.get("my_read_pattern");

  Attribute.createAttribute("example", ReadPattern, (builder) => {
    builder.names.add("示例属性");
  }).register();
}

Kotlin

kotlin
val ReadPattern = AttributeSystem.readPatternManager["my_read_pattern"]
Attribute.createAttribute("example", ReadPattern) {
    names += "示例属性"
}.register()

贡献者

The avatar of contributor named as Glomzzz Glomzzz
The avatar of contributor named as Glom-c Glom-c

页面历史