sapdon 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +3 -2
  2. package/dist/cli/build.d.ts +7 -0
  3. package/dist/cli/build.js +236 -0
  4. package/dist/cli/dev-server/client.d.ts +2 -0
  5. package/dist/cli/dev-server/client.js +21 -0
  6. package/dist/cli/dev-server/config.d.ts +3 -0
  7. package/dist/cli/dev-server/config.js +3 -0
  8. package/dist/cli/dev-server/handles.d.ts +4 -0
  9. package/dist/cli/dev-server/handles.js +5 -0
  10. package/dist/cli/dev-server/hmr.d.ts +1 -0
  11. package/dist/cli/dev-server/hmr.js +13 -0
  12. package/dist/cli/dev-server/index.d.ts +4 -0
  13. package/dist/cli/dev-server/index.js +17 -0
  14. package/dist/cli/dev-server/server.d.ts +14 -0
  15. package/dist/cli/dev-server/server.js +59 -0
  16. package/dist/cli/dev-server/syncFiles.d.ts +3 -0
  17. package/dist/cli/dev-server/syncFiles.js +45 -0
  18. package/dist/cli/index.d.ts +20 -0
  19. package/dist/cli/index.js +90 -0
  20. package/dist/cli/init.d.ts +9 -0
  21. package/dist/cli/init.js +80 -0
  22. package/dist/cli/load.d.ts +3 -0
  23. package/dist/cli/load.js +94 -0
  24. package/dist/cli/start.d.ts +2 -0
  25. package/dist/cli/start.js +1398 -0
  26. package/dist/cli/tools/textureSet.d.ts +13 -0
  27. package/dist/cli/tools/textureSet.js +103 -0
  28. package/dist/cli/utils.d.ts +13 -0
  29. package/dist/cli/utils.js +89 -0
  30. package/dist/core/addon/biome.d.ts +22 -0
  31. package/dist/core/addon/biome.js +27 -0
  32. package/dist/core/addon/block/block.d.ts +41 -0
  33. package/dist/core/addon/block/block.js +46 -0
  34. package/dist/core/addon/controllers/animationController.d.ts +43 -0
  35. package/dist/core/addon/controllers/animationController.js +73 -0
  36. package/dist/core/addon/controllers/render_controllers.js +162 -0
  37. package/dist/core/addon/entity/clientEntity.d.ts +107 -0
  38. package/dist/core/addon/entity/clientEntity.js +149 -0
  39. package/dist/core/addon/entity/entity.d.ts +42 -0
  40. package/dist/core/addon/entity/entity.js +50 -0
  41. package/dist/core/addon/feature/oreFeature.d.ts +19 -0
  42. package/dist/core/addon/feature/oreFeature.js +24 -0
  43. package/dist/core/addon/featureRule.d.ts +20 -0
  44. package/dist/core/addon/featureRule.js +25 -0
  45. package/dist/core/addon/item/attachable.d.ts +94 -0
  46. package/dist/core/addon/item/attachable.js +134 -0
  47. package/dist/core/addon/item/item.d.ts +19 -0
  48. package/dist/core/addon/item/item.js +26 -0
  49. package/dist/core/addon/manifest.d.ts +49 -0
  50. package/dist/core/addon/manifest.js +65 -0
  51. package/dist/core/addon/menuCategory.d.ts +6 -0
  52. package/dist/core/addon/menuCategory.js +7 -0
  53. package/dist/core/addon/recipe/baseRecipe.d.ts +12 -0
  54. package/dist/core/addon/recipe/baseRecipe.js +23 -0
  55. package/dist/core/addon/recipe/data.d.ts +66 -0
  56. package/dist/core/addon/recipe/data.js +74 -0
  57. package/dist/core/addon/recipe/furnace.d.ts +17 -0
  58. package/dist/core/addon/recipe/furnace.js +43 -0
  59. package/dist/core/addon/recipe/shaped.d.ts +26 -0
  60. package/dist/core/addon/recipe/shaped.js +53 -0
  61. package/dist/core/addon/recipe/shapeless.d.ts +18 -0
  62. package/dist/core/addon/recipe/shapeless.js +36 -0
  63. package/dist/core/biome/biome.d.ts +14 -0
  64. package/dist/core/biome/biome.js +23 -0
  65. package/dist/core/biome/biomeComponent.d.ts +46 -0
  66. package/dist/core/biome/biomeComponent.js +77 -0
  67. package/dist/core/block/basicBlock.d.ts +48 -0
  68. package/dist/core/block/basicBlock.js +105 -0
  69. package/dist/core/block/block.d.ts +32 -0
  70. package/dist/core/block/block.js +92 -0
  71. package/dist/core/block/blockComponent.d.ts +187 -0
  72. package/dist/core/block/blockComponent.js +500 -0
  73. package/dist/core/block/cropBlock.d.ts +4 -0
  74. package/dist/core/block/cropBlock.js +27 -0
  75. package/dist/core/block/geometryBlock.d.ts +12 -0
  76. package/dist/core/block/geometryBlock.js +16 -0
  77. package/dist/core/block/oreBlock.d.ts +9 -0
  78. package/dist/core/block/oreBlock.js +25 -0
  79. package/dist/core/block/rotatableBlock.d.ts +27 -0
  80. package/dist/core/block/rotatableBlock.js +107 -0
  81. package/dist/core/block/tileBlock.d.ts +17 -0
  82. package/dist/core/block/tileBlock.js +125 -0
  83. package/dist/core/entity/basicEntity.d.ts +111 -0
  84. package/dist/core/entity/basicEntity.js +170 -0
  85. package/dist/core/entity/behavior/followMob.d.ts +12 -0
  86. package/dist/core/entity/behavior/followMob.js +35 -0
  87. package/dist/core/entity/behavior/followParent.d.ts +7 -0
  88. package/dist/core/entity/behavior/followParent.js +15 -0
  89. package/dist/core/entity/behavior/randomStroll.d.ts +31 -0
  90. package/dist/core/entity/behavior/randomStroll.js +63 -0
  91. package/dist/core/entity/behavior/tempt.d.ts +73 -0
  92. package/dist/core/entity/behavior/tempt.js +134 -0
  93. package/dist/core/entity/bundles/BasicMoveBundle.js +8 -0
  94. package/dist/core/entity/bundles/basicBundle.d.ts +13 -0
  95. package/dist/core/entity/bundles/basicBundle.js +38 -0
  96. package/dist/core/entity/clientEntity.d.ts +20 -0
  97. package/dist/core/entity/clientEntity.js +37 -0
  98. package/dist/core/entity/componets/entityComponet.d.ts +202 -0
  99. package/dist/core/entity/componets/entityComponet.js +354 -0
  100. package/dist/core/entity/data/nativeEntityData.d.ts +9 -0
  101. package/dist/core/entity/data/nativeEntityData.js +38 -0
  102. package/dist/core/entity/dummyEntity.js +14 -0
  103. package/dist/core/entity/entity.d.ts +15 -0
  104. package/dist/core/entity/entity.js +11 -0
  105. package/dist/core/entity/nativeEntity.d.ts +8 -0
  106. package/dist/core/entity/nativeEntity.js +28 -0
  107. package/dist/core/entity/navigation/walk.d.ts +23 -0
  108. package/dist/core/entity/navigation/walk.js +56 -0
  109. package/dist/core/entity/projectile.d.ts +3 -0
  110. package/dist/core/entity/projectile.js +7 -0
  111. package/dist/core/factory/biomeFactory.d.ts +4 -0
  112. package/dist/core/factory/biomeFactory.js +13 -0
  113. package/dist/core/factory/blockFactory.d.ts +34 -0
  114. package/dist/core/factory/blockFactory.js +143 -0
  115. package/dist/core/factory/entityFactory.d.ts +17 -0
  116. package/dist/core/factory/entityFactory.js +75 -0
  117. package/dist/core/factory/featureFactory.d.ts +6 -0
  118. package/dist/core/factory/featureFactory.js +23 -0
  119. package/dist/core/factory/itemExtra.d.ts +8 -0
  120. package/dist/core/factory/itemExtra.js +9 -0
  121. package/dist/core/factory/itemFactory.d.ts +27 -0
  122. package/dist/core/factory/itemFactory.js +112 -0
  123. package/dist/core/factory/recipeFactory.d.ts +18 -0
  124. package/dist/core/factory/recipeFactory.js +39 -0
  125. package/dist/core/factory/uiFactory.d.ts +12 -0
  126. package/dist/core/factory/uiFactory.js +32 -0
  127. package/dist/core/feature/oreFeature.d.ts +10 -0
  128. package/dist/core/feature/oreFeature.js +11 -0
  129. package/dist/core/feature-rule/condition/biomeFilter.d.ts +26 -0
  130. package/dist/core/feature-rule/condition/biomeFilter.js +36 -0
  131. package/dist/core/feature-rule/condition/featureConditions.d.ts +27 -0
  132. package/dist/core/feature-rule/condition/featureConditions.js +37 -0
  133. package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +17 -0
  134. package/dist/core/feature-rule/distribution/coordinateDistribution.js +23 -0
  135. package/dist/core/feature-rule/distribution/featureDistribution.d.ts +31 -0
  136. package/dist/core/feature-rule/distribution/featureDistribution.js +41 -0
  137. package/dist/core/feature-rule/featureRule.d.ts +17 -0
  138. package/dist/core/feature-rule/featureRule.js +26 -0
  139. package/dist/core/index.d.ts +2241 -0
  140. package/dist/core/index.js +1 -0
  141. package/dist/core/item/armor.d.ts +21 -0
  142. package/dist/core/item/armor.js +90 -0
  143. package/dist/core/item/attachable.d.ts +6 -0
  144. package/dist/core/item/attachable.js +26 -0
  145. package/dist/core/item/food.d.ts +24 -0
  146. package/dist/core/item/food.js +38 -0
  147. package/dist/core/item/item.d.ts +36 -0
  148. package/dist/core/item/item.js +69 -0
  149. package/dist/core/item/itemComponents.d.ts +113 -0
  150. package/dist/core/item/itemComponents.js +225 -0
  151. package/dist/core/registry.d.ts +12 -0
  152. package/dist/core/registry.js +17 -0
  153. package/dist/core/texture.d.ts +18 -0
  154. package/dist/core/texture.js +38 -0
  155. package/dist/core/ui/buttonMapping.d.ts +97 -0
  156. package/dist/core/ui/buttonMapping.js +132 -0
  157. package/dist/core/ui/dataBindingObject.d.ts +97 -0
  158. package/dist/core/ui/dataBindingObject.js +134 -0
  159. package/dist/core/ui/elements/button.d.ts +21 -0
  160. package/dist/core/ui/elements/button.js +101 -0
  161. package/dist/core/ui/elements/collectionPanel.d.ts +12 -0
  162. package/dist/core/ui/elements/collectionPanel.js +53 -0
  163. package/dist/core/ui/elements/grid.d.ts +8 -0
  164. package/dist/core/ui/elements/grid.js +33 -0
  165. package/dist/core/ui/elements/image.d.ts +13 -0
  166. package/dist/core/ui/elements/image.js +55 -0
  167. package/dist/core/ui/elements/label.d.ts +14 -0
  168. package/dist/core/ui/elements/label.js +61 -0
  169. package/dist/core/ui/elements/panel.d.ts +11 -0
  170. package/dist/core/ui/elements/panel.js +49 -0
  171. package/dist/core/ui/elements/scrollingPanel.d.ts +14 -0
  172. package/dist/core/ui/elements/scrollingPanel.js +59 -0
  173. package/dist/core/ui/elements/stackPanel.d.ts +14 -0
  174. package/dist/core/ui/elements/stackPanel.js +37 -0
  175. package/dist/core/ui/elements/uiElement.d.ts +53 -0
  176. package/dist/core/ui/elements/uiElement.js +129 -0
  177. package/dist/core/ui/properties/control.d.ts +214 -0
  178. package/dist/core/ui/properties/control.js +286 -0
  179. package/dist/core/ui/properties/dataBinding.d.ts +6 -0
  180. package/dist/core/ui/properties/dataBinding.js +16 -0
  181. package/dist/core/ui/properties/factory.d.ts +37 -0
  182. package/dist/core/ui/properties/factory.js +62 -0
  183. package/dist/core/ui/properties/gridProp.d.ts +65 -0
  184. package/dist/core/ui/properties/gridProp.js +90 -0
  185. package/dist/core/ui/properties/input.d.ts +97 -0
  186. package/dist/core/ui/properties/input.js +134 -0
  187. package/dist/core/ui/properties/layout.d.ts +105 -0
  188. package/dist/core/ui/properties/layout.js +145 -0
  189. package/dist/core/ui/properties/scrollView.d.ts +105 -0
  190. package/dist/core/ui/properties/scrollView.js +145 -0
  191. package/dist/core/ui/properties/sound.d.ts +47 -0
  192. package/dist/core/ui/properties/sound.js +66 -0
  193. package/dist/core/ui/properties/sprite.d.ts +161 -0
  194. package/dist/core/ui/properties/sprite.js +222 -0
  195. package/dist/core/ui/properties/text.d.ts +135 -0
  196. package/dist/core/ui/properties/text.js +187 -0
  197. package/dist/core/ui/registry/uiSystemRegistry.d.ts +8 -0
  198. package/dist/core/ui/registry/uiSystemRegistry.js +26 -0
  199. package/dist/core/ui/systems/chest.d.ts +5 -0
  200. package/dist/core/ui/systems/chest.js +21 -0
  201. package/dist/core/ui/systems/containerUISystem.d.ts +67 -0
  202. package/dist/core/ui/systems/containerUISystem.js +214 -0
  203. package/dist/core/ui/systems/guidebook.d.ts +9 -0
  204. package/dist/core/ui/systems/guidebook.js +206 -0
  205. package/dist/core/ui/systems/serverForm.d.ts +13 -0
  206. package/dist/core/ui/systems/serverForm.js +116 -0
  207. package/dist/core/ui/systems/system.d.ts +16 -0
  208. package/dist/core/ui/systems/system.js +37 -0
  209. package/dist/oc/actor.js +44 -0
  210. package/dist/oc/core.js +201 -0
  211. package/dist/oc/index.d.ts +142 -0
  212. package/dist/oc/index.js +1 -0
  213. package/dist/oc/input.js +67 -0
  214. package/dist/oc/optional.js +31 -0
  215. package/doc/oc/index.md +0 -0
  216. package/doc/sapdon-ts.md +41 -5
  217. package/package.json +6 -8
  218. package/doc/cli.md +0 -24
  219. /package/doc/hello_sapdon/{sapdon/344/275/277/347/224/250/346/225/231/347/250/213.md" → hello_sapdon.md} +0 -0
@@ -0,0 +1,21 @@
1
+ export class Armor {
2
+ constructor(identifier: any, category: any, item_texture: any, texture_path: any, options?: {});
3
+ identifier: any;
4
+ item: Item;
5
+ attachable: Attachable;
6
+ setArrachableGeometry(key: any, geometry: any): this;
7
+ }
8
+ export class Chestplate extends Armor {
9
+ constructor(identifier: any, item_texture: any, texture_path: any, options?: {});
10
+ }
11
+ export class Boot extends Armor {
12
+ constructor(identifier: any, item_texture: any, texture_path: any, options?: {});
13
+ }
14
+ export class Leggings extends Armor {
15
+ constructor(identifier: any, item_texture: any, texture_path: any, options?: {});
16
+ }
17
+ export class Helmet extends Armor {
18
+ constructor(identifier: any, item_texture: any, texture_path: any, options?: {});
19
+ }
20
+ import { Item } from "./item.js";
21
+ import { Attachable } from "./attachable.js";
@@ -0,0 +1,90 @@
1
+ import { Attachable } from "./attachable.js";
2
+ import { Item } from "./item.js";
3
+ import { ItemComponent } from "./itemComponents.js";
4
+ // 定义 Armor 基类
5
+ export class Armor {
6
+ constructor(identifier, category, item_texture, texture_path, options = {}) {
7
+ this.identifier = identifier;
8
+ //默认分组
9
+ options["group"] = "minecraft:itemGroup.name.chestplate";
10
+ // 创建物品
11
+ this.item = new Item(identifier, category, item_texture, options);
12
+ // 创建附加物
13
+ this.attachable = new Attachable(identifier);
14
+ // 配置附加物
15
+ this.attachable
16
+ .addTexture("default", texture_path) // 添加默认纹理
17
+ .addMaterial("default", "armor") // 添加默认材质
18
+ .addMaterial("enchanted", "armor_enchanted") // 添加附魔材质
19
+ .addTexture("default", texture_path)
20
+ .addTexture("enchanted", "textures/misc/enchanted_actor_glint") // 添加附魔纹理
21
+ .addRenderController("controller.render.armor") // 添加渲染控制器
22
+ //默认类型 胸甲
23
+ .addGeometry("default", "geometry.player.armor.chestplate") // 添加几何模型
24
+ .setScript("parent_setup", "v.chest_layer_visible = 0.0;"); // 设置脚本
25
+ }
26
+ setArrachableGeometry(key, geometry) {
27
+ this.attachable.addGeometry(key, geometry);
28
+ return this;
29
+ }
30
+ }
31
+ // 扩展 Armor 类,实现胸甲
32
+ export class Chestplate extends Armor {
33
+ constructor(identifier, item_texture, texture_path, options = {}) {
34
+ super(identifier, "equipment", item_texture, texture_path, options);
35
+ options["group"] = "minecraft:itemGroup.name.chestplate";
36
+ //头盔专属
37
+ this.attachable.addGeometry("default", "geometry.player.armor.chestplate") // 添加几何模型
38
+ .setScript("parent_setup", "v.chest_layer_visible = 0.0;"); // 设置脚本
39
+ // 自定义胸甲物品
40
+ this.item.addComponent(ItemComponent.combineComponents(ItemComponent.setDisplayName("我的自定义胸甲"), // 设置显示名称
41
+ ItemComponent.setMaxStackSize(1), // 设置最大堆叠数量
42
+ ItemComponent.setWearable(5, "slot.armor.chest") // 设置为可穿戴,并指定装备槽
43
+ ));
44
+ }
45
+ }
46
+ // 扩展 Armor 类,实现靴子
47
+ export class Boot extends Armor {
48
+ constructor(identifier, item_texture, texture_path, options = {}) {
49
+ super(identifier, "equipment", item_texture, texture_path, options);
50
+ options["group"] = "minecraft:itemGroup.name.boots";
51
+ //头盔专属
52
+ this.attachable.addGeometry("default", "geometry.player.armor.boots") // 添加几何模型
53
+ .setScript("parent_setup", "v.boot_layer_visible = 0.0;"); // 设置脚本
54
+ // 自定义靴子物品
55
+ this.item.addComponent(ItemComponent.combineComponents(ItemComponent.setDisplayName("我的自定义靴子"), // 设置显示名称
56
+ ItemComponent.setMaxStackSize(1), // 设置最大堆叠数量
57
+ ItemComponent.setWearable(4, "slot.armor.feet") // 设置为可穿戴,并指定装备槽
58
+ ));
59
+ }
60
+ }
61
+ // 扩展 Armor 类,实现裤子
62
+ export class Leggings extends Armor {
63
+ constructor(identifier, item_texture, texture_path, options = {}) {
64
+ super(identifier, "equipment", item_texture, texture_path, options);
65
+ options["group"] = "minecraft:itemGroup.name.leggings";
66
+ //头盔专属
67
+ this.attachable.addGeometry("default", "geometry.player.armor.leggings") // 添加几何模型
68
+ .setScript("parent_setup", "v.leg_layer_visible = 0.0;"); // 设置脚本
69
+ // 自定义裤子物品
70
+ this.item.addComponent(ItemComponent.combineComponents(ItemComponent.setDisplayName("我的自定义裤子"), // 设置显示名称
71
+ ItemComponent.setMaxStackSize(1), // 设置最大堆叠数量
72
+ ItemComponent.setWearable(6, "slot.armor.legs") // 设置为可穿戴,并指定装备槽
73
+ ));
74
+ }
75
+ }
76
+ // 扩展 Armor 类,实现头盔
77
+ export class Helmet extends Armor {
78
+ constructor(identifier, item_texture, texture_path, options = {}) {
79
+ super(identifier, "equipment", item_texture, texture_path, options);
80
+ options["group"] = "minecraft:itemGroup.name.helmet";
81
+ //头盔专属
82
+ this.attachable.addGeometry("default", "geometry.player.armor.helmet") // 添加几何模型
83
+ .setScript("parent_setup", "v.helmet_layer_visible = 0.0;"); // 设置脚本
84
+ // 自定义头盔物品
85
+ this.item.addComponent(ItemComponent.combineComponents(ItemComponent.setDisplayName("我的自定义头盔"), // 设置显示名称
86
+ ItemComponent.setMaxStackSize(1), // 设置最大堆叠数量
87
+ ItemComponent.setWearable(3, "slot.armor.head") // 设置为可穿戴,并指定装备槽
88
+ ));
89
+ }
90
+ }
@@ -0,0 +1,6 @@
1
+ export class Attachable extends AddonAttachableDescription {
2
+ constructor(identifier: any);
3
+ getId(): string;
4
+ toJson(): Object;
5
+ }
6
+ import { AddonAttachableDescription } from "../addon/item/attachable.js";
@@ -0,0 +1,26 @@
1
+ import { AddonAttachable, AddonAttachableDefinition, AddonAttachableDescription } from "../addon/item/attachable.js";
2
+ export class Attachable extends AddonAttachableDescription {
3
+ constructor(identifier) {
4
+ super(identifier);
5
+ }
6
+ getId() {
7
+ return this.identifier;
8
+ }
9
+ toJson() {
10
+ const entity = new AddonAttachable("1.8.0", new AddonAttachableDefinition(this));
11
+ return entity.toJson();
12
+ }
13
+ }
14
+ /*
15
+ const attachable = new Attachable("test")
16
+ attachable.addMaterial("default", "armor")
17
+ attachable.addMaterial("enchanted","armor_enchanted")
18
+ attachable.addTexture("default","textures/models/armor/custom_main")
19
+ attachable.addTexture("enchanted", "textures/misc/enchanted_actor_glint")
20
+ attachable.addGeometry("default", "geometry.player.armor.chestplate")
21
+ attachable.addRenderController("controller.render.armor")
22
+ attachable.setScript("parent_setup","v.chest_layer_visible = 0.0;")
23
+
24
+ console.log(JSON.stringify(attachable.toJson(),null,2))
25
+ debugger
26
+ */
@@ -0,0 +1,24 @@
1
+ export class Food extends Item {
2
+ /**
3
+ * 物品类
4
+ * @param {string} identifier 物品唯一标识符
5
+ * @param {string} category 菜单栏分类 可选:"construction", "nature", "equipment", "items", and "none"
6
+ * @param {string} texture 物品纹理
7
+ * @param {Object} options 可选参数
8
+ * @param {string} options.group 分组
9
+ * @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
10
+ * @param {string} options.animation 使用动画,默认为 "eat"
11
+ * @param {boolean} options.canAlwaysEat 是否总是可以食用,默认为 false
12
+ * @param {number} options.nutrition 营养价值,默认为 0
13
+ * @param {number} options.saturationModifier 饱和度修正值,默认为 1
14
+ */
15
+ constructor(identifier: string, category: string, texture: string, options?: {
16
+ group: string;
17
+ hide_in_command: boolean;
18
+ animation: string;
19
+ canAlwaysEat: boolean;
20
+ nutrition: number;
21
+ saturationModifier: number;
22
+ });
23
+ }
24
+ import { Item } from "./item.js";
@@ -0,0 +1,38 @@
1
+ import { ItemComponent } from "./itemComponents.js";
2
+ import { Item } from "./item.js";
3
+ export class Food extends Item {
4
+ /**
5
+ * 物品类
6
+ * @param {string} identifier 物品唯一标识符
7
+ * @param {string} category 菜单栏分类 可选:"construction", "nature", "equipment", "items", and "none"
8
+ * @param {string} texture 物品纹理
9
+ * @param {Object} options 可选参数
10
+ * @param {string} options.group 分组
11
+ * @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
12
+ * @param {string} options.animation 使用动画,默认为 "eat"
13
+ * @param {boolean} options.canAlwaysEat 是否总是可以食用,默认为 false
14
+ * @param {number} options.nutrition 营养价值,默认为 0
15
+ * @param {number} options.saturationModifier 饱和度修正值,默认为 1
16
+ */
17
+ constructor(identifier, category, texture, options = {}) {
18
+ // 继承父类
19
+ super(identifier, category, texture, options);
20
+ // 解构 options 并设置默认值
21
+ const { animation = "eat", movement = 1, useDuration = 1, canAlwaysEat = false, nutrition = 0, saturationModifier = 1, } = options;
22
+ // 参数验证
23
+ if (typeof nutrition !== "number" || nutrition < 0) {
24
+ throw new Error('nutrition 必须是一个非负数');
25
+ }
26
+ if (typeof saturationModifier !== "number" || saturationModifier <= 0) {
27
+ throw new Error('saturationModifier 必须是一个正数');
28
+ }
29
+ if (typeof animation !== "string") {
30
+ throw new Error('animation 必须是字符串类型');
31
+ }
32
+ if (typeof canAlwaysEat !== "boolean") {
33
+ throw new Error('canAlwaysEat 必须是布尔类型');
34
+ }
35
+ // 添加组件
36
+ this.addComponent(ItemComponent.combineComponents(ItemComponent.setUseModifiers(movement, useDuration), ItemComponent.setFoodComponent(canAlwaysEat, nutrition, saturationModifier), ItemComponent.setUseAnimation(animation)));
37
+ }
38
+ }
@@ -0,0 +1,36 @@
1
+ export class Item {
2
+ /**
3
+ * 物品类
4
+ * @param {string} identifier 物品唯一标识符
5
+ * @param {string} category 菜单栏分类 可选:"construction", "nature", "equipment", "items", and "none"
6
+ * @param {string} texture 物品纹理
7
+ * @param {Object} options 可选参数
8
+ * @param {string} options.group 分组
9
+ * @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
10
+ */
11
+ constructor(identifier: string, category: string, texture: string, options?: {
12
+ group: string;
13
+ hide_in_command: boolean;
14
+ });
15
+ identifier: string;
16
+ category: string;
17
+ texture: string;
18
+ group: string;
19
+ hide_in_command: boolean;
20
+ components: Map<any, any>;
21
+ /**
22
+ * 添加组件
23
+ * @param {Map} componentMap 组件 Map
24
+ */
25
+ addComponent(componentMap: Map<any, any>): this;
26
+ /**
27
+ * 移除组件
28
+ * @param {string} key 组件名称
29
+ */
30
+ removeComponent(key: string): this;
31
+ /**
32
+ * 将物品转换为 JSON 格式
33
+ * @returns {Object} JSON 格式的物品对象
34
+ */
35
+ toJson(): Object;
36
+ }
@@ -0,0 +1,69 @@
1
+ import { ItemComponent } from "./itemComponents.js";
2
+ import { AddonItem, AddonItemDefinition, AddonItemDescription } from "../addon/item/item.js";
3
+ import { AddonMenuCategory } from "../addon/menuCategory.js";
4
+ export class Item {
5
+ /**
6
+ * 物品类
7
+ * @param {string} identifier 物品唯一标识符
8
+ * @param {string} category 菜单栏分类 可选:"construction", "nature", "equipment", "items", and "none"
9
+ * @param {string} texture 物品纹理
10
+ * @param {Object} options 可选参数
11
+ * @param {string} options.group 分组
12
+ * @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
13
+ */
14
+ constructor(identifier, category, texture, options = {}) {
15
+ // 参数校验
16
+ if (!identifier || typeof identifier !== "string") {
17
+ throw new Error("identifier is required and must be a string");
18
+ }
19
+ if (!category || typeof category !== "string") {
20
+ throw new Error("category is required and must be a string");
21
+ }
22
+ if (!texture || typeof texture !== "string") {
23
+ throw new Error("texture is required and must be a string");
24
+ }
25
+ const { group, hide_in_command = false, max_stack_size = 64, } = options;
26
+ this.identifier = identifier;
27
+ this.category = category;
28
+ this.texture = texture;
29
+ this.group = group;
30
+ this.hide_in_command = hide_in_command;
31
+ this.components = new Map();
32
+ // 初始化默认组件
33
+ this.addComponent(ItemComponent.combineComponents(ItemComponent.setIcon(this.texture), ItemComponent.setMaxStackSize(max_stack_size)));
34
+ }
35
+ /**
36
+ * 添加组件
37
+ * @param {Map} componentMap 组件 Map
38
+ */
39
+ addComponent(componentMap) {
40
+ if (!componentMap || !(componentMap instanceof Map)) {
41
+ throw new Error("componentMap is required and must be a Map");
42
+ }
43
+ for (const [key, value] of componentMap.entries()) {
44
+ this.components.set(key, value);
45
+ }
46
+ return this;
47
+ }
48
+ /**
49
+ * 移除组件
50
+ * @param {string} key 组件名称
51
+ */
52
+ removeComponent(key) {
53
+ if (!key || typeof key !== "string") {
54
+ throw new Error("key is required and must be a string");
55
+ }
56
+ this.components.delete(key);
57
+ return this;
58
+ }
59
+ /**
60
+ * 将物品转换为 JSON 格式
61
+ * @returns {Object} JSON 格式的物品对象
62
+ */
63
+ toJson() {
64
+ const item = new AddonItem("1.21.40", // 格式版本
65
+ new AddonItemDefinition(new AddonItemDescription(this.identifier, new AddonMenuCategory(this.category, this.group, this.hide_in_command)), Object.fromEntries(this.components) // 将 Map 转换为普通对象
66
+ ));
67
+ return item.toJson();
68
+ }
69
+ }
@@ -0,0 +1,113 @@
1
+ export class ItemComponent {
2
+ /**
3
+ * 物品的耐久度组件
4
+ * @param {number} max_durability 最大耐久
5
+ * @param {number} damage_chance_min 损坏最小几率
6
+ * @param {number} damage_chance_max 损坏最大几率
7
+ * @returns {ItemComponent}
8
+ */
9
+ static setDurability(max_durability: number, damage_chance_min?: number, damage_chance_max?: number): ItemComponent;
10
+ static setBlockPlacer(block: any, replace_block_item: any, use_on: any): Map<any, any>;
11
+ /**
12
+ *
13
+ * @param {Array} custom_components
14
+ * @returns
15
+ */
16
+ static setCustomComponents(custom_components: any[]): Map<any, any>;
17
+ /**
18
+ * 设置物品的可投掷组件。
19
+ * @param {Boolean} doSwingAnimation - 是否使用挥动动画。
20
+ * @param {Number} launchPowerScale - 投掷力量的缩放比例。
21
+ * @param {Number} maxDrawDuration - 最大蓄力时间。
22
+ * @param {Number} maxLaunchPower - 最大投掷力量。
23
+ * @param {Number} minDrawDuration - 最小蓄力时间。
24
+ * @param {Boolean} scalePowerByDrawDuration - 投掷力量是否随蓄力时间增加。
25
+ * @returns {Map} - 新的组件集合。
26
+ */
27
+ static setThrowable(doSwingAnimation?: boolean, launchPowerScale?: number, maxDrawDuration?: number, maxLaunchPower?: number, minDrawDuration?: number, scalePowerByDrawDuration?: boolean): Map<any, any>;
28
+ /**
29
+ * 设置物品的显示名称。
30
+ * @param {String} displayName - 显示名称或本地化键。
31
+ * @returns {Map} - 新的组件集合。
32
+ */
33
+ static setDisplayName(displayName: string): Map<any, any>;
34
+ /**
35
+ * 设置物品的食物组件。
36
+ * @param {Boolean} canAlwaysEat - 是否随时可以食用。
37
+ * @param {Number} nutrition - 营养值。
38
+ * @param {Number} saturationModifier - 饱和度修正值。
39
+ * @param {String} [usingConvertsTo] - 食用后转换的目标物品。
40
+ * @returns {Map} - 新的组件集合。
41
+ */
42
+ static setFoodComponent(canAlwaysEat: boolean, nutrition: number, saturationModifier: number, usingConvertsTo?: string): Map<any, any>;
43
+ /**
44
+ * 设置物品的燃料组件。
45
+ * @param {Number} duration - 燃料燃烧的持续时间(秒),最小值为 0.05。
46
+ * @returns {Map} - 新的组件集合。
47
+ */
48
+ static setFuel(duration: number): Map<any, any>;
49
+ /**
50
+ * 设置物品的附魔光效组件。
51
+ * @param {Boolean} hasGlint - 是否显示附魔光效。
52
+ * @returns {Map} - 新的组件集合。
53
+ */
54
+ static setGlint(hasGlint: boolean): Map<any, any>;
55
+ /**
56
+ * 设置物品的手持渲染方式组件。
57
+ * @param {Boolean} isHandEquipped - 是否像工具一样渲染。
58
+ * @returns {Map} - 新的组件集合。
59
+ */
60
+ static setHandEquipped(isHandEquipped: boolean): Map<any, any>;
61
+ /**
62
+ * 设置物品的图标组件。
63
+ * @param {String} texture - 图标纹理名称。
64
+ * @returns {Map} - 新的组件集合。
65
+ */
66
+ static setIcon(texture: string): Map<any, any>;
67
+ /**
68
+ * 设置物品的最大堆叠数量组件。
69
+ * @param {Number} maxStackSize - 最大堆叠数量,默认值为 64。
70
+ * @returns {Map} - 新的组件集合。
71
+ */
72
+ static setMaxStackSize(maxStackSize?: number): Map<any, any>;
73
+ /**
74
+ * 设置物品的投射物组件。
75
+ * @param {Number} [minimumCriticalPower] - 投射物需要蓄力多久才能造成暴击。
76
+ * @param {String} [projectileEntity] - 作为投射物发射的实体名称。
77
+ * @returns {Map} - 新的组件集合。
78
+ */
79
+ static setProjectile(minimumCriticalPower?: number, projectileEntity?: string): Map<any, any>;
80
+ /**
81
+ * 设置物品的使用修饰组件。
82
+ * @param {Number} [movementModifier] - 使用物品时玩家移动速度的缩放值。
83
+ * @param {Number} [useDuration] - 物品使用所需的时间(秒)。
84
+ * @returns {Map} - 新的组件集合。
85
+ */
86
+ static setUseModifiers(movementModifier?: number, useDuration?: number): Map<any, any>;
87
+ /**
88
+ * 设置物品的可穿戴组件。
89
+ * @param {Number} [protection=0] - 物品提供的保护值。
90
+ * @param {String} [slot] - 物品可以穿戴的槽位(如 "head"、"chest" 等)。
91
+ * @returns {Map} - 新的组件集合。
92
+ */
93
+ static setWearable(protection?: number, slot?: string): Map<any, any>;
94
+ /**
95
+ * 设置物品的使用动画组件。
96
+ * @param {String} animation - 物品使用时的动画类型(如 "eat"、"drink" 等)。
97
+ * @returns {Map} - 新的组件集合。
98
+ * @throws {Error} - 如果 animation 不是字符串类型。
99
+ */
100
+ static setUseAnimation(animation: string): Map<any, any>;
101
+ /**
102
+ * 将多个组件集合合并为一个。
103
+ * @param {...Map} componentMaps - 多个组件集合。
104
+ * @returns {Map} - 合并后的组件集合。
105
+ */
106
+ static combineComponents(...componentMaps: Map<any, any>[]): Map<any, any>;
107
+ /**
108
+ * 获取当前组件的 JSON 表示。
109
+ * @param {Map} components - 组件集合。
110
+ * @returns {Object} - 组件的 JSON 对象。
111
+ */
112
+ static toJSON(components: Map<any, any>): Object;
113
+ }
@@ -0,0 +1,225 @@
1
+ export class ItemComponent {
2
+ /**
3
+ * 物品的耐久度组件
4
+ * @param {number} max_durability 最大耐久
5
+ * @param {number} damage_chance_min 损坏最小几率
6
+ * @param {number} damage_chance_max 损坏最大几率
7
+ * @returns {ItemComponent}
8
+ */
9
+ static setDurability(max_durability, damage_chance_min = 0, damage_chance_max = 100) {
10
+ return new Map().set("minecraft:durability", {
11
+ "damage_chance": {
12
+ "min": damage_chance_min,
13
+ "max": damage_chance_max
14
+ },
15
+ "max_durability": max_durability
16
+ });
17
+ }
18
+ static setBlockPlacer(block, replace_block_item, use_on) {
19
+ return new Map().set("minecraft:block_placer", {
20
+ block: block,
21
+ replace_block_item: replace_block_item,
22
+ use_on: use_on
23
+ });
24
+ }
25
+ /**
26
+ *
27
+ * @param {Array} custom_components
28
+ * @returns
29
+ */
30
+ static setCustomComponents(custom_components) {
31
+ return new Map().set("minecraft:custom_components", [...custom_components]);
32
+ }
33
+ /**
34
+ * 设置物品的可投掷组件。
35
+ * @param {Boolean} doSwingAnimation - 是否使用挥动动画。
36
+ * @param {Number} launchPowerScale - 投掷力量的缩放比例。
37
+ * @param {Number} maxDrawDuration - 最大蓄力时间。
38
+ * @param {Number} maxLaunchPower - 最大投掷力量。
39
+ * @param {Number} minDrawDuration - 最小蓄力时间。
40
+ * @param {Boolean} scalePowerByDrawDuration - 投掷力量是否随蓄力时间增加。
41
+ * @returns {Map} - 新的组件集合。
42
+ */
43
+ static setThrowable(doSwingAnimation = false, launchPowerScale = 1.0, maxDrawDuration = 0.0, maxLaunchPower = 1.0, minDrawDuration = 0.0, scalePowerByDrawDuration = false) {
44
+ return new Map().set("minecraft:throwable", {
45
+ do_swing_animation: doSwingAnimation,
46
+ launch_power_scale: launchPowerScale,
47
+ max_draw_duration: maxDrawDuration,
48
+ max_launch_power: maxLaunchPower,
49
+ min_draw_duration: minDrawDuration,
50
+ scale_power_by_draw_duration: scalePowerByDrawDuration,
51
+ });
52
+ }
53
+ /**
54
+ * 设置物品的显示名称。
55
+ * @param {String} displayName - 显示名称或本地化键。
56
+ * @returns {Map} - 新的组件集合。
57
+ */
58
+ static setDisplayName(displayName) {
59
+ if (typeof displayName !== "string") {
60
+ throw new Error('显示名称必须是字符串类型');
61
+ }
62
+ return new Map().set("minecraft:display_name", { value: displayName });
63
+ }
64
+ /**
65
+ * 设置物品的食物组件。
66
+ * @param {Boolean} canAlwaysEat - 是否随时可以食用。
67
+ * @param {Number} nutrition - 营养值。
68
+ * @param {Number} saturationModifier - 饱和度修正值。
69
+ * @param {String} [usingConvertsTo] - 食用后转换的目标物品。
70
+ * @returns {Map} - 新的组件集合。
71
+ */
72
+ static setFoodComponent(canAlwaysEat, nutrition, saturationModifier, usingConvertsTo) {
73
+ return new Map().set("minecraft:food", {
74
+ can_always_eat: canAlwaysEat,
75
+ nutrition: nutrition || 0,
76
+ saturation_modifier: saturationModifier || 0.6,
77
+ using_converts_to: usingConvertsTo || undefined,
78
+ });
79
+ }
80
+ /**
81
+ * 设置物品的燃料组件。
82
+ * @param {Number} duration - 燃料燃烧的持续时间(秒),最小值为 0.05。
83
+ * @returns {Map} - 新的组件集合。
84
+ */
85
+ static setFuel(duration) {
86
+ if (typeof duration !== "number" || duration < 0.05) {
87
+ throw new Error('燃料持续时间必须是一个大于或等于 0.05 的数字');
88
+ }
89
+ return new Map().set("minecraft:fuel", { duration });
90
+ }
91
+ /**
92
+ * 设置物品的附魔光效组件。
93
+ * @param {Boolean} hasGlint - 是否显示附魔光效。
94
+ * @returns {Map} - 新的组件集合。
95
+ */
96
+ static setGlint(hasGlint) {
97
+ if (typeof hasGlint !== "boolean") {
98
+ throw new Error('附魔光效值必须是布尔类型');
99
+ }
100
+ return new Map().set("minecraft:glint", hasGlint);
101
+ }
102
+ /**
103
+ * 设置物品的手持渲染方式组件。
104
+ * @param {Boolean} isHandEquipped - 是否像工具一样渲染。
105
+ * @returns {Map} - 新的组件集合。
106
+ */
107
+ static setHandEquipped(isHandEquipped) {
108
+ if (typeof isHandEquipped !== "boolean") {
109
+ throw new Error('手持渲染方式值必须是布尔类型');
110
+ }
111
+ return new Map().set("minecraft:hand_equipped", isHandEquipped);
112
+ }
113
+ /**
114
+ * 设置物品的图标组件。
115
+ * @param {String} texture - 图标纹理名称。
116
+ * @returns {Map} - 新的组件集合。
117
+ */
118
+ static setIcon(texture) {
119
+ if (typeof texture !== "string") {
120
+ throw new Error('图标纹理必须是字符串类型');
121
+ }
122
+ return new Map().set("minecraft:icon", texture);
123
+ }
124
+ /**
125
+ * 设置物品的最大堆叠数量组件。
126
+ * @param {Number} maxStackSize - 最大堆叠数量,默认值为 64。
127
+ * @returns {Map} - 新的组件集合。
128
+ */
129
+ static setMaxStackSize(maxStackSize = 64) {
130
+ if (typeof maxStackSize !== "number" || maxStackSize <= 0 || !Number.isInteger(maxStackSize)) {
131
+ throw new Error('最大堆叠数量必须是正整数');
132
+ }
133
+ return new Map().set("minecraft:max_stack_size", maxStackSize);
134
+ }
135
+ /**
136
+ * 设置物品的投射物组件。
137
+ * @param {Number} [minimumCriticalPower] - 投射物需要蓄力多久才能造成暴击。
138
+ * @param {String} [projectileEntity] - 作为投射物发射的实体名称。
139
+ * @returns {Map} - 新的组件集合。
140
+ */
141
+ static setProjectile(minimumCriticalPower, projectileEntity) {
142
+ const projectileComponent = {};
143
+ if (minimumCriticalPower !== undefined) {
144
+ if (typeof minimumCriticalPower !== "number" || minimumCriticalPower < 0) {
145
+ throw new Error('minimumCriticalPower 必须是非负数');
146
+ }
147
+ projectileComponent.minimum_critical_power = minimumCriticalPower;
148
+ }
149
+ if (projectileEntity !== undefined) {
150
+ if (typeof projectileEntity !== "string") {
151
+ throw new Error('projectileEntity 必须是字符串类型');
152
+ }
153
+ projectileComponent.projectile_entity = projectileEntity;
154
+ }
155
+ return new Map().set("minecraft:projectile", projectileComponent);
156
+ }
157
+ /**
158
+ * 设置物品的使用修饰组件。
159
+ * @param {Number} [movementModifier] - 使用物品时玩家移动速度的缩放值。
160
+ * @param {Number} [useDuration] - 物品使用所需的时间(秒)。
161
+ * @returns {Map} - 新的组件集合。
162
+ */
163
+ static setUseModifiers(movementModifier, useDuration) {
164
+ const useModifiersComponent = {};
165
+ if (movementModifier !== undefined) {
166
+ if (typeof movementModifier !== "number") {
167
+ throw new Error('movementModifier 必须是数字类型');
168
+ }
169
+ useModifiersComponent.movement_modifier = movementModifier;
170
+ }
171
+ if (useDuration !== undefined) {
172
+ if (typeof useDuration !== "number" || useDuration < 0) {
173
+ throw new Error('useDuration 必须是非负数');
174
+ }
175
+ useModifiersComponent.use_duration = useDuration;
176
+ }
177
+ return new Map().set("minecraft:use_modifiers", useModifiersComponent);
178
+ }
179
+ /**
180
+ * 设置物品的可穿戴组件。
181
+ * @param {Number} [protection=0] - 物品提供的保护值。
182
+ * @param {String} [slot] - 物品可以穿戴的槽位(如 "head"、"chest" 等)。
183
+ * @returns {Map} - 新的组件集合。
184
+ */
185
+ static setWearable(protection = 0, slot) {
186
+ const wearableComponent = { protection };
187
+ if (slot !== undefined) {
188
+ if (typeof slot !== "string") {
189
+ throw new Error('slot 必须是字符串类型');
190
+ }
191
+ wearableComponent.slot = slot;
192
+ }
193
+ return new Map().set("minecraft:wearable", wearableComponent);
194
+ }
195
+ /**
196
+ * 设置物品的使用动画组件。
197
+ * @param {String} animation - 物品使用时的动画类型(如 "eat"、"drink" 等)。
198
+ * @returns {Map} - 新的组件集合。
199
+ * @throws {Error} - 如果 animation 不是字符串类型。
200
+ */
201
+ static setUseAnimation(animation) {
202
+ // 检查 animation 是否为字符串
203
+ if (typeof animation !== "string") {
204
+ throw new Error('animation 必须是字符串类型');
205
+ }
206
+ // 返回包含动画设置的 Map 对象
207
+ return new Map().set("minecraft:use_animation", animation);
208
+ }
209
+ /**
210
+ * 将多个组件集合合并为一个。
211
+ * @param {...Map} componentMaps - 多个组件集合。
212
+ * @returns {Map} - 合并后的组件集合。
213
+ */
214
+ static combineComponents(...componentMaps) {
215
+ return new Map(componentMaps.flatMap(map => [...map]));
216
+ }
217
+ /**
218
+ * 获取当前组件的 JSON 表示。
219
+ * @param {Map} components - 组件集合。
220
+ * @returns {Object} - 组件的 JSON 对象。
221
+ */
222
+ static toJSON(components) {
223
+ return Object.fromEntries(components);
224
+ }
225
+ }
@@ -0,0 +1,12 @@
1
+ export class GRegistry {
2
+ static dataList: any[];
3
+ /**
4
+ * 生成注册器
5
+ * @param {string} name 文件名字
6
+ * @param {string} root 根目录,如 "behavior"、"resource" 等
7
+ * @param {string} path 数据的路径,如 "blocks/"、"items/"、"recipes/" 等
8
+ * @param {string} data 实例 必须包含 toJson 方法
9
+ */
10
+ static register(name: string, root: string, path: string, data: string): void;
11
+ static getDataList(): any[];
12
+ }