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,500 @@
1
+ export class BlockComponent {
2
+ static setTick(interval_range, looping) {
3
+ return new Map().set("minecraft:tick", {
4
+ interval_range: interval_range,
5
+ looping: looping
6
+ });
7
+ }
8
+ /**
9
+ *
10
+ * @param {Array} custom_components
11
+ * @returns
12
+ */
13
+ static setCustomComponents(custom_components) {
14
+ return new Map().set("minecraft:custom_components", [...custom_components]);
15
+ }
16
+ /**
17
+ * 创建一个用于 Minecraft 方块的变换对象,并返回一个 Map。
18
+ * @param {number[]} [translation=[0, 0, 0]] - 平移向量 [x, y, z]。
19
+ * @param {number[]} [scale=[1, 1, 1]] - 缩放向量 [x, y, z]。
20
+ * @param {number[]} [scale_pivot=[0, 0, 0]] - 缩放的枢轴点 [x, y, z]。
21
+ * @param {number[]} [rotation=[0, 0, 0]] - 旋转向量(角度)[x, y, z]。
22
+ * @param {number[]} [rotation_pivot=[0, 0, 0]] - 旋转的枢轴点 [x, y, z]。
23
+ * @returns {Map} - 一个包含变换数据的 Map 对象。
24
+ * @throws {Error} - 如果任何参数无效,则抛出错误。
25
+ */
26
+ static setTransformation(translation = [0, 0, 0], scale = [1, 1, 1], scale_pivot = [0, 0, 0], rotation = [0, 0, 0], rotation_pivot = [0, 0, 0]) {
27
+ // 验证输入参数是否为有效的 3D 向量
28
+ const validateVector = (vector, name) => {
29
+ if (!Array.isArray(vector) ||
30
+ vector.length !== 3 ||
31
+ !vector.every((value) => typeof value === "number" && !isNaN(value))) {
32
+ throw new Error(`${name} 必须是一个包含 3 个有效数字的数组`);
33
+ }
34
+ };
35
+ // 验证所有输入参数
36
+ validateVector(translation, "translation");
37
+ validateVector(scale, "scale");
38
+ validateVector(scale_pivot, "scale_pivot");
39
+ validateVector(rotation, "rotation");
40
+ validateVector(rotation_pivot, "rotation_pivot");
41
+ // 创建变换对象
42
+ const transformation = {
43
+ translation,
44
+ scale,
45
+ scale_pivot,
46
+ rotation,
47
+ rotation_pivot,
48
+ };
49
+ // 将变换对象存入 Map
50
+ const transformationMap = new Map();
51
+ transformationMap.set("minecraft:transformation", transformation);
52
+ return transformationMap;
53
+ }
54
+ /**
55
+ * 设置方块的呼吸行为。
56
+ * @param {String} value - 呼吸行为,可选值为 "solid" 或 "air"。
57
+ * @returns {Map} - 新的组件集合。
58
+ */
59
+ static setBreathability(value) {
60
+ if (value !== "solid" && value !== "air") {
61
+ throw new Error('breathability must be either "solid" or "air"');
62
+ }
63
+ return new Map().set("minecraft:breathability", value);
64
+ }
65
+ /**
66
+ * 启用或禁用方块的碰撞箱。
67
+ * @param {Boolean} enabled - 是否启用碰撞箱。
68
+ * @returns {Map} - 新的组件集合。
69
+ */
70
+ static setCollisionBoxEnabled(enabled) {
71
+ if (typeof enabled !== "boolean") {
72
+ throw new Error('enabled must be a boolean');
73
+ }
74
+ return new Map().set("minecraft:collision_box", enabled);
75
+ }
76
+ /**
77
+ * 设置自定义的碰撞箱。
78
+ * @param {Array} origin - 碰撞箱的起点坐标 [x, y, z]。
79
+ * @param {Array} size - 碰撞箱的大小 [width, height, depth]。
80
+ * @returns {Map} - 新的组件集合。
81
+ */
82
+ static setCollisionBoxCustom(origin, size) {
83
+ if (!Array.isArray(origin) || origin.length !== 3) {
84
+ throw new Error('origin must be an array of 3 numbers');
85
+ }
86
+ if (!Array.isArray(size) || size.length !== 3) {
87
+ throw new Error('size must be an array of 3 numbers');
88
+ }
89
+ const [x, y, z] = origin;
90
+ const [width, height, depth] = size;
91
+ if (x < -8 || x > 8 || y < 0 || y > 16 || z < -8 || z > 8) {
92
+ throw new Error('origin must be in the range (-8, 0, -8) to (8, 16, 8)');
93
+ }
94
+ if (x + width < -8 || x + width > 8 || y + height < 0 || y + height > 16 || z + depth < -8 || z + depth > 8) {
95
+ throw new Error('origin + size must be in the range (-8, 0, -8) to (8, 16, 8)');
96
+ }
97
+ return new Map().set("minecraft:collision_box", { origin, size });
98
+ }
99
+ /**
100
+ * 设置方块的合成台属性。
101
+ * @param {Array} craftingTags - 合成标签。
102
+ * @param {String} tableName - 合成台名称。
103
+ * @returns {Map} - 新的组件集合。
104
+ */
105
+ static setCraftingTable(craftingTags, tableName) {
106
+ if (!Array.isArray(craftingTags) || craftingTags.length > 64) {
107
+ throw new Error('craftingTags must be an array with a maximum of 64 tags');
108
+ }
109
+ for (const tag of craftingTags) {
110
+ if (typeof tag !== "string" || tag.length > 64) {
111
+ throw new Error('each crafting tag must be a string with a maximum of 64 characters');
112
+ }
113
+ }
114
+ if (tableName && typeof tableName !== "string") {
115
+ throw new Error('tableName must be a string');
116
+ }
117
+ return new Map().set("minecraft:crafting_table", {
118
+ crafting_tags: craftingTags,
119
+ table_name: tableName,
120
+ });
121
+ }
122
+ /**
123
+ * 启用或禁用方块的爆炸抗性。
124
+ * @param {Boolean} enabled - 是否启用爆炸抗性。
125
+ * @returns {Map} - 新的组件集合。
126
+ */
127
+ static setDestructibleByExplosionEnabled(enabled) {
128
+ if (typeof enabled !== "boolean") {
129
+ throw new Error('enabled must be a boolean');
130
+ }
131
+ return new Map().set("minecraft:destructible_by_explosion", enabled);
132
+ }
133
+ /**
134
+ * 设置自定义的爆炸抗性。
135
+ * @param {Number} explosionResistance - 爆炸抗性值。
136
+ * @returns {Map} - 新的组件集合。
137
+ */
138
+ static setDestructibleByExplosionCustom(explosionResistance) {
139
+ if (typeof explosionResistance !== "number") {
140
+ throw new Error('explosionResistance must be a number');
141
+ }
142
+ return new Map().set("minecraft:destructible_by_explosion", {
143
+ explosion_resistance: explosionResistance,
144
+ });
145
+ }
146
+ /**
147
+ * 启用或禁用方块的挖掘抗性。
148
+ * @param {Boolean} enabled - 是否启用挖掘抗性。
149
+ * @returns {Map} - 新的组件集合。
150
+ */
151
+ static setDestructibleByMiningEnabled(enabled) {
152
+ if (typeof enabled !== "boolean") {
153
+ throw new Error('enabled must be a boolean');
154
+ }
155
+ return new Map().set("minecraft:destructible_by_mining", enabled);
156
+ }
157
+ /**
158
+ * 设置自定义的挖掘抗性。
159
+ * @param {Number} secondsToDestroy - 破坏所需时间(秒)。
160
+ * @param {Array} itemSpecificSpeeds - 特定工具的挖掘速度。
161
+ * @returns {Map} - 新的组件集合。
162
+ */
163
+ static setDestructibleByMiningCustom(secondsToDestroy, itemSpecificSpeeds) {
164
+ if (typeof secondsToDestroy !== "number") {
165
+ throw new Error('secondsToDestroy must be a number');
166
+ }
167
+ if (itemSpecificSpeeds && Array.isArray(itemSpecificSpeeds)) {
168
+ for (const speed of itemSpecificSpeeds) {
169
+ if (typeof speed.destroy_speed !== "number") {
170
+ throw new Error('destroy_speed must be a number');
171
+ }
172
+ if (!speed.item) {
173
+ throw new Error('item is required in item_specific_speeds');
174
+ }
175
+ }
176
+ }
177
+ return new Map().set("minecraft:destructible_by_mining", {
178
+ seconds_to_destroy: secondsToDestroy,
179
+ item_specific_speeds: itemSpecificSpeeds,
180
+ });
181
+ }
182
+ /**
183
+ * 设置方块的显示名称。
184
+ * @param {String} displayName - 显示名称。
185
+ * @returns {Map} - 新的组件集合。
186
+ */
187
+ static setDisplayName(displayName) {
188
+ if (typeof displayName !== "string") {
189
+ throw new Error('displayName must be a string');
190
+ }
191
+ return new Map().set("minecraft:display_name", displayName);
192
+ }
193
+ /**
194
+ * 启用或禁用方块的易燃性。
195
+ * @param {Boolean} enabled - 是否启用易燃性。
196
+ * @returns {Map} - 新的组件集合。
197
+ */
198
+ static setFlammableEnabled(enabled) {
199
+ if (typeof enabled !== "boolean") {
200
+ throw new Error('enabled must be a boolean');
201
+ }
202
+ return new Map().set("minecraft:flammable", enabled);
203
+ }
204
+ /**
205
+ * 设置自定义的易燃性。
206
+ * @param {Number} catchChanceModifier - 着火概率。
207
+ * @param {Number} destroyChanceModifier - 被火焰摧毁的概率。
208
+ * @returns {Map} - 新的组件集合。
209
+ */
210
+ static setFlammableCustom(catchChanceModifier, destroyChanceModifier) {
211
+ if (typeof catchChanceModifier !== "number" || catchChanceModifier < 0) {
212
+ throw new Error('catchChanceModifier must be a number greater than or equal to 0');
213
+ }
214
+ if (typeof destroyChanceModifier !== "number" || destroyChanceModifier < 0) {
215
+ throw new Error('destroyChanceModifier must be a number greater than or equal to 0');
216
+ }
217
+ return new Map().set("minecraft:flammable", {
218
+ catch_chance_modifier: catchChanceModifier,
219
+ destroy_chance_modifier: destroyChanceModifier,
220
+ });
221
+ }
222
+ /**
223
+ * 设置方块的摩擦力。
224
+ * @param {Number} value - 摩擦力值,范围为 0.0 到 0.9。
225
+ * @returns {Map} - 新的组件集合。
226
+ */
227
+ static setFriction(value) {
228
+ if (typeof value !== "number" || value < 0.0 || value > 0.9) {
229
+ throw new Error('friction must be a number between 0.0 and 0.9');
230
+ }
231
+ return new Map().set("minecraft:friction", value);
232
+ }
233
+ /**
234
+ * 设置方块的几何模型。
235
+ * @param {String} identifier - 几何模型标识符。
236
+ * @param {Object} bone_visibility - 骨骼可见性配置。
237
+ * @returns {Map} - 新的组件集合。
238
+ */
239
+ static setGeometry(identifier, bone_visibility) {
240
+ if (typeof identifier !== "string") {
241
+ throw new Error('identifier must be a string');
242
+ }
243
+ return new Map().set("minecraft:geometry", {
244
+ identifier: identifier,
245
+ bone_visibility: bone_visibility
246
+ });
247
+ }
248
+ /**
249
+ * 设置方块的物品视觉属性。
250
+ * @param {String} geometry - 几何模型标识符。
251
+ * @param {Object} materialInstances - 材质实例配置。
252
+ * @returns {Map} - 新的组件集合。
253
+ */
254
+ static setItemVisual(geometry, materialInstances) {
255
+ if (typeof geometry !== "string") {
256
+ throw new Error('geometry must be a string');
257
+ }
258
+ if (!materialInstances || typeof materialInstances !== "object") {
259
+ throw new Error('materialInstances must be an object');
260
+ }
261
+ return new Map().set("minecraft:item_visual", {
262
+ geometry,
263
+ material_instances: materialInstances,
264
+ });
265
+ }
266
+ /**
267
+ * 设置方块的光衰减值。
268
+ * @param {Number} value - 光的衰减值,范围为 0 到 15。
269
+ * @returns {Map} - 新的组件集合。
270
+ */
271
+ static setLightDampening(value) {
272
+ if (typeof value !== "number" || value < 0 || value > 15) {
273
+ throw new Error('lightDampening must be a number between 0 and 15');
274
+ }
275
+ return new Map().set("minecraft:light_dampening", value);
276
+ }
277
+ /**
278
+ * 设置方块的光照强度。
279
+ * @param {Number} value - 光照强度,范围为 0 到 15。
280
+ * @returns {Map} - 新的组件集合。
281
+ */
282
+ static setLightEmission(value) {
283
+ if (typeof value !== "number" || value < 0 || value > 15) {
284
+ throw new Error('lightEmission must be a number between 0 and 15');
285
+ }
286
+ return new Map().set("minecraft:light_emission", value);
287
+ }
288
+ /**
289
+ * 设置方块的液体检测属性。
290
+ * @param {Boolean} canContainLiquid - 是否可以包含液体。
291
+ * @param {String} liquidType - 液体类型。
292
+ * @param {String} onLiquidTouches - 对液体的反应方式。
293
+ * @param {Array} stopsLiquidFlowingFromDirection - 阻止液体流动的方向。
294
+ * @returns {Map} - 新的组件集合。
295
+ */
296
+ static setLiquidDetection(canContainLiquid, liquidType, onLiquidTouches, stopsLiquidFlowingFromDirection) {
297
+ if (typeof canContainLiquid !== "boolean") {
298
+ throw new Error('canContainLiquid must be a boolean');
299
+ }
300
+ if (liquidType && liquidType !== "water") {
301
+ throw new Error('liquidType must be "water"');
302
+ }
303
+ const validReactions = ["blocking", "broken", "popped", "no_reaction"];
304
+ if (onLiquidTouches && !validReactions.includes(onLiquidTouches)) {
305
+ throw new Error('onLiquidTouches must be one of: "blocking", "broken", "popped", "no_reaction"');
306
+ }
307
+ const validDirections = ["up", "down", "north", "south", "east", "west"];
308
+ if (stopsLiquidFlowingFromDirection && Array.isArray(stopsLiquidFlowingFromDirection)) {
309
+ for (const direction of stopsLiquidFlowingFromDirection) {
310
+ if (!validDirections.includes(direction)) {
311
+ throw new Error('stopsLiquidFlowingFromDirection must be one of: "up", "down", "north", "south", "east", "west"');
312
+ }
313
+ }
314
+ }
315
+ return new Map().set("minecraft:liquid_detection", {
316
+ can_contain_liquid: canContainLiquid,
317
+ liquid_type: liquidType,
318
+ on_liquid_touches: onLiquidTouches,
319
+ stops_liquid_flowing_from_direction: stopsLiquidFlowingFromDirection,
320
+ });
321
+ }
322
+ /**
323
+ * 设置方块的战利品表路径。
324
+ * @param {String} path - 战利品表路径。
325
+ * @returns {Map} - 新的组件集合。
326
+ */
327
+ static setLoot(path) {
328
+ if (typeof path !== "string" || path.length > 256) {
329
+ throw new Error('path must be a string with a maximum length of 256 characters');
330
+ }
331
+ return new Map().set("minecraft:loot", path);
332
+ }
333
+ /**
334
+ * 设置方块的地图颜色。
335
+ * @param {String|Array} value - 地图颜色,可以是十六进制字符串或 RGB 数组。
336
+ * @returns {Map} - 新的组件集合。
337
+ */
338
+ static setMapColor(value) {
339
+ if (typeof value === "string") {
340
+ if (!/^#[0-9A-Fa-f]{6}$/.test(value)) {
341
+ throw new Error('mapColor must be a valid hex string (e.g., "#FFFFFF")');
342
+ }
343
+ }
344
+ else if (Array.isArray(value)) {
345
+ if (value.length !== 3 || value.some((v) => typeof v !== "number" || v < 0 || v > 255)) {
346
+ throw new Error('mapColor must be a valid RGB array (e.g., [255, 255, 255])');
347
+ }
348
+ }
349
+ else {
350
+ throw new Error('mapColor must be a hex string or an RGB array');
351
+ }
352
+ return new Map().set("minecraft:map_color", value);
353
+ }
354
+ /**
355
+ * 设置方块的材质实例。
356
+ * @param {Object} instances - 材质实例配置。
357
+ * @returns {Map} - 新的组件集合。
358
+ */
359
+ static setMaterialInstances(instances) {
360
+ if (!instances || typeof instances !== "object") {
361
+ throw new Error('instances must be an object');
362
+ }
363
+ if (!instances["*"]) {
364
+ throw new Error('material_instances must include a "*" material instance');
365
+ }
366
+ for (const [key, value] of Object.entries(instances)) {
367
+ if (typeof value === "object") {
368
+ if (!value.texture || typeof value.texture !== "string") {
369
+ throw new Error(`material instance "${key}" must have a texture`);
370
+ }
371
+ if (value.ambient_occlusion !== undefined && typeof value.ambient_occlusion !== "boolean" && typeof value.ambient_occlusion !== "number") {
372
+ throw new Error(`ambient_occlusion in material instance "${key}" must be a boolean or number`);
373
+ }
374
+ if (value.face_dimming !== undefined && typeof value.face_dimming !== "boolean") {
375
+ throw new Error(`face_dimming in material instance "${key}" must be a boolean`);
376
+ }
377
+ if (value.render_method && !["opaque", "double_sided", "blend", "alpha_test", "alpha_test_single_sided"].includes(value.render_method)) {
378
+ throw new Error(`render_method in material instance "${key}" must be one of: opaque, double_sided, blend, alpha_test, alpha_test_single_sided`);
379
+ }
380
+ }
381
+ else if (typeof value !== "string") {
382
+ throw new Error(`material instance "${key}" must be an object or a string`);
383
+ }
384
+ }
385
+ return new Map().set("minecraft:material_instances", instances);
386
+ }
387
+ /**
388
+ * 设置方块的放置过滤条件。
389
+ * @param {Array} conditions - 放置条件列表。
390
+ * @returns {Map} - 新的组件集合。
391
+ */
392
+ static setPlacementFilter(conditions) {
393
+ if (!Array.isArray(conditions) || conditions.length === 0 || conditions.length > 64) {
394
+ throw new Error('conditions must be an array with 1 to 64 elements');
395
+ }
396
+ for (const condition of conditions) {
397
+ if (condition.allowed_faces && Array.isArray(condition.allowed_faces)) {
398
+ const validFaces = ["up", "down", "north", "south", "east", "west", "side", "all"];
399
+ for (const face of condition.allowed_faces) {
400
+ if (!validFaces.includes(face)) {
401
+ throw new Error(`allowed_faces must be one of: ${validFaces.join(", ")}`);
402
+ }
403
+ }
404
+ }
405
+ if (condition.block_filter && Array.isArray(condition.block_filter)) {
406
+ for (const block of condition.block_filter) {
407
+ if (typeof block === "string") {
408
+ continue;
409
+ }
410
+ else if (typeof block === "object" && block !== null) {
411
+ if (block.tags && typeof block.tags !== "string") {
412
+ throw new Error('tags in block_filter must be a string');
413
+ }
414
+ if (block.name && typeof block.name !== "string") {
415
+ throw new Error('name in block_filter must be a string');
416
+ }
417
+ if (block.states && typeof block.states !== "object") {
418
+ throw new Error('states in block_filter must be an object');
419
+ }
420
+ }
421
+ else {
422
+ throw new Error('block_filter must be a string or a BlockDescriptor object');
423
+ }
424
+ }
425
+ }
426
+ if (!condition.allowed_faces && !condition.block_filter) {
427
+ throw new Error('each condition must have at least one of allowed_faces or block_filter');
428
+ }
429
+ }
430
+ return new Map().set("minecraft:placement_filter", { conditions });
431
+ }
432
+ /**
433
+ * 设置方块的红石导电性。
434
+ * @param {Boolean} allowsWireToStepDown - 是否允许红石线向下阶梯连接。
435
+ * @param {Boolean} redstoneConductor - 方块是否可以被红石信号激活。
436
+ * @returns {Map} - 新的组件集合。
437
+ */
438
+ static setRedstoneConductivity(allowsWireToStepDown, redstoneConductor) {
439
+ if (typeof allowsWireToStepDown !== "boolean") {
440
+ throw new Error('allowsWireToStepDown must be a boolean');
441
+ }
442
+ if (typeof redstoneConductor !== "boolean") {
443
+ throw new Error('redstoneConductor must be a boolean');
444
+ }
445
+ return new Map().set("minecraft:redstone_conductivity", {
446
+ allows_wire_to_step_down: allowsWireToStepDown,
447
+ redstone_conductor: redstoneConductor,
448
+ });
449
+ }
450
+ /**
451
+ * 启用或禁用方块的选择框。
452
+ * @param {Boolean} enabled - 是否启用选择框。
453
+ * @returns {Map} - 新的组件集合。
454
+ */
455
+ static setSelectionBoxEnabled(enabled) {
456
+ if (typeof enabled !== "boolean") {
457
+ throw new Error('enabled must be a boolean');
458
+ }
459
+ return new Map().set("minecraft:selection_box", enabled);
460
+ }
461
+ /**
462
+ * 设置自定义的选择框。
463
+ * @param {Array} origin - 选择框的起点坐标 [x, y, z]。
464
+ * @param {Array} size - 选择框的大小 [width, height, depth]。
465
+ * @returns {Map} - 新的组件集合。
466
+ */
467
+ static setSelectionBoxCustom(origin, size) {
468
+ if (!Array.isArray(origin) || origin.length !== 3) {
469
+ throw new Error('origin must be an array of 3 numbers');
470
+ }
471
+ if (!Array.isArray(size) || size.length !== 3) {
472
+ throw new Error('size must be an array of 3 numbers');
473
+ }
474
+ const [x, y, z] = origin;
475
+ const [width, height, depth] = size;
476
+ if (x < -8 || x > 8 || y < 0 || y > 16 || z < -8 || z > 8) {
477
+ throw new Error('origin must be in the range (-8, 0, -8) to (8, 16, 8)');
478
+ }
479
+ if (x + width < -8 || x + width > 8 || y + height < 0 || y + height > 16 || z + depth < -8 || z + depth > 8) {
480
+ throw new Error('origin + size must be in the range (-8, 0, -8) to (8, 16, 8)');
481
+ }
482
+ return new Map().set("minecraft:selection_box", { origin, size });
483
+ }
484
+ /**
485
+ * 将多个组件集合合并为一个。
486
+ * @param {...Map} componentMaps - 多个组件集合。
487
+ * @returns {Map} - 合并后的组件集合。
488
+ */
489
+ static combineComponents(...componentMaps) {
490
+ return new Map(componentMaps.flatMap(map => [...map]));
491
+ }
492
+ /**
493
+ * 获取当前组件的 JSON 表示。
494
+ * @param {Map} components - 组件集合。
495
+ * @returns {Object} - 组件的 JSON 对象。
496
+ */
497
+ static toJSON(components) {
498
+ return Object.fromEntries(components);
499
+ }
500
+ }
@@ -0,0 +1,4 @@
1
+ export class CropBlock extends Block {
2
+ stageNum: number;
3
+ }
4
+ import { Block } from "./block.js";
@@ -0,0 +1,27 @@
1
+ import { Block } from "./block.js";
2
+ import { BlockComponent } from "./blockComponent.js";
3
+ export class CropBlock extends Block {
4
+ /**
5
+ * 作物方块类
6
+ * @param {string} identifier 方块的唯一标识符
7
+ * @param {string} category 方块的分类 "construction", "nature", "equipment", "items", and "none"
8
+ * @param {Array} variantDatas 方块的变体数据,包含每个变体的状态标签和纹理
9
+ * @param {Object} options 可选参数
10
+ * @param {string} options.group 分组,默认为 "construction"
11
+ * @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
12
+ * @param {boolean} options.ambient_occlusion 是否应用环境光遮蔽,默认为 false
13
+ * @param {boolean} options.face_dimming 是否根据面的方向进行亮度调整,默认为 false
14
+ * @param {string} options.render_method 渲染方法,默认为 "alpha_test"
15
+ */
16
+ constructor(identifier, category, variantDatas, options = {}) {
17
+ super(identifier, category, variantDatas, options);
18
+ this.stageNum = variantDatas.length;
19
+ this.addComponent(BlockComponent.combineComponents(BlockComponent.setCollisionBoxEnabled(false), BlockComponent.setGeometry("geometry.crop"), BlockComponent.setLightEmission(0), BlockComponent.setPlacementFilter([{
20
+ "allowed_faces": ["up"],
21
+ "block_filter": ["minecraft:farmland"]
22
+ }])));
23
+ for (let i = 0; i < this.stageNum; i++) {
24
+ this.addVariantComponent(i, BlockComponent.setSelectionBoxCustom([-8, 0, -8], [16, (i + 1) * this.stageNum / 16, 16]));
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,12 @@
1
+ export class GeometryBlock extends BasicBlock {
2
+ /**
3
+ * 带模型方块类
4
+ * @param {string} identifier 方块标识符 由命名空间和方块名组成 例如 "my_mod:stone"
5
+ * @param {string} category 方块的分类 "construction", "nature", "equipment", "items", and "none"
6
+ * @param {string} geometry 模型标识符
7
+ * @param {Object} material_instances 材质实例对象
8
+ * @param {Object} options 可选参数
9
+ */
10
+ constructor(identifier: string, category: string, geometry: string, material_instances: Object, options?: Object);
11
+ }
12
+ import { BasicBlock } from "./basicBlock.js";
@@ -0,0 +1,16 @@
1
+ import { BasicBlock } from "./basicBlock.js";
2
+ import { BlockComponent } from "./blockComponent.js";
3
+ export class GeometryBlock extends BasicBlock {
4
+ /**
5
+ * 带模型方块类
6
+ * @param {string} identifier 方块标识符 由命名空间和方块名组成 例如 "my_mod:stone"
7
+ * @param {string} category 方块的分类 "construction", "nature", "equipment", "items", and "none"
8
+ * @param {string} geometry 模型标识符
9
+ * @param {Object} material_instances 材质实例对象
10
+ * @param {Object} options 可选参数
11
+ */
12
+ constructor(identifier, category, geometry, material_instances, options = {}) {
13
+ super(identifier, category, [material_instances["*"]["texture"]], options);
14
+ this.addComponent(BlockComponent.combineComponents(BlockComponent.setGeometry(geometry), BlockComponent.setMaterialInstances(material_instances)));
15
+ }
16
+ }
@@ -0,0 +1,9 @@
1
+ export class OreBlock {
2
+ constructor(identifier: any, category: any, textures_arr: any, options?: {});
3
+ block: BasicBlock;
4
+ feature: OreFeature;
5
+ feature_rules: FeatureRule;
6
+ }
7
+ import { BasicBlock } from "./basicBlock.js";
8
+ import { OreFeature } from "../feature/oreFeature.js";
9
+ import { FeatureRule } from "../feature-rule/featureRule.js";
@@ -0,0 +1,25 @@
1
+ import { OreFeature } from "../feature/oreFeature.js";
2
+ import { BiomeFilter } from "../feature-rule/condition/biomeFilter.js";
3
+ import { CoordinateDistribution } from "../feature-rule/distribution/coordinateDistribution.js";
4
+ import { FeatureRule } from "../feature-rule/featureRule.js";
5
+ import { BasicBlock } from "./basicBlock.js";
6
+ export class OreBlock {
7
+ constructor(identifier, category, textures_arr, options = {}) {
8
+ this.block = new BasicBlock(identifier, category, textures_arr, options);
9
+ this.feature = new OreFeature(`${identifier}_ore_feature`, 6, [
10
+ {
11
+ "places_block": identifier,
12
+ "may_replace": ["minecraft:stone"]
13
+ },
14
+ ]);
15
+ this.feature_rules = new FeatureRule(`${identifier}_orefeatre_rule`, `${identifier}_ore_feature`);
16
+ this.feature_rules.condition.setPlacementPass("underground_pass").setBiomeFilter(new BiomeFilter().addLogicGroup("any_of", [
17
+ { test: "has_biome_tag", operator: "==", value: "overworld" },
18
+ { test: "has_biome_tag", operator: "==", value: "overworld_generation" }
19
+ ]));
20
+ this.feature_rules.distribution.setIterations(10)
21
+ .setAxisDistribution("x", new CoordinateDistribution("uniform", [0, 16]))
22
+ .setAxisDistribution("y", new CoordinateDistribution("uniform", [0, 64]))
23
+ .setAxisDistribution("z", new CoordinateDistribution("uniform", [0, 16]));
24
+ }
25
+ }
@@ -0,0 +1,27 @@
1
+ export namespace RotationTypes {
2
+ let CARDINAL: string;
3
+ let FACING: string;
4
+ let BLOCK_FACE: string;
5
+ let LOG: string;
6
+ }
7
+ export class RotatableBlock extends BasicBlock {
8
+ /**
9
+ * 可旋转方块类
10
+ * @param {string} identifier 方块唯一标识符
11
+ * @param {string} category 菜单栏分类
12
+ * @param {Array} textures_arr 纹理数组 [上,下,东,西,南,北]
13
+ * @param {Object} options 可选参数
14
+ * @param {string} options.group 分组,默认为 "construction"
15
+ * @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
16
+ * @param {string} options.rotationType 旋转类型,默认为 "cardinal"
17
+ * @param {number} options.yRotationOffset 初始旋转偏移量,默认为 180
18
+ */
19
+ constructor(identifier: string, category: string, textures_arr: any[], options?: {
20
+ group: string;
21
+ hide_in_command: boolean;
22
+ rotationType: string;
23
+ yRotationOffset: number;
24
+ });
25
+ #private;
26
+ }
27
+ import { BasicBlock } from "./basicBlock.js";