sapdon 3.0.2 → 3.0.3

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 (208) hide show
  1. package/dist/cli/build.d.ts +7 -0
  2. package/dist/cli/build.js +234 -0
  3. package/dist/cli/dev-server/client.d.ts +2 -0
  4. package/dist/cli/dev-server/client.js +21 -0
  5. package/dist/cli/dev-server/config.d.ts +3 -0
  6. package/dist/cli/dev-server/config.js +3 -0
  7. package/dist/cli/dev-server/handles.d.ts +4 -0
  8. package/dist/cli/dev-server/handles.js +5 -0
  9. package/dist/cli/dev-server/hmr.d.ts +1 -0
  10. package/dist/cli/dev-server/hmr.js +13 -0
  11. package/dist/cli/dev-server/index.d.ts +4 -0
  12. package/dist/cli/dev-server/index.js +17 -0
  13. package/dist/cli/dev-server/server.d.ts +14 -0
  14. package/dist/cli/dev-server/server.js +59 -0
  15. package/dist/cli/dev-server/syncFiles.d.ts +3 -0
  16. package/dist/cli/dev-server/syncFiles.js +37 -0
  17. package/dist/cli/index.d.ts +23 -0
  18. package/dist/cli/index.js +1 -0
  19. package/dist/cli/init.d.ts +9 -0
  20. package/dist/cli/init.js +80 -0
  21. package/dist/cli/load.d.ts +3 -0
  22. package/dist/cli/load.js +94 -0
  23. package/dist/cli/start.d.ts +2 -0
  24. package/dist/cli/start.js +2 -0
  25. package/dist/cli/tools/textureSet.d.ts +13 -0
  26. package/dist/cli/tools/textureSet.js +103 -0
  27. package/dist/cli/utils.d.ts +13 -0
  28. package/dist/cli/utils.js +89 -0
  29. package/dist/core/addon/biome.d.ts +22 -0
  30. package/dist/core/addon/biome.js +27 -0
  31. package/dist/core/addon/block/block.d.ts +41 -0
  32. package/dist/core/addon/block/block.js +46 -0
  33. package/dist/core/addon/controllers/animationController.d.ts +43 -0
  34. package/dist/core/addon/controllers/animationController.js +73 -0
  35. package/dist/core/addon/entity/clientEntity.d.ts +107 -0
  36. package/dist/core/addon/entity/clientEntity.js +149 -0
  37. package/dist/core/addon/entity/entity.d.ts +42 -0
  38. package/dist/core/addon/entity/entity.js +50 -0
  39. package/dist/core/addon/feature/oreFeature.d.ts +19 -0
  40. package/dist/core/addon/feature/oreFeature.js +24 -0
  41. package/dist/core/addon/featureRule.d.ts +20 -0
  42. package/dist/core/addon/featureRule.js +25 -0
  43. package/dist/core/addon/item/attachable.d.ts +94 -0
  44. package/dist/core/addon/item/attachable.js +134 -0
  45. package/dist/core/addon/item/item.d.ts +19 -0
  46. package/dist/core/addon/item/item.js +26 -0
  47. package/dist/core/addon/manifest.d.ts +49 -0
  48. package/dist/core/addon/manifest.js +65 -0
  49. package/dist/core/addon/menuCategory.d.ts +6 -0
  50. package/dist/core/addon/menuCategory.js +7 -0
  51. package/dist/core/addon/recipe/baseRecipe.d.ts +12 -0
  52. package/dist/core/addon/recipe/baseRecipe.js +23 -0
  53. package/dist/core/addon/recipe/data.d.ts +66 -0
  54. package/dist/core/addon/recipe/data.js +74 -0
  55. package/dist/core/addon/recipe/furnace.d.ts +17 -0
  56. package/dist/core/addon/recipe/furnace.js +43 -0
  57. package/dist/core/addon/recipe/shaped.d.ts +26 -0
  58. package/dist/core/addon/recipe/shaped.js +53 -0
  59. package/dist/core/addon/recipe/shapeless.d.ts +18 -0
  60. package/dist/core/addon/recipe/shapeless.js +36 -0
  61. package/dist/core/biome/biome.d.ts +14 -0
  62. package/dist/core/biome/biome.js +23 -0
  63. package/dist/core/biome/biomeComponent.d.ts +46 -0
  64. package/dist/core/biome/biomeComponent.js +77 -0
  65. package/dist/core/block/basicBlock.d.ts +48 -0
  66. package/dist/core/block/basicBlock.js +105 -0
  67. package/dist/core/block/block.d.ts +32 -0
  68. package/dist/core/block/block.js +92 -0
  69. package/dist/core/block/blockComponent.d.ts +187 -0
  70. package/dist/core/block/blockComponent.js +500 -0
  71. package/dist/core/block/cropBlock.d.ts +4 -0
  72. package/dist/core/block/cropBlock.js +27 -0
  73. package/dist/core/block/geometryBlock.d.ts +12 -0
  74. package/dist/core/block/geometryBlock.js +16 -0
  75. package/dist/core/block/oreBlock.d.ts +9 -0
  76. package/dist/core/block/oreBlock.js +25 -0
  77. package/dist/core/block/rotatableBlock.d.ts +27 -0
  78. package/dist/core/block/rotatableBlock.js +107 -0
  79. package/dist/core/block/tileBlock.d.ts +17 -0
  80. package/dist/core/block/tileBlock.js +125 -0
  81. package/dist/core/entity/basicEntity.d.ts +111 -0
  82. package/dist/core/entity/basicEntity.js +170 -0
  83. package/dist/core/entity/behavior/followMob.d.ts +12 -0
  84. package/dist/core/entity/behavior/followMob.js +35 -0
  85. package/dist/core/entity/behavior/followParent.d.ts +7 -0
  86. package/dist/core/entity/behavior/followParent.js +15 -0
  87. package/dist/core/entity/behavior/randomStroll.d.ts +31 -0
  88. package/dist/core/entity/behavior/randomStroll.js +63 -0
  89. package/dist/core/entity/behavior/tempt.d.ts +73 -0
  90. package/dist/core/entity/behavior/tempt.js +134 -0
  91. package/dist/core/entity/bundles/basicBundle.d.ts +13 -0
  92. package/dist/core/entity/bundles/basicBundle.js +45 -0
  93. package/dist/core/entity/clientEntity.d.ts +20 -0
  94. package/dist/core/entity/clientEntity.js +37 -0
  95. package/dist/core/entity/componets/entityComponet.d.ts +202 -0
  96. package/dist/core/entity/componets/entityComponet.js +347 -0
  97. package/dist/core/entity/data/nativeEntityData.d.ts +9 -0
  98. package/dist/core/entity/data/nativeEntityData.js +38 -0
  99. package/dist/core/entity/entity.d.ts +15 -0
  100. package/dist/core/entity/entity.js +18 -0
  101. package/dist/core/entity/nativeEntity.d.ts +8 -0
  102. package/dist/core/entity/nativeEntity.js +28 -0
  103. package/dist/core/entity/navigation/walk.d.ts +23 -0
  104. package/dist/core/entity/navigation/walk.js +56 -0
  105. package/dist/core/entity/projectile.d.ts +3 -0
  106. package/dist/core/entity/projectile.js +7 -0
  107. package/dist/core/factory/biomeFactory.d.ts +4 -0
  108. package/dist/core/factory/biomeFactory.js +13 -0
  109. package/dist/core/factory/blockFactory.d.ts +34 -0
  110. package/dist/core/factory/blockFactory.js +143 -0
  111. package/dist/core/factory/entityFactory.d.ts +17 -0
  112. package/dist/core/factory/entityFactory.js +75 -0
  113. package/dist/core/factory/featureFactory.d.ts +6 -0
  114. package/dist/core/factory/featureFactory.js +23 -0
  115. package/dist/core/factory/itemExtra.d.ts +8 -0
  116. package/dist/core/factory/itemExtra.js +9 -0
  117. package/dist/core/factory/itemFactory.d.ts +27 -0
  118. package/dist/core/factory/itemFactory.js +112 -0
  119. package/dist/core/factory/recipeFactory.d.ts +18 -0
  120. package/dist/core/factory/recipeFactory.js +39 -0
  121. package/dist/core/factory/uiFactory.d.ts +12 -0
  122. package/dist/core/factory/uiFactory.js +32 -0
  123. package/dist/core/feature/oreFeature.d.ts +10 -0
  124. package/dist/core/feature/oreFeature.js +11 -0
  125. package/dist/core/feature-rule/condition/biomeFilter.d.ts +26 -0
  126. package/dist/core/feature-rule/condition/biomeFilter.js +36 -0
  127. package/dist/core/feature-rule/condition/featureConditions.d.ts +27 -0
  128. package/dist/core/feature-rule/condition/featureConditions.js +37 -0
  129. package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +17 -0
  130. package/dist/core/feature-rule/distribution/coordinateDistribution.js +23 -0
  131. package/dist/core/feature-rule/distribution/featureDistribution.d.ts +31 -0
  132. package/dist/core/feature-rule/distribution/featureDistribution.js +41 -0
  133. package/dist/core/feature-rule/featureRule.d.ts +17 -0
  134. package/dist/core/feature-rule/featureRule.js +26 -0
  135. package/dist/core/index.d.ts +2062 -0
  136. package/dist/core/index.js +1 -0
  137. package/dist/core/item/armor.d.ts +21 -0
  138. package/dist/core/item/armor.js +90 -0
  139. package/dist/core/item/attachable.d.ts +6 -0
  140. package/dist/core/item/attachable.js +26 -0
  141. package/dist/core/item/food.d.ts +24 -0
  142. package/dist/core/item/food.js +38 -0
  143. package/dist/core/item/item.d.ts +36 -0
  144. package/dist/core/item/item.js +69 -0
  145. package/dist/core/item/itemComponents.d.ts +113 -0
  146. package/dist/core/item/itemComponents.js +225 -0
  147. package/dist/core/registry.d.ts +12 -0
  148. package/dist/core/registry.js +16 -0
  149. package/dist/core/texture.d.ts +18 -0
  150. package/dist/core/texture.js +38 -0
  151. package/dist/core/ui/buttonMapping.d.ts +97 -0
  152. package/dist/core/ui/buttonMapping.js +132 -0
  153. package/dist/core/ui/dataBindingObject.d.ts +97 -0
  154. package/dist/core/ui/dataBindingObject.js +134 -0
  155. package/dist/core/ui/elements/button.d.ts +21 -0
  156. package/dist/core/ui/elements/button.js +101 -0
  157. package/dist/core/ui/elements/collectionPanel.d.ts +12 -0
  158. package/dist/core/ui/elements/collectionPanel.js +53 -0
  159. package/dist/core/ui/elements/grid.d.ts +8 -0
  160. package/dist/core/ui/elements/grid.js +33 -0
  161. package/dist/core/ui/elements/image.d.ts +13 -0
  162. package/dist/core/ui/elements/image.js +55 -0
  163. package/dist/core/ui/elements/label.d.ts +14 -0
  164. package/dist/core/ui/elements/label.js +61 -0
  165. package/dist/core/ui/elements/panel.d.ts +11 -0
  166. package/dist/core/ui/elements/panel.js +49 -0
  167. package/dist/core/ui/elements/scrollingPanel.d.ts +14 -0
  168. package/dist/core/ui/elements/scrollingPanel.js +59 -0
  169. package/dist/core/ui/elements/stackPanel.d.ts +14 -0
  170. package/dist/core/ui/elements/stackPanel.js +37 -0
  171. package/dist/core/ui/elements/uiElement.d.ts +53 -0
  172. package/dist/core/ui/elements/uiElement.js +129 -0
  173. package/dist/core/ui/properties/control.d.ts +214 -0
  174. package/dist/core/ui/properties/control.js +286 -0
  175. package/dist/core/ui/properties/dataBinding.d.ts +6 -0
  176. package/dist/core/ui/properties/dataBinding.js +16 -0
  177. package/dist/core/ui/properties/factory.d.ts +37 -0
  178. package/dist/core/ui/properties/factory.js +62 -0
  179. package/dist/core/ui/properties/gridProp.d.ts +65 -0
  180. package/dist/core/ui/properties/gridProp.js +90 -0
  181. package/dist/core/ui/properties/input.d.ts +97 -0
  182. package/dist/core/ui/properties/input.js +134 -0
  183. package/dist/core/ui/properties/layout.d.ts +105 -0
  184. package/dist/core/ui/properties/layout.js +145 -0
  185. package/dist/core/ui/properties/scrollView.d.ts +105 -0
  186. package/dist/core/ui/properties/scrollView.js +145 -0
  187. package/dist/core/ui/properties/sound.d.ts +47 -0
  188. package/dist/core/ui/properties/sound.js +66 -0
  189. package/dist/core/ui/properties/sprite.d.ts +161 -0
  190. package/dist/core/ui/properties/sprite.js +222 -0
  191. package/dist/core/ui/properties/text.d.ts +135 -0
  192. package/dist/core/ui/properties/text.js +187 -0
  193. package/dist/core/ui/registry/uiSystemRegistry.d.ts +8 -0
  194. package/dist/core/ui/registry/uiSystemRegistry.js +26 -0
  195. package/dist/core/ui/systems/chest.d.ts +5 -0
  196. package/dist/core/ui/systems/chest.js +21 -0
  197. package/dist/core/ui/systems/containerUISystem.d.ts +67 -0
  198. package/dist/core/ui/systems/containerUISystem.js +214 -0
  199. package/dist/core/ui/systems/guidebook.d.ts +9 -0
  200. package/dist/core/ui/systems/guidebook.js +206 -0
  201. package/dist/core/ui/systems/serverForm.d.ts +13 -0
  202. package/dist/core/ui/systems/serverForm.js +116 -0
  203. package/dist/core/ui/systems/system.d.ts +16 -0
  204. package/dist/core/ui/systems/system.js +37 -0
  205. package/dist/oc/index.d.ts +142 -0
  206. package/dist/oc/index.js +1 -0
  207. package/doc/sapdon-ts.md +35 -1
  208. package/package.json +6 -8
@@ -0,0 +1,347 @@
1
+ export class EntityComponent {
2
+ static setMovement(speed) {
3
+ return new Map().set("minecraft:movement", {
4
+ "value": speed
5
+ });
6
+ }
7
+ static setCollisionBox(width, height) {
8
+ return new Map().set("minecraft:collision_box", {
9
+ width: width,
10
+ height: height,
11
+ });
12
+ }
13
+ /**
14
+ * 将多个组件集合合并为一个。
15
+ * @param {...Map} componentMaps - 多个组件集合。
16
+ * @returns {Map} - 合并后的组件集合。
17
+ */
18
+ static combineComponents(...componentMaps) {
19
+ return new Map(componentMaps.flatMap(map => [...map]));
20
+ }
21
+ /**
22
+ * 创建 minecraft:health 组件。
23
+ * @param {Object} options 配置选项
24
+ * @param {number} options.max 实体的最大生命值
25
+ * @param {number|Object} options.value 实体的初始生命值(可以是固定值或范围值)
26
+ * @returns {Map} 包含 minecraft:health 组件的 Map 对象
27
+ * @throws {Error} 如果参数无效。
28
+ */
29
+ static setHealth(options = {}) {
30
+ const { max, value } = options;
31
+ // 参数验证
32
+ this.validateHealthParameters(max, value);
33
+ // 构建组件
34
+ const healthComponent = {
35
+ max: max,
36
+ value: value,
37
+ };
38
+ // 返回 Map 对象
39
+ const healthMap = new Map();
40
+ healthMap.set("minecraft:health", healthComponent);
41
+ return healthMap;
42
+ }
43
+ /**
44
+ * 验证 minecraft:health 组件的参数。
45
+ * @param {number} max 最大生命值
46
+ * @param {number|Object} value 初始生命值
47
+ * @throws {Error} 如果参数无效。
48
+ */
49
+ static validateHealthParameters(max, value) {
50
+ if (typeof max !== "number" || max <= 0) {
51
+ throw new Error("max 必须是一个正数");
52
+ }
53
+ if ((typeof value !== "number" && typeof value !== "object") ||
54
+ (typeof value === "number" && value <= 0) ||
55
+ (typeof value === "object" &&
56
+ (typeof value.range_min !== "number" ||
57
+ typeof value.range_max !== "number" ||
58
+ value.range_min <= 0 ||
59
+ value.range_max <= 0))) {
60
+ throw new Error("value 必须是一个正数或包含 range_min 和 range_max 的对象");
61
+ }
62
+ }
63
+ /**
64
+ * 创建 minecraft:physics 组件。
65
+ * @param {boolean} has_collision 是否碰撞(默认:true)
66
+ * @param {boolean} has_gravity 是否受重力影响(默认:true)
67
+ * @param {boolean} push_towards_closest_space 是否在卡住时推向最近空间(默认:false)
68
+ * @returns {Map} 包含 minecraft:physics 组件的 Map 对象
69
+ * @throws {Error} 如果参数不是布尔类型。
70
+ */
71
+ static setPhysics(has_collision = true, has_gravity = true, push_towards_closest_space = false) {
72
+ // 参数验证
73
+ if (typeof has_collision !== "boolean" ||
74
+ typeof has_gravity !== "boolean" ||
75
+ typeof push_towards_closest_space !== "boolean") {
76
+ throw new Error("所有参数必须是布尔类型");
77
+ }
78
+ // 创建 Map 对象
79
+ const physicsMap = new Map();
80
+ physicsMap.set("minecraft:physics", {
81
+ has_collision: has_collision,
82
+ has_gravity: has_gravity,
83
+ push_towards_closest_space: push_towards_closest_space,
84
+ });
85
+ return physicsMap;
86
+ }
87
+ /**
88
+ * 创建 minecraft:scale 组件。
89
+ * @param {number} value 实体的缩放比例(默认:1.0)
90
+ * @returns {Map} 包含 minecraft:scale 组件的 Map 对象
91
+ * @throws {Error} 如果参数无效。
92
+ */
93
+ static setScale(value = 1.0) {
94
+ // 参数验证
95
+ if (typeof value !== "number" || value <= 0) {
96
+ throw new Error("value 必须是一个正数");
97
+ }
98
+ // 返回 Map 对象
99
+ const scaleMap = new Map();
100
+ scaleMap.set("minecraft:scale", {
101
+ value: value,
102
+ });
103
+ return scaleMap;
104
+ }
105
+ /**
106
+ * 创建默认的 minecraft:nameable 组件(不填写参数)。
107
+ * @returns {Map} 包含 minecraft:nameable 组件的 Map 对象
108
+ */
109
+ static setDefaultNameable() {
110
+ const nameableMap = new Map();
111
+ nameableMap.set("minecraft:nameable", {});
112
+ return nameableMap;
113
+ }
114
+ /**
115
+ * 创建自定义的 minecraft:nameable 组件(填写参数)。
116
+ * @param {boolean} allowNameTagRenaming 是否允许使用命名牌重命名(默认:true)
117
+ * @param {boolean} alwaysShow 是否始终显示名称(默认:false)
118
+ * @param {Object} defaultTrigger 默认触发事件(可选)
119
+ * @param {Array} nameActions 特殊名称及其对应的事件(可选)
120
+ * @returns {Map} 包含 minecraft:nameable 组件的 Map 对象
121
+ * @throws {Error} 如果参数无效。
122
+ */
123
+ static setCustomNameable(allowNameTagRenaming = true, alwaysShow = false, defaultTrigger = null, nameActions = []) {
124
+ // 参数验证
125
+ if (typeof allowNameTagRenaming !== "boolean" ||
126
+ typeof alwaysShow !== "boolean") {
127
+ throw new Error("allowNameTagRenaming 和 alwaysShow 必须是布尔类型");
128
+ }
129
+ // 构建组件
130
+ const nameableComponent = {
131
+ allow_name_tag_renaming: allowNameTagRenaming,
132
+ always_show: alwaysShow,
133
+ };
134
+ // 添加 default_trigger(如果存在)
135
+ if (defaultTrigger) {
136
+ nameableComponent.default_trigger = defaultTrigger;
137
+ }
138
+ // 添加 name_actions(如果存在)
139
+ if (nameActions.length > 0) {
140
+ nameableComponent.name_actions = nameActions;
141
+ }
142
+ // 返回 Map 对象
143
+ const nameableMap = new Map();
144
+ nameableMap.set("minecraft:nameable", nameableComponent);
145
+ return nameableMap;
146
+ }
147
+ /**
148
+ * 创建 minecraft:pushable 组件。
149
+ * @param {boolean} isPushable 是否可以被其他实体推动(默认:true)
150
+ * @param {boolean} isPushableByPiston 是否可以被活塞推动(默认:true)
151
+ * @returns {Map} 包含 minecraft:pushable 组件的 Map 对象
152
+ * @throws {Error} 如果参数无效。
153
+ */
154
+ static setPushable(isPushable = true, isPushableByPiston = true) {
155
+ // 参数验证
156
+ if (typeof isPushable !== "boolean" || typeof isPushableByPiston !== "boolean") {
157
+ throw new Error("isPushable 和 isPushableByPiston 必须是布尔类型");
158
+ }
159
+ // 返回 Map 对象
160
+ const pushableMap = new Map();
161
+ pushableMap.set("minecraft:pushable", {
162
+ is_pushable: isPushable,
163
+ is_pushable_by_piston: isPushableByPiston,
164
+ });
165
+ return pushableMap;
166
+ }
167
+ /**
168
+ * 创建 minecraft:jump.static 组件。
169
+ * @param {number} jumpPower 跳跃的初始垂直速度(默认:0.42)
170
+ * @returns {Map} 包含 minecraft:jump.static 组件的 Map 对象
171
+ * @throws {Error} 如果参数无效。
172
+ */
173
+ static setJumpStatic(jumpPower = 0.42) {
174
+ // 参数验证
175
+ if (typeof jumpPower !== "number" || jumpPower < 0) {
176
+ throw new Error("jumpPower 必须是一个非负数");
177
+ }
178
+ // 返回 Map 对象
179
+ const jumpStaticMap = new Map();
180
+ jumpStaticMap.set("minecraft:jump.static", {
181
+ jump_power: jumpPower,
182
+ });
183
+ return jumpStaticMap;
184
+ }
185
+ /**
186
+ * 创建 minecraft:navigation.walk 组件。
187
+ * @param {Object} options 配置选项
188
+ * @param {boolean} options.avoidDamageBlocks 是否避免伤害性方块(默认:false)
189
+ * @param {boolean} options.avoidPortals 是否避免传送门(默认:false)
190
+ * @param {boolean} options.avoidSun 是否避免阳光下的方块(默认:false)
191
+ * @param {boolean} options.avoidWater 是否避免水(默认:false)
192
+ * @param {Array} options.blocksToAvoid 需要避免的方块列表(默认:[])
193
+ * @param {boolean} options.canBreach 是否可以跳出水面(默认:false)
194
+ * @param {boolean} options.canBreakDoors 是否可以破坏门(默认:false)
195
+ * @param {boolean} options.canFloat 是否可以漂浮(默认:false)
196
+ * @param {boolean} options.canJump 是否可以跳跃(默认:true)
197
+ * @param {boolean} options.canOpenDoors 是否可以开门(默认:false)
198
+ * @param {boolean} options.canOpenIronDoors 是否可以开铁门(默认:false)
199
+ * @param {boolean} options.canPassDoors 是否可以穿过门(默认:true)
200
+ * @param {boolean} options.canPathFromAir 是否可以在空中开始路径规划(默认:false)
201
+ * @param {boolean} options.canPathOverLava 是否可以在熔岩表面行走(默认:false)
202
+ * @param {boolean} options.canPathOverWater 是否可以在水面上行走(默认:false)
203
+ * @param {boolean} options.canSink 是否会在水中下沉(默认:true)
204
+ * @param {boolean} options.canSwim 是否可以游泳(默认:false)
205
+ * @param {boolean} options.canWalk 是否可以在地面上行走(默认:true)
206
+ * @param {boolean} options.canWalkInLava 是否可以在熔岩中行走(默认:false)
207
+ * @param {boolean} options.isAmphibious 是否可以在水下行走(默认:false)
208
+ * @returns {Map} 包含 minecraft:navigation.walk 组件的 Map 对象
209
+ * @throws {Error} 如果参数无效。
210
+ */
211
+ static setNavigationWalk(options = {}) {
212
+ // 默认值
213
+ const { avoidDamageBlocks = false, avoidPortals = false, avoidSun = false, avoidWater = false, blocksToAvoid = [], canBreach = false, canBreakDoors = false, canFloat = false, canJump = true, canOpenDoors = false, canOpenIronDoors = false, canPassDoors = true, canPathFromAir = false, canPathOverLava = false, canPathOverWater = false, canSink = true, canSwim = false, canWalk = true, canWalkInLava = false, isAmphibious = false, } = options;
214
+ // 构建组件
215
+ const navigationWalkComponent = {
216
+ avoid_damage_blocks: avoidDamageBlocks,
217
+ avoid_portals: avoidPortals,
218
+ avoid_sun: avoidSun,
219
+ avoid_water: avoidWater,
220
+ blocks_to_avoid: blocksToAvoid,
221
+ can_breach: canBreach,
222
+ can_break_doors: canBreakDoors,
223
+ can_float: canFloat,
224
+ can_jump: canJump,
225
+ can_open_doors: canOpenDoors,
226
+ can_open_iron_doors: canOpenIronDoors,
227
+ can_pass_doors: canPassDoors,
228
+ can_path_from_air: canPathFromAir,
229
+ can_path_over_lava: canPathOverLava,
230
+ can_path_over_water: canPathOverWater,
231
+ can_sink: canSink,
232
+ can_swim: canSwim,
233
+ can_walk: canWalk,
234
+ can_walk_in_lava: canWalkInLava,
235
+ is_amphibious: isAmphibious,
236
+ };
237
+ // 返回 Map 对象
238
+ const navigationWalkMap = new Map();
239
+ navigationWalkMap.set("minecraft:navigation.walk", navigationWalkComponent);
240
+ return navigationWalkMap;
241
+ }
242
+ /**
243
+ * 创建 minecraft:movement.basic 组件。
244
+ * @param {number} maxTurn 实体每 tick 可以转向的最大角度(默认:30.0)
245
+ * @returns {Map} 包含 minecraft:movement.basic 组件的 Map 对象
246
+ * @throws {Error} 如果参数无效。
247
+ */
248
+ static setMovementBasic(maxTurn = 30.0) {
249
+ // 参数验证
250
+ if (typeof maxTurn !== "number" || maxTurn < 0) {
251
+ throw new Error("maxTurn 必须是一个非负数");
252
+ }
253
+ // 返回 Map 对象
254
+ const movementBasicMap = new Map();
255
+ movementBasicMap.set("minecraft:movement.basic", {
256
+ max_turn: maxTurn,
257
+ });
258
+ return movementBasicMap;
259
+ }
260
+ /**
261
+ * 创建 minecraft:projectile 组件。
262
+ * @param {Object} options 配置选项
263
+ * @param {number} options.anchor 发射锚点(默认:0)
264
+ * @param {number} options.angleOffset 角度偏移(默认:0.0)
265
+ * @param {boolean} options.catchFire 是否点燃目标(默认:false)
266
+ * @param {boolean} options.critParticleOnHurt 是否生成暴击粒子(默认:false)
267
+ * @param {boolean} options.destroyOnHurt 是否在击中时销毁(默认:false)
268
+ * @param {string} options.filter 过滤的实体(可选)
269
+ * @param {boolean} options.fireAffectedByGriefing 是否受游戏规则影响(默认:false)
270
+ * @param {number} options.gravity 重力值(默认:0.05)
271
+ * @param {string} options.hitSound 击中声音(可选)
272
+ * @param {string} options.hitGroundSound 击中地面声音(可选)
273
+ * @param {boolean} options.homing 是否追踪目标(默认:false)
274
+ * @param {number} options.inertia 空气惯性(默认:0.99)
275
+ * @param {boolean} options.isDangerous 是否对玩家危险(默认:false)
276
+ * @param {boolean} options.knockback 是否击退目标(默认:true)
277
+ * @param {boolean} options.lightning 是否召唤闪电(默认:false)
278
+ * @param {number} options.liquidInertia 水中惯性(默认:0.6)
279
+ * @param {boolean} options.multipleTargets 是否可击中多个目标(默认:true)
280
+ * @param {number[]} options.offset 发射偏移量(默认:[0, 0, 0])
281
+ * @param {number} options.onFireTime 着火时间(默认:0.0)
282
+ * @param {Object} options.onHit 击中时的行为(可选)
283
+ * @param {string} options.particle 碰撞粒子(默认:"ironcrack")
284
+ * @param {number} options.power 初始速度(默认:1.3)
285
+ * @param {number} options.reflectImmunity 反射免疫时间(默认:0.0)
286
+ * @param {boolean} options.reflectOnHurt 是否反射(默认:false)
287
+ * @param {string} options.shootSound 发射声音(可选)
288
+ * @param {boolean} options.shootTarget 是否朝向目标发射(默认:true)
289
+ * @param {boolean} options.shouldBounce 是否反弹(默认:false)
290
+ * @param {boolean} options.splashPotion 是否为喷溅药水(默认:false)
291
+ * @param {number} options.splashRange 喷溅范围(默认:4)
292
+ * @param {boolean} options.stopOnHurt 是否在击中时停止(默认:false)
293
+ * @param {number} options.uncertaintyBase 基础精度(默认:0)
294
+ * @param {number} options.uncertaintyMultiplier 精度倍数(默认:0)
295
+ * @returns {Map} 包含 minecraft:projectile 组件的 Map 对象
296
+ * @throws {Error} 如果参数无效。
297
+ */
298
+ static setProjectile(options = {}) {
299
+ // 默认值
300
+ const { anchor = 0, angleOffset = 0.0, catchFire = false, critParticleOnHurt = false, destroyOnHurt = false, filter = null, fireAffectedByGriefing = false, gravity = 0.05, hitSound = null, hitGroundSound = null, homing = false, inertia = 0.99, isDangerous = false, knockback = true, lightning = false, liquidInertia = 0.6, multipleTargets = true, offset = [0, 0, 0], onFireTime = 0.0, onHit = null, particle = "ironcrack", power = 1.3, reflectImmunity = 0.0, reflectOnHurt = false, shootSound = null, shootTarget = true, shouldBounce = false, splashPotion = false, splashRange = 4, stopOnHurt = false, uncertaintyBase = 0, uncertaintyMultiplier = 0, } = options;
301
+ // 构建组件
302
+ const projectileComponent = {
303
+ anchor,
304
+ angle_offset: angleOffset,
305
+ catch_fire: catchFire,
306
+ crit_particle_on_hurt: critParticleOnHurt,
307
+ destroy_on_hurt: destroyOnHurt,
308
+ fire_affected_by_griefing: fireAffectedByGriefing,
309
+ gravity,
310
+ homing,
311
+ inertia,
312
+ is_dangerous: isDangerous,
313
+ knockback,
314
+ lightning,
315
+ liquid_inertia: liquidInertia,
316
+ multiple_targets: multipleTargets,
317
+ offset,
318
+ on_fire_time: onFireTime,
319
+ particle,
320
+ power,
321
+ reflect_immunity: reflectImmunity,
322
+ reflect_on_hurt: reflectOnHurt,
323
+ shoot_target: shootTarget,
324
+ should_bounce: shouldBounce,
325
+ splash_potion: splashPotion,
326
+ splash_range: splashRange,
327
+ stop_on_hurt: stopOnHurt,
328
+ uncertainty_base: uncertaintyBase,
329
+ uncertainty_multiplier: uncertaintyMultiplier,
330
+ };
331
+ // 添加可选参数
332
+ if (filter)
333
+ projectileComponent.filter = filter;
334
+ if (hitSound)
335
+ projectileComponent.hit_sound = hitSound;
336
+ if (hitGroundSound)
337
+ projectileComponent.hit_ground_sound = hitGroundSound;
338
+ if (onHit)
339
+ projectileComponent.on_hit = onHit;
340
+ if (shootSound)
341
+ projectileComponent.shoot_sound = shootSound;
342
+ // 返回 Map 对象
343
+ const projectileMap = new Map();
344
+ projectileMap.set("minecraft:projectile", projectileComponent);
345
+ return projectileMap;
346
+ }
347
+ }
@@ -0,0 +1,9 @@
1
+ export class NativeEntityData {
2
+ static behDataPath: string;
3
+ static resDataPath: string;
4
+ static behData: null;
5
+ static resData: null;
6
+ static loadDataSync(filePath: any): any;
7
+ static reloadDataSync(): void;
8
+ static getDataById(type: any, id: any): any;
9
+ }
@@ -0,0 +1,38 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ // 获取当前文件的目录路径
5
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+ export class NativeEntityData {
7
+ // 使用 __dirname 获取当前文件所在目录
8
+ static behDataPath = path.join(__dirname, 'data_bp.json');
9
+ static resDataPath = path.join(__dirname, 'data_rp.json');
10
+ static behData = null;
11
+ static resData = null;
12
+ static loadDataSync(filePath) {
13
+ try {
14
+ const data = fs.readFileSync(filePath, 'utf8');
15
+ return JSON.parse(data);
16
+ }
17
+ catch (error) {
18
+ console.error(`Failed to load data from $$${filePath}:`, error);
19
+ return {};
20
+ }
21
+ }
22
+ static reloadDataSync() {
23
+ this.behData = this.loadDataSync(this.behDataPath);
24
+ this.resData = this.loadDataSync(this.resDataPath);
25
+ }
26
+ static getDataById(type, id) {
27
+ if (typeof type !== 'string' || typeof id !== 'string') {
28
+ throw new Error("type and id must be strings");
29
+ }
30
+ if (!this.behData || !this.resData) {
31
+ this.reloadDataSync();
32
+ }
33
+ if (type === 'beh') {
34
+ return this.behData[id] || null;
35
+ }
36
+ return this.resData[id] || null;
37
+ }
38
+ }
@@ -0,0 +1,15 @@
1
+ export class Entity {
2
+ /**
3
+ *
4
+ * @param {*} identifier
5
+ * @param {*} texture
6
+ * @param {*} behData
7
+ * @param {*} resData
8
+ * @param {*} options
9
+ */
10
+ constructor(identifier: any, texture: any, behData: any, resData: any, options?: any);
11
+ identifier: any;
12
+ entity: BasicEntity;
13
+ client_entity: import("../addon/entity/clientEntity.js").AddonClientEntityDescription;
14
+ }
15
+ import { BasicEntity } from "./basicEntity.js";
@@ -0,0 +1,18 @@
1
+ import { BasicEntity } from "./basicEntity.js";
2
+ import { ClientEntity } from "./clientEntity.js";
3
+ export class Entity {
4
+ /**
5
+ *
6
+ * @param {*} identifier
7
+ * @param {*} texture
8
+ * @param {*} behData
9
+ * @param {*} resData
10
+ * @param {*} options
11
+ */
12
+ constructor(identifier, texture, behData, resData, options = {}) {
13
+ // 创建行为实体和客户端实体
14
+ this.identifier = identifier;
15
+ this.entity = new BasicEntity(identifier, options, behData);
16
+ this.client_entity = new ClientEntity(identifier, resData).addTexture("default", texture);
17
+ }
18
+ }
@@ -0,0 +1,8 @@
1
+ export class NativeEntity {
2
+ constructor(identifier: any, proto_id: any, options?: {});
3
+ identifier: any;
4
+ entity: BasicEntity;
5
+ client_entity: ClientEntity;
6
+ }
7
+ import { BasicEntity } from "./basicEntity.js";
8
+ import { ClientEntity } from "./clientEntity.js";
@@ -0,0 +1,28 @@
1
+ import { BasicEntity } from "./basicEntity.js";
2
+ import { ClientEntity } from "./clientEntity.js";
3
+ import { NativeEntityData } from "./data/nativeEntityData.js";
4
+ export class NativeEntity {
5
+ constructor(identifier, proto_id, options = {}) {
6
+ try {
7
+ // 获取行为数据
8
+ const behData = NativeEntityData.getDataById("beh", proto_id)?.["minecraft:entity"];
9
+ if (!behData) {
10
+ throw new Error(`Behavior data not found for proto_id: ${proto_id}`);
11
+ }
12
+ // 获取资源数据
13
+ const resData = NativeEntityData.getDataById("res", proto_id)?.["minecraft:client_entity"]?.["description"];
14
+ if (!resData) {
15
+ throw new Error(`Resource data not found for proto_id: ${proto_id}`);
16
+ }
17
+ options["runtime_identifier"] = proto_id;
18
+ // 创建行为实体和客户端实体
19
+ this.identifier = identifier;
20
+ this.entity = new BasicEntity(identifier, options, behData);
21
+ this.client_entity = new ClientEntity(identifier, resData);
22
+ }
23
+ catch (error) {
24
+ console.error(`Failed to create NativeEntity ${identifier}:`, error);
25
+ throw error; // 抛出错误,避免继续执行
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,23 @@
1
+ export namespace Navigation {
2
+ function walk(options?: {
3
+ avoid_damage_blocks?: boolean | undefined;
4
+ avoid_portals?: boolean | undefined;
5
+ avoid_sun?: boolean | undefined;
6
+ avoid_water?: boolean | undefined;
7
+ blocks_to_avoid?: any[] | undefined;
8
+ can_breach?: boolean | undefined;
9
+ can_break_doors?: boolean | undefined;
10
+ can_jump?: boolean | undefined;
11
+ can_open_doors?: boolean | undefined;
12
+ can_open_iron_doors?: boolean | undefined;
13
+ can_pass_doors?: boolean | undefined;
14
+ can_path_from_air?: boolean | undefined;
15
+ can_path_over_lava?: boolean | undefined;
16
+ can_path_over_water?: boolean | undefined;
17
+ can_sink?: boolean | undefined;
18
+ can_swim?: boolean | undefined;
19
+ can_walk?: boolean | undefined;
20
+ can_walk_in_lava?: boolean | undefined;
21
+ is_amphibious?: boolean | undefined;
22
+ }): Map<any, any>;
23
+ }
@@ -0,0 +1,56 @@
1
+ export const Navigation = {
2
+ /**
3
+ * 创建 minecraft:navigation.walk 组件的配置。
4
+ * @param {Object} options - 配置选项。
5
+ * @param {boolean} [options.avoid_damage_blocks=false] - 是否避免伤害方块。
6
+ * @param {boolean} [options.avoid_portals=false] - 是否避免传送门。
7
+ * @param {boolean} [options.avoid_sun=false] - 是否避免阳光。
8
+ * @param {boolean} [options.avoid_water=false] - 是否避免水。
9
+ * @param {Array} [options.blocks_to_avoid=[]] - 需要避免的方块列表。
10
+ * @param {boolean} [options.can_breach=false] - 是否可以突破方块。
11
+ * @param {boolean} [options.can_break_doors=false] - 是否可以破坏门。
12
+ * @param {boolean} [options.can_jump=true] - 是否可以跳跃。
13
+ * @param {boolean} [options.can_open_doors=false] - 是否可以开门。
14
+ * @param {boolean} [options.can_open_iron_doors=false] - 是否可以开铁门。
15
+ * @param {boolean} [options.can_pass_doors=true] - 是否可以通过门。
16
+ * @param {boolean} [options.can_path_from_air=false] - 是否可以从空中寻路。
17
+ * @param {boolean} [options.can_path_over_lava=false] - 是否可以在熔岩上寻路。
18
+ * @param {boolean} [options.can_path_over_water=false] - 是否可以在水上寻路。
19
+ * @param {boolean} [options.can_sink=true] - 是否可以沉入水中。
20
+ * @param {boolean} [options.can_swim=false] - 是否可以游泳。
21
+ * @param {boolean} [options.can_walk=true] - 是否可以行走。
22
+ * @param {boolean} [options.can_walk_in_lava=false] - 是否可以在熔岩中行走。
23
+ * @param {boolean} [options.is_amphibious=false] - 是否是两栖动物。
24
+ * @returns {Map} - 包含 minecraft:navigation.walk 组件的 Map 对象。
25
+ */
26
+ walk: function (options = {}) {
27
+ // 默认值
28
+ const defaultOptions = {
29
+ avoid_damage_blocks: false,
30
+ avoid_portals: false,
31
+ avoid_sun: false,
32
+ avoid_water: false,
33
+ blocks_to_avoid: [],
34
+ can_breach: false,
35
+ can_break_doors: false,
36
+ can_jump: true,
37
+ can_open_doors: false,
38
+ can_open_iron_doors: false,
39
+ can_pass_doors: true,
40
+ can_path_from_air: false,
41
+ can_path_over_lava: false,
42
+ can_path_over_water: false,
43
+ can_sink: true,
44
+ can_swim: false,
45
+ can_walk: true,
46
+ can_walk_in_lava: false,
47
+ is_amphibious: false
48
+ };
49
+ // 合并用户提供的选项和默认值
50
+ const finalOptions = { ...defaultOptions, ...options };
51
+ // 返回 Map 对象
52
+ const navigationMap = new Map();
53
+ navigationMap.set("minecraft:navigation.walk", finalOptions);
54
+ return navigationMap;
55
+ }
56
+ };
@@ -0,0 +1,3 @@
1
+ export class Projectile extends NativeEntity {
2
+ }
3
+ import { NativeEntity } from "./nativeEntity.js";
@@ -0,0 +1,7 @@
1
+ import { NativeEntity } from "./nativeEntity.js";
2
+ export class Projectile extends NativeEntity {
3
+ constructor(identifier, texture_path, options = {}) {
4
+ super(identifier, "minecraft:snowball", options);
5
+ this.client_entity.addTexture("default", texture_path);
6
+ }
7
+ }
@@ -0,0 +1,4 @@
1
+ export namespace BiomeAPI {
2
+ function createBiome(identifier: any): Biome;
3
+ }
4
+ import { Biome } from "../biome/biome.js";
@@ -0,0 +1,13 @@
1
+ import { Biome } from "../biome/biome.js";
2
+ import { GRegistry } from "../registry.js";
3
+ const registerBiome = (biome) => {
4
+ const biome_name = biome.identifier.split(":")[biome.identifier.split(":").length - 1];
5
+ GRegistry.register(biome_name, "behavior", "biomes/", biome);
6
+ };
7
+ export const BiomeAPI = {
8
+ createBiome: function (identifier) {
9
+ const biome = new Biome(identifier);
10
+ registerBiome(biome);
11
+ return biome;
12
+ }
13
+ };
@@ -0,0 +1,34 @@
1
+ export namespace BlockAPI {
2
+ function createBasicBlock(identifier: string, category: string, textures_arr: any[], options?: {
3
+ group: string;
4
+ hide_in_command: boolean;
5
+ }): BasicBlock;
6
+ function createBlock(identifier: string, category: string, variantDatas: any[], options?: {
7
+ group: string;
8
+ hide_in_command: boolean;
9
+ ambient_occlusion: boolean;
10
+ face_dimming: boolean;
11
+ render_method: string;
12
+ }): Block;
13
+ function createRotatableBlock(identifier: string, category: string, textures_arr: any[], options?: {
14
+ group: string;
15
+ hide_in_command: boolean;
16
+ rotationType: string;
17
+ yRotationOffset: number;
18
+ }): RotatableBlock;
19
+ function createGeometryBlock(identifier: any, category: any, geometry: any, material_instances: any, options?: {}): GeometryBlock;
20
+ function createOreBlock(identifier: any, category: any, textures_arr: any, options?: {}): OreBlock;
21
+ function createCropBlock(identifier: string, category: string, variantDatas: any[], options?: {
22
+ group: string;
23
+ hide_in_command: boolean;
24
+ ambient_occlusion: boolean;
25
+ face_dimming: boolean;
26
+ render_method: string;
27
+ }): CropBlock;
28
+ }
29
+ import { BasicBlock } from "../block/basicBlock.js";
30
+ import { Block } from "../block/block.js";
31
+ import { RotatableBlock } from "../block/rotatableBlock.js";
32
+ import { GeometryBlock } from "../block/geometryBlock.js";
33
+ import { OreBlock } from "../block/oreBlock.js";
34
+ import { CropBlock } from "../block/cropBlock.js";