Trtr:注解编程:修订间差异

删除的内容 添加的内容
草awa留言 | 贡献
无编辑摘要
草awa留言 | 贡献
无编辑摘要
 
(未显示同一用户的4个中间版本)
第8行:
 
= 约束 =
任何需要被自动处理的字段和方法必须被"[[Trtr:com.github.cao.awa.apricot.anntation.Auto]]"注解,这也包括已经自行初始化的字段。
任何需要被自动处理的字段和方法必须被"static"关键字修饰<ref>{{cite web |url=https://github.com/cao-awa/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/framework/accessor/filed/FieldAccess.java |title=FieldAccess.java at main · cao-awa/the-road-to-reality |publisher=草二号机 |date=2023-03-16 |archiveurl=https://github.com/cao-awa/the-road-to-reality/blob/728911a683ee57ce94dc59212318e37073604bed/src/main/java/com/github/cao/awa/trtr/framework/accessor/filed/FieldAccess.java |archivedate=2023-03-16 |accessdate=2023-03-16 }}</ref>,这也包括已经自行初始化的字段。
 
= 示例 =
第59行:
// 另一种方式声明方块物品
// @Auto
// public static final Class<TestBlockItem> ITEM = TestBlockItem.class;
 
@Auto
第69行:
 
= 约定 =
在使用注解编程时,只有匹配约定字段的名称和类型才会被自动处理,且必须被"[[Trtr:com.github.cao.awa.apricot.anntation.Auto]]"注解
 
== 字段 ==
=== 标识符 ===
标识符(Identifier)约定名称为"IDENTIFIER"、类型为:[[Minecraft:net.minecraft.util.Identifier]]或[[java.lang.String]]<ref>{{cite web |url=https://github.com/caosky-awaways/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/framework/accessor/identifier/IdentifierAccessor.java |title=IdentifierAccessor.java at main · caosky-awaways/the-road-to-reality |publisher=草awa |date=2023-0306-1503 |archiveurl=https://github.com/caosky-awaways/the-road-to-reality/commitblob/040e9e90eccf3f46cc84871bbcabb22e55cfbaf2#diff-b0f8f794d57dc8d42be5e3fc874aadc53e6d93f552a8907b9eb2056053378cb2/src/main/java/com/github/cao/awa/trtr/framework/accessor/identifier/IdentifierAccessor.java |archivedate=2023-0306-1503 |accessdate=2023-0306-1611 }}</ref>。
 
=== 设置(方块) ===
方块设置(Settings)约定名称为"SETTINGS"、备选"SETTING",类型为:[[Minecraft:net.minecraft.block.AbstractBlock.Settings]]的子类<ref>{{cite web |url=https://github.com/caosky-awaways/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/framework/accessor/block/setting/BlockSettingAccessor.java |title=BlockSettingAccessor.java at main · caosky-awaways/the-road-to-reality |publisher=草awa |date=2023-03-16 |archiveurl=https://github.com/caosky-awaways/the-road-to-reality/blob/0c273d23aa961cdc5d031ca6d52fed12ed68867f/src/main/java/com/github/cao/awa/trtr/framework/accessor/block/setting/BlockSettingAccessor.java |archivedate=2023-03-16 |accessdate=2023-03-16 }}</ref>,如[[Minecraft:net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSetting|net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSetting]]。<ref name="example_block">{{cite web |url=https://github.com/caosky-awaways/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/block/example/ExampleBlock.java |title=ExampleBlock.java at main · caosky-awaways/the-road-to-reality |publisher=草二号机 |date=2023-03-15 |archiveurl=https://github.com/caosky-awaways/the-road-to-reality/blob/40ff64d245df47ca0c8b25db78252ab0cccbc62f/src/main/java/com/github/cao/awa/trtr/block/example/ExampleBlock.java |archivedate=2023-03-15 |accessdate=2023-03-16 }}</ref>
 
=== 方块物品 ===
方块物品(BlockItem)约定名称为"ITEM"、备选"BLOCK_ITEM",类型为:[[Minecraft:net.minecraft.item.BlockItem|net.minecraft.item.BlockItem]]或其子类<ref>{{cite web |url=https://github.com/caosky-awaways/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/framework/accessor/block/item/BlockItemAccessor.java |title=BlockItemAccessor.java at main · caosky-awaways/the-road-to-reality |publisher=草awa |date=2023-03-16 |archiveurl=https://github.com/caosky-awaways/the-road-to-reality/blob/0c273d23aa961cdc5d031ca6d52fed12ed68867f/src/main/java/com/github/cao/awa/trtr/framework/accessor/block/item/BlockItemAccessor.java |archivedate=2023-03-16 |accessdate=2023-03-16 }}</ref>。
 
或者以形如Class<? extends BlockItem>的方式声明类型。<ref name="example_block"></ref>
 
=== 方块战利品(数据生成) ===
方块战利品(Loot)约定名称为"LOOT"、备选"LOOT_PROVIDER",类型为[[Minecraft:net.fabricmc.fabric.api.datagen.v1.provider.SimpleFabricLootTableProvider]]的子类或[[Trtr:com.github.cao.awa.trtr.framework.data.gen.loot.LootFactory]]的实现<ref>{{cite web |url=https://github.com/caosky-awaways/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/framework/accessor/data/gen/loot/LootDataGeneratorAccessor.java |title=LootDataGeneratorAccessor.java at main · caosky-awaways/the-road-to-reality |publisher=草awa |date=2023-03-16 |archiveurl=https://github.com/caosky-awaways/the-road-to-reality/blob/4cffec2d6a283a8d4421dcd2d93faff805d2817b/src/main/java/com/github/cao/awa/trtr/framework/accessor/data/gen/loot/LootDataGeneratorAccessor.java |archivedate=2023-03-16 |accessdate=2023-03-16 }}</ref>,如[[Trtr:com.github.cao.awa.trtr.data.gen.loot.GenericBlockLootProvider]]。
 
或者以形如Class<? extends SimpleFabricLootTableProvider>或LootFactory<? extends SimpleFabricLootTableProvider>的方式声明类型。<ref name="example_block"></ref>
 
=== 方块模型(数据生成) ===
方块模型(models)约定名称为"MODEL"、备选"MODEL_PROVIDER",类型为[[Minecraft:net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider]]的子类<ref>{{cite web |url=https://github.com/caosky-awaways/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/framework/accessor/data/gen/model/ModelDataGeneratorAccessor.java |title=ModelDataGeneratorAccessor.java at main · caosky-awaways/the-road-to-reality |publisher=草awa |date=2023-03-15 |archiveurl=https://github.com/caosky-awaways/the-road-to-reality/blob/4cffec2d6a283a8d4421dcd2d93faff805d2817b/src/main/java/com/github/cao/awa/trtr/framework/accessor/data/gen/model/ModelDataGeneratorAccessor.java |archivedate=2023-03-15 |accessdate=2023-03-16 }}</ref>,如[[Trtr:com.github.cao.awa.trtr.data.gen.model.GenericBlockModelProvider]]。
 
或者以形如Class<? extends BlockItem>的方式声明类型。<ref name="example_block"></ref>
 
=== 方块属性 ===
任何方块属性(properties)没有约定名称,只需要添加[[Trtr:com.github.cao.awa.trtr.annotation.property.AutoProperty]]即可被自动处理添加,类型为[[Minecraft:net.minecraft.state.property.Property]]字段和方法必须被"static"关键字修饰子类<ref>{{cite web |url=https://github.com/caosky-awaways/the-road-to-reality/blob/main/src/main/java/com/github/cao/awa/trtr/framework/accessorblock/filed/FieldAccessBlockFramework.java#L245 |title=FieldAccessBlockFramework.java#L245 at main · caosky-awaways/the-road-to-reality |publisher=草二号机awa |date=2023-0306-1604 |archiveurl=https://github.com/caosky-awaways/the-road-to-reality/blob/728911a683ee57ce94dc59212318e37073604bed27190e7d17f57d0cfb9d9a4577404e086824ef72/src/main/java/com/github/cao/awa/trtr/framework/accessorblock/filed/FieldAccessBlockFramework.java#L245 |archivedate=2023-0306-1604 |accessdate=2023-0306-1614 }}</ref>,这也包括已经自行初始化的字段
 
== 方法 ==
第97行 ⟶ 第100行:
== 注解 ==
=== 自动处理 ===
要让框架自动处理一个类,需要在类上添加[[Trtr:com.github.cao.awa.apricot.annotations.Auto|@Auto]]注解,照标准样式,其他任何需要字段自动处理的字段和方法也应加上此注解(包括构造器)
 
=== 要求工具挖掘 ===
第118行 ⟶ 第121行:
 
= 样式 =
在代码中,@Auto注解虽然被依照标准要求在每一个会被自动处理的字段、方法和类上出现,以统一标准样式。但这一要求不是强制性的,只需要至少在类上添加没有@Auto注解即可使用注解编程的字段将不会被处理
 
标准样式是在向主仓库创建拉取请求或用任意其他方式提交代码时所必须的,非规范样式的代码会被拒绝合并。
 
= 参考 =