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,107 @@
1
+ import { BasicBlock } from "./basicBlock.js";
2
+ import { BlockComponent } from "./blockComponent.js";
3
+ export const RotationTypes = {
4
+ CARDINAL: "cardinal", // 北、南、东、西
5
+ FACING: "facing", // 上、下、北、南、东、西
6
+ BLOCK_FACE: "block_face", // 上、下、北、南、东、西(与 FACING 类似,但用途不同)
7
+ LOG: "log" // 原木旋转(X、Y、Z 轴对齐)
8
+ };
9
+ export class RotatableBlock extends BasicBlock {
10
+ /**
11
+ * 可旋转方块类
12
+ * @param {string} identifier 方块唯一标识符
13
+ * @param {string} category 菜单栏分类
14
+ * @param {Array} textures_arr 纹理数组 [上,下,东,西,南,北]
15
+ * @param {Object} options 可选参数
16
+ * @param {string} options.group 分组,默认为 "construction"
17
+ * @param {boolean} options.hide_in_command 是否在命令中隐藏,默认为 false
18
+ * @param {string} options.rotationType 旋转类型,默认为 "cardinal"
19
+ * @param {number} options.yRotationOffset 初始旋转偏移量,默认为 180
20
+ */
21
+ constructor(identifier, category, textures_arr, options = {}) {
22
+ // 调用父类构造函数
23
+ super(identifier, category, textures_arr, options);
24
+ const { rotationType = RotationTypes.CARDINAL, yRotationOffset = 180 } = options;
25
+ // 根据旋转类型注册特性和添加变体
26
+ this.#setupRotation(rotationType, yRotationOffset);
27
+ }
28
+ /**
29
+ * 根据旋转类型设置特性和变体
30
+ * @param {string} rotationType 旋转类型
31
+ * @param {number} yRotationOffset 初始旋转偏移量
32
+ */
33
+ #setupRotation(rotationType, yRotationOffset) {
34
+ switch (rotationType) {
35
+ case RotationTypes.CARDINAL:
36
+ // 北、南、东、西
37
+ this.registerTrait("minecraft:placement_direction", {
38
+ enabled_states: ["minecraft:cardinal_direction"],
39
+ y_rotation_offset: yRotationOffset
40
+ });
41
+ this.#addCardinalDirectionPermutations();
42
+ break;
43
+ case RotationTypes.FACING:
44
+ // 上、下、北、南、东、西
45
+ this.registerTrait("minecraft:placement_direction", {
46
+ enabled_states: ["minecraft:facing_direction"]
47
+ });
48
+ this.#addFacingDirectionPermutations();
49
+ break;
50
+ case RotationTypes.BLOCK_FACE:
51
+ // 上、下、北、南、东、西(与 FACING 类似,但用途不同)
52
+ this.registerTrait("minecraft:placement_position", {
53
+ enabled_states: ["minecraft:block_face"]
54
+ });
55
+ this.#addBlockFacePermutations();
56
+ break;
57
+ case RotationTypes.LOG:
58
+ // 原木旋转(X、Y、Z 轴对齐)
59
+ this.registerTrait("minecraft:placement_position", {
60
+ enabled_states: ["minecraft:block_face"]
61
+ });
62
+ this.#addLogRotationPermutations();
63
+ break;
64
+ default:
65
+ throw new Error(`Unknown rotation type: ${rotationType}`);
66
+ }
67
+ }
68
+ /**
69
+ * 添加 Cardinal Direction 旋转变体
70
+ */
71
+ #addCardinalDirectionPermutations() {
72
+ this.addPermutation("q.block_state('minecraft:cardinal_direction') == 'north'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0]))
73
+ .addPermutation("q.block_state('minecraft:cardinal_direction') == 'south'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 90, 0]))
74
+ .addPermutation("q.block_state('minecraft:cardinal_direction') == 'east'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 180, 0]))
75
+ .addPermutation("q.block_state('minecraft:cardinal_direction') == 'west'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, -90, 0]));
76
+ }
77
+ /**
78
+ * 添加 Facing Direction 旋转变体
79
+ */
80
+ #addFacingDirectionPermutations() {
81
+ this.addPermutation("q.block_state('minecraft:facing_direction') == 'down'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [-90, 0, 0]))
82
+ .addPermutation("q.block_state('minecraft:facing_direction') == 'up'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [90, 0, 0]))
83
+ .addPermutation("q.block_state('minecraft:facing_direction') == 'north'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0]))
84
+ .addPermutation("q.block_state('minecraft:facing_direction') == 'west'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 90, 0]))
85
+ .addPermutation("q.block_state('minecraft:facing_direction') == 'south'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 180, 0]))
86
+ .addPermutation("q.block_state('minecraft:facing_direction') == 'east'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, -90, 0]));
87
+ }
88
+ /**
89
+ * 添加 Block Face 旋转变体
90
+ */
91
+ #addBlockFacePermutations() {
92
+ this.addPermutation("q.block_state('minecraft:block_face') == 'down'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [-90, 0, 0], [0, 0, 0]))
93
+ .addPermutation("q.block_state('minecraft:block_face') == 'up'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [90, 0, 0], [0, 0, 0]))
94
+ .addPermutation("q.block_state('minecraft:block_face') == 'north'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0]))
95
+ .addPermutation("q.block_state('minecraft:block_face') == 'south'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 180, 0], [0, 90, 0]))
96
+ .addPermutation("q.block_state('minecraft:block_face') == 'east'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 90, 0], [0, 180, 0]))
97
+ .addPermutation("q.block_state('minecraft:block_face') == 'west'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, -90, 0], [0, -90, 0]));
98
+ }
99
+ /**
100
+ * 添加 Log Rotation 旋转变体
101
+ */
102
+ #addLogRotationPermutations() {
103
+ this.addPermutation("q.block_state('minecraft:block_face') == 'west' || q.block_state('minecraft:block_face') == 'east'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 90], [0, 0, 0]))
104
+ .addPermutation("q.block_state('minecraft:block_face') == 'down' || q.block_state('minecraft:block_face') == 'up'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0]))
105
+ .addPermutation("q.block_state('minecraft:block_face') == 'north' || q.block_state('minecraft:block_face') == 'south'", BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [90, 0, 0], [0, 0, 0]));
106
+ }
107
+ }
@@ -0,0 +1,17 @@
1
+ export class TileBlock {
2
+ /**
3
+ * 带实体的方块类
4
+ * @param {*} identifier
5
+ * @param {*} category
6
+ * @param {*} textures_arr
7
+ * @param {*} options
8
+ */
9
+ constructor(identifier: any, category: any, textures_arr: any, options?: any);
10
+ block: BasicBlock;
11
+ entity: Entity;
12
+ setGeometry(geometry: any): void;
13
+ addAnimation(name: any, animation: any): void;
14
+ setScript(key: any, value: any): void;
15
+ }
16
+ import { BasicBlock } from "./basicBlock.js";
17
+ import { Entity } from "../entity/entity.js";
@@ -0,0 +1,125 @@
1
+ import { Entity } from "../entity/entity.js";
2
+ import { BasicBlock } from "./basicBlock.js";
3
+ import { BlockComponent } from "./blockComponent.js";
4
+ const TileBehData = {
5
+ component_groups: {
6
+ "item_despawn": {
7
+ "minecraft:despawn": {},
8
+ "minecraft:instant_despawn": {
9
+ "remove_child_entities": false
10
+ },
11
+ "minecraft:transformation": {
12
+ "drop_inventory": true,
13
+ "into": "minecraft:air"
14
+ }
15
+ }
16
+ },
17
+ components: {
18
+ "minecraft:inventory": {
19
+ "inventory_size": 27,
20
+ "can_be_siphoned_from": true,
21
+ "container_type": "minecart_chest"
22
+ },
23
+ "minecraft:nameable": {
24
+ "allow_name_tag_renaming": false
25
+ },
26
+ // Knockback resistance is needed to make it not be Knocked off by an entity.
27
+ "minecraft:knockback_resistance": {
28
+ "value": 1
29
+ },
30
+ // Tells if the entity can be pushed or not.
31
+ "minecraft:pushable": {
32
+ "is_pushable": false,
33
+ "is_pushable_by_piston": true
34
+ },
35
+ // Sets the distance through which the entity can push through.
36
+ "minecraft:push_through": {
37
+ "value": 1
38
+ },
39
+ "minecraft:custom_hit_test": {
40
+ "hitboxes": [
41
+ {
42
+ "width": 0.81,
43
+ "height": 0.92,
44
+ "pivot": [
45
+ 0,
46
+ 0.5,
47
+ 0
48
+ ]
49
+ }
50
+ ]
51
+ },
52
+ //可以被活塞推动,但是不会被实体推动
53
+ "minecraft:pushable": {
54
+ "is_pushable": false,
55
+ "is_pushable_by_piston": true
56
+ },
57
+ // Makes it invincible.
58
+ "minecraft:damage_sensor": {
59
+ "triggers": [
60
+ {
61
+ "deals_damage": false,
62
+ "cause": "all"
63
+ }
64
+ ]
65
+ },
66
+ "minecraft:persistent": {}
67
+ },
68
+ events: {
69
+ "despawn_event": {
70
+ "add": {
71
+ "component_groups": [
72
+ "item_despawn"
73
+ ]
74
+ }
75
+ }
76
+ }
77
+ };
78
+ export class TileBlock {
79
+ /**
80
+ * 带实体的方块类
81
+ * @param {*} identifier
82
+ * @param {*} category
83
+ * @param {*} textures_arr
84
+ * @param {*} options
85
+ */
86
+ constructor(identifier, category, textures_arr, options = {}) {
87
+ this.block = new BasicBlock(identifier, category, textures_arr, options);
88
+ this.entity = new Entity(`${identifier}_entity`, textures_arr[0], TileBehData, {});
89
+ // 注册方块状态 0:方块 1:实体
90
+ this.block.registerState("sapdon:block_or_entity", [0, 1]);
91
+ this.block.addComponent(BlockComponent.setCustomComponents(["sapdon:block_with_entity"]));
92
+ this.block.addPermutation("q.block_state('sapdon:block_or_entity') == 1", BlockComponent.combineComponents(BlockComponent.setTick([0, 0], true), //提供tick
93
+ BlockComponent.setGeometry("geometry.cube"), BlockComponent.setMaterialInstances({ "*": {
94
+ "texture": "none",
95
+ "render_method": "alpha_test"
96
+ } })));
97
+ //设置生物
98
+ this.entity.entity.addComponent(new Map().set("minecraft:block_sensor", {
99
+ "sensor_radius": 1,
100
+ "on_break": [
101
+ {
102
+ "block_list": [
103
+ identifier
104
+ ],
105
+ "on_block_broken": "despawn_event"
106
+ }
107
+ ]
108
+ }));
109
+ this.entity.client_entity.addMaterial("default", "entity_alphatest")
110
+ .addGeometry("default", "geometry.cube")
111
+ .addRenderController("controller.render.cow");
112
+ }
113
+ setGeometry(geometry) {
114
+ //设置方块模型
115
+ this.block.addComponent(BlockComponent.setGeometry(geometry));
116
+ //设置实体模型
117
+ this.entity.client_entity.addGeometry("default", geometry);
118
+ }
119
+ addAnimation(name, animation) {
120
+ this.entity.client_entity.addAnimation(name, animation);
121
+ }
122
+ setScript(key, value) {
123
+ this.entity.client_entity.setScript(key, value);
124
+ }
125
+ }
@@ -0,0 +1,111 @@
1
+ export class BasicEntity {
2
+ /**
3
+ * 构造函数
4
+ * @param {string} identifier - 实体的唯一标识符
5
+ * @param {Object} options - 配置选项
6
+ * @param {boolean} [options.is_spawnable=true] - 是否可生成
7
+ * @param {boolean} [options.is_summonable=true] - 是否可召唤
8
+ * @param {string} [options.runtime_identifier] - 复刻标识符
9
+ * @param {Object} data - 继承的数据
10
+ * @param {Object} [data.components={}] - 继承的组件
11
+ * @param {Object} [data.component_groups={}] - 继承的组件组
12
+ * @param {Object} [data.events={}] - 继承的事件
13
+ */
14
+ constructor(identifier: string, options?: {
15
+ is_spawnable?: boolean | undefined;
16
+ is_summonable?: boolean | undefined;
17
+ runtime_identifier?: string | undefined;
18
+ }, data?: {
19
+ components?: Object | undefined;
20
+ component_groups?: Object | undefined;
21
+ events?: Object | undefined;
22
+ });
23
+ identifier: string;
24
+ is_spawnable: boolean;
25
+ is_summonable: boolean;
26
+ runtime_identifier: string | undefined;
27
+ properties: Map<string, any>;
28
+ components: Map<string, any>;
29
+ component_groups: Map<string, any>;
30
+ events: Map<string, any>;
31
+ /**
32
+ * 添加属性到实体
33
+ * @param {string} name 属性名称
34
+ * @param {Object} value 属性值
35
+ * @returns
36
+ */
37
+ addProperty(name: string, value: Object): this;
38
+ /**
39
+ * 移除属性
40
+ * @param {string} name 属性名称
41
+ * @returns
42
+ */
43
+ removeProperty(name: string): this;
44
+ /**
45
+ * 移除所有属性
46
+ * @returns
47
+ */
48
+ clearProperties(): this;
49
+ /**
50
+ * 添加事件到实体
51
+ * @param {string} name - 事件名称
52
+ * @param {Map} eventMap - 事件的键值对 Map
53
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
54
+ */
55
+ addEvent(name: string, eventMap: Map<any, any>): BasicEntity;
56
+ /**
57
+ * 删除事件
58
+ * @param {string} name - 事件名称
59
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
60
+ */
61
+ removeEvent(name: string): BasicEntity;
62
+ /**
63
+ * 清除所有事件
64
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
65
+ */
66
+ clearEvents(): BasicEntity;
67
+ /**
68
+ * 添加组件组到实体
69
+ * @param {string} name - 组件组名称
70
+ * @param {Map} componentMap - 组件组的键值对 Map
71
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
72
+ */
73
+ addComponentGroup(name: string, componentMap: Map<any, any>): BasicEntity;
74
+ /**
75
+ * 删除组件组
76
+ * @param {string} name - 组件组名称
77
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
78
+ */
79
+ removeComponentGroup(name: string): BasicEntity;
80
+ /**
81
+ * 清除所有组件组
82
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
83
+ */
84
+ clearComponentGroups(): BasicEntity;
85
+ /**
86
+ * 添加组件到实体
87
+ * @param {Map} componentMap - 组件的键值对 Map
88
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
89
+ */
90
+ addComponent(componentMap: Map<any, any>): BasicEntity;
91
+ /**
92
+ * 删除组件
93
+ * @param {string} key - 组件名称
94
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
95
+ */
96
+ removeComponent(key: string): BasicEntity;
97
+ /**
98
+ * 清除所有组件
99
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
100
+ */
101
+ clearComponents(): BasicEntity;
102
+ /**
103
+ * 清除所有数据
104
+ */
105
+ clearAll(): this;
106
+ /**
107
+ * 将实体转换为 JSON 格式
108
+ * @returns {Object} - 返回 JSON 格式的实体数据
109
+ */
110
+ toJson(): Object;
111
+ }
@@ -0,0 +1,170 @@
1
+ import { AddonEntity, AddonEntityDefinition, AddonEntityDescription } from "../addon/entity/entity.js";
2
+ export class BasicEntity {
3
+ /**
4
+ * 构造函数
5
+ * @param {string} identifier - 实体的唯一标识符
6
+ * @param {Object} options - 配置选项
7
+ * @param {boolean} [options.is_spawnable=true] - 是否可生成
8
+ * @param {boolean} [options.is_summonable=true] - 是否可召唤
9
+ * @param {string} [options.runtime_identifier] - 复刻标识符
10
+ * @param {Object} data - 继承的数据
11
+ * @param {Object} [data.components={}] - 继承的组件
12
+ * @param {Object} [data.component_groups={}] - 继承的组件组
13
+ * @param {Object} [data.events={}] - 继承的事件
14
+ */
15
+ constructor(identifier, options = {}, data = {}) {
16
+ // 参数验证
17
+ if (typeof identifier !== 'string' || !identifier) {
18
+ throw new Error('identifier must be a non-empty string.');
19
+ }
20
+ if (options.runtime_identifier && typeof options.runtime_identifier !== 'string') {
21
+ throw new Error('runtime_identifier must be a string.');
22
+ }
23
+ this.identifier = identifier;
24
+ this.is_spawnable = options.is_spawnable ?? true;
25
+ this.is_summonable = options.is_summonable ?? true;
26
+ this.runtime_identifier = options.runtime_identifier;
27
+ // 初始化 components、component_groups 和 events,确保 data 中的值为对象
28
+ this.properties = new Map(Object.entries(data.description ? data.description.properties || {} : {}));
29
+ this.components = new Map(Object.entries(data.components || {}));
30
+ this.component_groups = new Map(Object.entries(data.component_groups || {}));
31
+ this.events = new Map(Object.entries(data.events || {}));
32
+ }
33
+ /**
34
+ * 添加属性到实体
35
+ * @param {string} name 属性名称
36
+ * @param {Object} value 属性值
37
+ * @returns
38
+ */
39
+ addProperty(name, value) {
40
+ this.properties.set(name, value);
41
+ return this;
42
+ }
43
+ /**
44
+ * 移除属性
45
+ * @param {string} name 属性名称
46
+ * @returns
47
+ */
48
+ removeProperty(name) {
49
+ this.properties.delete(name);
50
+ return this;
51
+ }
52
+ /**
53
+ * 移除所有属性
54
+ * @returns
55
+ */
56
+ clearProperties() {
57
+ this.properties.clear();
58
+ return this;
59
+ }
60
+ /**
61
+ * 添加事件到实体
62
+ * @param {string} name - 事件名称
63
+ * @param {Map} eventMap - 事件的键值对 Map
64
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
65
+ */
66
+ addEvent(name, eventMap) {
67
+ if (!(eventMap instanceof Map)) {
68
+ throw new Error("eventMap must be an instance of Map.");
69
+ }
70
+ this.events.set(name, eventMap);
71
+ return this;
72
+ }
73
+ /**
74
+ * 删除事件
75
+ * @param {string} name - 事件名称
76
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
77
+ */
78
+ removeEvent(name) {
79
+ this.events.delete(name);
80
+ return this;
81
+ }
82
+ /**
83
+ * 清除所有事件
84
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
85
+ */
86
+ clearEvents() {
87
+ this.events.clear();
88
+ return this;
89
+ }
90
+ /**
91
+ * 添加组件组到实体
92
+ * @param {string} name - 组件组名称
93
+ * @param {Map} componentMap - 组件组的键值对 Map
94
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
95
+ */
96
+ addComponentGroup(name, componentMap) {
97
+ if (!(componentMap instanceof Map)) {
98
+ throw new Error("componentMap must be an instance of Map.");
99
+ }
100
+ this.component_groups.set(name, componentMap);
101
+ return this;
102
+ }
103
+ /**
104
+ * 删除组件组
105
+ * @param {string} name - 组件组名称
106
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
107
+ */
108
+ removeComponentGroup(name) {
109
+ this.component_groups.delete(name);
110
+ return this;
111
+ }
112
+ /**
113
+ * 清除所有组件组
114
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
115
+ */
116
+ clearComponentGroups() {
117
+ this.component_groups.clear();
118
+ return this;
119
+ }
120
+ /**
121
+ * 添加组件到实体
122
+ * @param {Map} componentMap - 组件的键值对 Map
123
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
124
+ */
125
+ addComponent(componentMap) {
126
+ if (!(componentMap instanceof Map)) {
127
+ throw new Error("componentMap must be an instance of Map.");
128
+ }
129
+ for (const [key, value] of componentMap) {
130
+ this.components.set(key, value);
131
+ }
132
+ return this; // 支持链式调用
133
+ }
134
+ /**
135
+ * 删除组件
136
+ * @param {string} key - 组件名称
137
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
138
+ */
139
+ removeComponent(key) {
140
+ this.components.delete(key);
141
+ return this;
142
+ }
143
+ /**
144
+ * 清除所有组件
145
+ * @returns {BasicEntity} - 返回当前实例以支持链式调用
146
+ */
147
+ clearComponents() {
148
+ this.components.clear();
149
+ return this;
150
+ }
151
+ /**
152
+ * 清除所有数据
153
+ */
154
+ clearAll() {
155
+ this.components.clear();
156
+ this.component_groups.clear();
157
+ this.events.clear();
158
+ return this;
159
+ }
160
+ /**
161
+ * 将实体转换为 JSON 格式
162
+ * @returns {Object} - 返回 JSON 格式的实体数据
163
+ */
164
+ toJson() {
165
+ return new AddonEntity("1.16.0", new AddonEntityDefinition(new AddonEntityDescription(this.identifier, this.is_spawnable, this.is_summonable, Object.fromEntries(this.properties), this.runtime_identifier), Object.fromEntries(this.components), // 将 Map 转换为普通对象
166
+ Object.fromEntries(this.component_groups), // 将 Map 转换为普通对象
167
+ Object.fromEntries(this.events) // 将 Map 转换为普通对象
168
+ )).toJson();
169
+ }
170
+ }
@@ -0,0 +1,12 @@
1
+ export class FollowMobBehavior {
2
+ constructor(priority: any);
3
+ priority: any;
4
+ searchRange: number;
5
+ speedMultiplier: number;
6
+ stopDistance: number;
7
+ setPriority(priority: any): this;
8
+ setSearchRange(searchRange: any): this;
9
+ setSpeedMultiplier(speedMultiplier: any): this;
10
+ setStopDistance(stopDistance: any): this;
11
+ toJSON(): Map<any, any>;
12
+ }
@@ -0,0 +1,35 @@
1
+ export class FollowMobBehavior {
2
+ constructor(priority) {
3
+ this.priority = priority;
4
+ this.searchRange = 0;
5
+ this.speedMultiplier = 1.0;
6
+ this.stopDistance = 2.0;
7
+ }
8
+ setPriority(priority) {
9
+ this.priority = priority;
10
+ return this; // 支持链式调用
11
+ }
12
+ setSearchRange(searchRange) {
13
+ this.searchRange = searchRange;
14
+ return this; // 支持链式调用
15
+ }
16
+ setSpeedMultiplier(speedMultiplier) {
17
+ this.speedMultiplier = speedMultiplier;
18
+ return this; // 支持链式调用
19
+ }
20
+ setStopDistance(stopDistance) {
21
+ this.stopDistance = stopDistance;
22
+ return this; // 支持链式调用
23
+ }
24
+ toJSON() {
25
+ if (this.priority === null) {
26
+ throw new Error("Priority must be set for FollowMobBehavior.");
27
+ }
28
+ return new Map().set("minecraft:behavior.follow_mob", {
29
+ priority: this.priority,
30
+ search_range: this.searchRange,
31
+ speed_multiplier: this.speedMultiplier,
32
+ stop_distance: this.stopDistance
33
+ });
34
+ }
35
+ }
@@ -0,0 +1,7 @@
1
+ export class FollowParentBehavior {
2
+ constructor(priority: any);
3
+ priority: any;
4
+ speed_multiplier: number;
5
+ setSpeedMultiplier(speed_multiplier: any): void;
6
+ toJson(): Map<any, any>;
7
+ }
@@ -0,0 +1,15 @@
1
+ export class FollowParentBehavior {
2
+ constructor(priority) {
3
+ this.priority = priority;
4
+ this.speed_multiplier = 1.10;
5
+ }
6
+ setSpeedMultiplier(speed_multiplier) {
7
+ this.speed_multiplier = speed_multiplier;
8
+ }
9
+ toJson() {
10
+ return new Map().set("minecraft:behavior.follow_parent", {
11
+ "priority": this.priority,
12
+ "speed_multiplier": this.speed_multiplier
13
+ });
14
+ }
15
+ }
@@ -0,0 +1,31 @@
1
+ export class RandomStrollBehavior {
2
+ /**
3
+ * 随机漫步行为
4
+ * @param {number} priority 优先级
5
+ * @param {number} interval 间隔
6
+ * @param {number} speed_multiplier 速度倍数
7
+ */
8
+ constructor(priority: number, interval: number, speed_multiplier: number);
9
+ priority: number;
10
+ interval: number;
11
+ speed_multiplier: number;
12
+ xz_dist: number;
13
+ y_dist: number;
14
+ /**
15
+ * 设置水平距离
16
+ * @param {number} xz_dist 水平距离
17
+ * @returns {EntityBehaviorRandomStroll} 返回当前实例以支持链式调用
18
+ */
19
+ setXZDist(xz_dist: number): EntityBehaviorRandomStroll;
20
+ /**
21
+ * 设置垂直距离
22
+ * @param {number} y_dist 垂直距离
23
+ * @returns {EntityBehaviorRandomStroll} 返回当前实例以支持链式调用
24
+ */
25
+ setYDist(y_dist: number): EntityBehaviorRandomStroll;
26
+ /**
27
+ * 将组件转换为 JSON 对象
28
+ * @returns {Object} minecraft:behavior.random_stroll 组件的 JSON 对象
29
+ */
30
+ toJSON(): Object;
31
+ }