sapdon 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +3 -2
  2. package/dist/cli/build.d.ts +7 -0
  3. package/dist/cli/build.js +236 -0
  4. package/dist/cli/dev-server/client.d.ts +2 -0
  5. package/dist/cli/dev-server/client.js +21 -0
  6. package/dist/cli/dev-server/config.d.ts +3 -0
  7. package/dist/cli/dev-server/config.js +3 -0
  8. package/dist/cli/dev-server/handles.d.ts +4 -0
  9. package/dist/cli/dev-server/handles.js +5 -0
  10. package/dist/cli/dev-server/hmr.d.ts +1 -0
  11. package/dist/cli/dev-server/hmr.js +13 -0
  12. package/dist/cli/dev-server/index.d.ts +4 -0
  13. package/dist/cli/dev-server/index.js +17 -0
  14. package/dist/cli/dev-server/server.d.ts +14 -0
  15. package/dist/cli/dev-server/server.js +59 -0
  16. package/dist/cli/dev-server/syncFiles.d.ts +3 -0
  17. package/dist/cli/dev-server/syncFiles.js +45 -0
  18. package/dist/cli/index.d.ts +20 -0
  19. package/dist/cli/index.js +90 -0
  20. package/dist/cli/init.d.ts +9 -0
  21. package/dist/cli/init.js +80 -0
  22. package/dist/cli/load.d.ts +3 -0
  23. package/dist/cli/load.js +94 -0
  24. package/dist/cli/start.d.ts +2 -0
  25. package/dist/cli/start.js +1398 -0
  26. package/dist/cli/tools/textureSet.d.ts +13 -0
  27. package/dist/cli/tools/textureSet.js +103 -0
  28. package/dist/cli/utils.d.ts +13 -0
  29. package/dist/cli/utils.js +89 -0
  30. package/dist/core/addon/biome.d.ts +22 -0
  31. package/dist/core/addon/biome.js +27 -0
  32. package/dist/core/addon/block/block.d.ts +41 -0
  33. package/dist/core/addon/block/block.js +46 -0
  34. package/dist/core/addon/controllers/animationController.d.ts +43 -0
  35. package/dist/core/addon/controllers/animationController.js +73 -0
  36. package/dist/core/addon/controllers/render_controllers.js +162 -0
  37. package/dist/core/addon/entity/clientEntity.d.ts +107 -0
  38. package/dist/core/addon/entity/clientEntity.js +149 -0
  39. package/dist/core/addon/entity/entity.d.ts +42 -0
  40. package/dist/core/addon/entity/entity.js +50 -0
  41. package/dist/core/addon/feature/oreFeature.d.ts +19 -0
  42. package/dist/core/addon/feature/oreFeature.js +24 -0
  43. package/dist/core/addon/featureRule.d.ts +20 -0
  44. package/dist/core/addon/featureRule.js +25 -0
  45. package/dist/core/addon/item/attachable.d.ts +94 -0
  46. package/dist/core/addon/item/attachable.js +134 -0
  47. package/dist/core/addon/item/item.d.ts +19 -0
  48. package/dist/core/addon/item/item.js +26 -0
  49. package/dist/core/addon/manifest.d.ts +49 -0
  50. package/dist/core/addon/manifest.js +65 -0
  51. package/dist/core/addon/menuCategory.d.ts +6 -0
  52. package/dist/core/addon/menuCategory.js +7 -0
  53. package/dist/core/addon/recipe/baseRecipe.d.ts +12 -0
  54. package/dist/core/addon/recipe/baseRecipe.js +23 -0
  55. package/dist/core/addon/recipe/data.d.ts +66 -0
  56. package/dist/core/addon/recipe/data.js +74 -0
  57. package/dist/core/addon/recipe/furnace.d.ts +17 -0
  58. package/dist/core/addon/recipe/furnace.js +43 -0
  59. package/dist/core/addon/recipe/shaped.d.ts +26 -0
  60. package/dist/core/addon/recipe/shaped.js +53 -0
  61. package/dist/core/addon/recipe/shapeless.d.ts +18 -0
  62. package/dist/core/addon/recipe/shapeless.js +36 -0
  63. package/dist/core/biome/biome.d.ts +14 -0
  64. package/dist/core/biome/biome.js +23 -0
  65. package/dist/core/biome/biomeComponent.d.ts +46 -0
  66. package/dist/core/biome/biomeComponent.js +77 -0
  67. package/dist/core/block/basicBlock.d.ts +48 -0
  68. package/dist/core/block/basicBlock.js +105 -0
  69. package/dist/core/block/block.d.ts +32 -0
  70. package/dist/core/block/block.js +92 -0
  71. package/dist/core/block/blockComponent.d.ts +187 -0
  72. package/dist/core/block/blockComponent.js +500 -0
  73. package/dist/core/block/cropBlock.d.ts +4 -0
  74. package/dist/core/block/cropBlock.js +27 -0
  75. package/dist/core/block/geometryBlock.d.ts +12 -0
  76. package/dist/core/block/geometryBlock.js +16 -0
  77. package/dist/core/block/oreBlock.d.ts +9 -0
  78. package/dist/core/block/oreBlock.js +25 -0
  79. package/dist/core/block/rotatableBlock.d.ts +27 -0
  80. package/dist/core/block/rotatableBlock.js +107 -0
  81. package/dist/core/block/tileBlock.d.ts +17 -0
  82. package/dist/core/block/tileBlock.js +125 -0
  83. package/dist/core/entity/basicEntity.d.ts +111 -0
  84. package/dist/core/entity/basicEntity.js +170 -0
  85. package/dist/core/entity/behavior/followMob.d.ts +12 -0
  86. package/dist/core/entity/behavior/followMob.js +35 -0
  87. package/dist/core/entity/behavior/followParent.d.ts +7 -0
  88. package/dist/core/entity/behavior/followParent.js +15 -0
  89. package/dist/core/entity/behavior/randomStroll.d.ts +31 -0
  90. package/dist/core/entity/behavior/randomStroll.js +63 -0
  91. package/dist/core/entity/behavior/tempt.d.ts +73 -0
  92. package/dist/core/entity/behavior/tempt.js +134 -0
  93. package/dist/core/entity/bundles/BasicMoveBundle.js +8 -0
  94. package/dist/core/entity/bundles/basicBundle.d.ts +13 -0
  95. package/dist/core/entity/bundles/basicBundle.js +38 -0
  96. package/dist/core/entity/clientEntity.d.ts +20 -0
  97. package/dist/core/entity/clientEntity.js +37 -0
  98. package/dist/core/entity/componets/entityComponet.d.ts +202 -0
  99. package/dist/core/entity/componets/entityComponet.js +354 -0
  100. package/dist/core/entity/data/nativeEntityData.d.ts +9 -0
  101. package/dist/core/entity/data/nativeEntityData.js +38 -0
  102. package/dist/core/entity/dummyEntity.js +14 -0
  103. package/dist/core/entity/entity.d.ts +15 -0
  104. package/dist/core/entity/entity.js +11 -0
  105. package/dist/core/entity/nativeEntity.d.ts +8 -0
  106. package/dist/core/entity/nativeEntity.js +28 -0
  107. package/dist/core/entity/navigation/walk.d.ts +23 -0
  108. package/dist/core/entity/navigation/walk.js +56 -0
  109. package/dist/core/entity/projectile.d.ts +3 -0
  110. package/dist/core/entity/projectile.js +7 -0
  111. package/dist/core/factory/biomeFactory.d.ts +4 -0
  112. package/dist/core/factory/biomeFactory.js +13 -0
  113. package/dist/core/factory/blockFactory.d.ts +34 -0
  114. package/dist/core/factory/blockFactory.js +143 -0
  115. package/dist/core/factory/entityFactory.d.ts +17 -0
  116. package/dist/core/factory/entityFactory.js +75 -0
  117. package/dist/core/factory/featureFactory.d.ts +6 -0
  118. package/dist/core/factory/featureFactory.js +23 -0
  119. package/dist/core/factory/itemExtra.d.ts +8 -0
  120. package/dist/core/factory/itemExtra.js +9 -0
  121. package/dist/core/factory/itemFactory.d.ts +27 -0
  122. package/dist/core/factory/itemFactory.js +112 -0
  123. package/dist/core/factory/recipeFactory.d.ts +18 -0
  124. package/dist/core/factory/recipeFactory.js +39 -0
  125. package/dist/core/factory/uiFactory.d.ts +12 -0
  126. package/dist/core/factory/uiFactory.js +32 -0
  127. package/dist/core/feature/oreFeature.d.ts +10 -0
  128. package/dist/core/feature/oreFeature.js +11 -0
  129. package/dist/core/feature-rule/condition/biomeFilter.d.ts +26 -0
  130. package/dist/core/feature-rule/condition/biomeFilter.js +36 -0
  131. package/dist/core/feature-rule/condition/featureConditions.d.ts +27 -0
  132. package/dist/core/feature-rule/condition/featureConditions.js +37 -0
  133. package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +17 -0
  134. package/dist/core/feature-rule/distribution/coordinateDistribution.js +23 -0
  135. package/dist/core/feature-rule/distribution/featureDistribution.d.ts +31 -0
  136. package/dist/core/feature-rule/distribution/featureDistribution.js +41 -0
  137. package/dist/core/feature-rule/featureRule.d.ts +17 -0
  138. package/dist/core/feature-rule/featureRule.js +26 -0
  139. package/dist/core/index.d.ts +2241 -0
  140. package/dist/core/index.js +1 -0
  141. package/dist/core/item/armor.d.ts +21 -0
  142. package/dist/core/item/armor.js +90 -0
  143. package/dist/core/item/attachable.d.ts +6 -0
  144. package/dist/core/item/attachable.js +26 -0
  145. package/dist/core/item/food.d.ts +24 -0
  146. package/dist/core/item/food.js +38 -0
  147. package/dist/core/item/item.d.ts +36 -0
  148. package/dist/core/item/item.js +69 -0
  149. package/dist/core/item/itemComponents.d.ts +113 -0
  150. package/dist/core/item/itemComponents.js +225 -0
  151. package/dist/core/registry.d.ts +12 -0
  152. package/dist/core/registry.js +17 -0
  153. package/dist/core/texture.d.ts +18 -0
  154. package/dist/core/texture.js +38 -0
  155. package/dist/core/ui/buttonMapping.d.ts +97 -0
  156. package/dist/core/ui/buttonMapping.js +132 -0
  157. package/dist/core/ui/dataBindingObject.d.ts +97 -0
  158. package/dist/core/ui/dataBindingObject.js +134 -0
  159. package/dist/core/ui/elements/button.d.ts +21 -0
  160. package/dist/core/ui/elements/button.js +101 -0
  161. package/dist/core/ui/elements/collectionPanel.d.ts +12 -0
  162. package/dist/core/ui/elements/collectionPanel.js +53 -0
  163. package/dist/core/ui/elements/grid.d.ts +8 -0
  164. package/dist/core/ui/elements/grid.js +33 -0
  165. package/dist/core/ui/elements/image.d.ts +13 -0
  166. package/dist/core/ui/elements/image.js +55 -0
  167. package/dist/core/ui/elements/label.d.ts +14 -0
  168. package/dist/core/ui/elements/label.js +61 -0
  169. package/dist/core/ui/elements/panel.d.ts +11 -0
  170. package/dist/core/ui/elements/panel.js +49 -0
  171. package/dist/core/ui/elements/scrollingPanel.d.ts +14 -0
  172. package/dist/core/ui/elements/scrollingPanel.js +59 -0
  173. package/dist/core/ui/elements/stackPanel.d.ts +14 -0
  174. package/dist/core/ui/elements/stackPanel.js +37 -0
  175. package/dist/core/ui/elements/uiElement.d.ts +53 -0
  176. package/dist/core/ui/elements/uiElement.js +129 -0
  177. package/dist/core/ui/properties/control.d.ts +214 -0
  178. package/dist/core/ui/properties/control.js +286 -0
  179. package/dist/core/ui/properties/dataBinding.d.ts +6 -0
  180. package/dist/core/ui/properties/dataBinding.js +16 -0
  181. package/dist/core/ui/properties/factory.d.ts +37 -0
  182. package/dist/core/ui/properties/factory.js +62 -0
  183. package/dist/core/ui/properties/gridProp.d.ts +65 -0
  184. package/dist/core/ui/properties/gridProp.js +90 -0
  185. package/dist/core/ui/properties/input.d.ts +97 -0
  186. package/dist/core/ui/properties/input.js +134 -0
  187. package/dist/core/ui/properties/layout.d.ts +105 -0
  188. package/dist/core/ui/properties/layout.js +145 -0
  189. package/dist/core/ui/properties/scrollView.d.ts +105 -0
  190. package/dist/core/ui/properties/scrollView.js +145 -0
  191. package/dist/core/ui/properties/sound.d.ts +47 -0
  192. package/dist/core/ui/properties/sound.js +66 -0
  193. package/dist/core/ui/properties/sprite.d.ts +161 -0
  194. package/dist/core/ui/properties/sprite.js +222 -0
  195. package/dist/core/ui/properties/text.d.ts +135 -0
  196. package/dist/core/ui/properties/text.js +187 -0
  197. package/dist/core/ui/registry/uiSystemRegistry.d.ts +8 -0
  198. package/dist/core/ui/registry/uiSystemRegistry.js +26 -0
  199. package/dist/core/ui/systems/chest.d.ts +5 -0
  200. package/dist/core/ui/systems/chest.js +21 -0
  201. package/dist/core/ui/systems/containerUISystem.d.ts +67 -0
  202. package/dist/core/ui/systems/containerUISystem.js +214 -0
  203. package/dist/core/ui/systems/guidebook.d.ts +9 -0
  204. package/dist/core/ui/systems/guidebook.js +206 -0
  205. package/dist/core/ui/systems/serverForm.d.ts +13 -0
  206. package/dist/core/ui/systems/serverForm.js +116 -0
  207. package/dist/core/ui/systems/system.d.ts +16 -0
  208. package/dist/core/ui/systems/system.js +37 -0
  209. package/dist/oc/actor.js +44 -0
  210. package/dist/oc/core.js +201 -0
  211. package/dist/oc/index.d.ts +142 -0
  212. package/dist/oc/index.js +1 -0
  213. package/dist/oc/input.js +67 -0
  214. package/dist/oc/optional.js +31 -0
  215. package/doc/oc/index.md +0 -0
  216. package/doc/sapdon-ts.md +41 -5
  217. package/package.json +6 -8
  218. package/doc/cli.md +0 -24
  219. /package/doc/hello_sapdon/{sapdon/344/275/277/347/224/250/346/225/231/347/250/213.md" → hello_sapdon.md} +0 -0
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 生成 block_texture.json 文件
3
+ * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
4
+ * @param {string} outputPath - 输出的 JSON 文件路径
5
+ * @param {string} projectName - 项目名称
6
+ */
7
+ export function generateBlockTextureJson(itemTexturesPath: string, outputPath: string, projectName: string, userTerrainTextures: any): Promise<void>;
8
+ /**
9
+ * 生成 item_texture.json 文件
10
+ * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
11
+ * @param {string} outputPath - 输出的 JSON 文件路径
12
+ */
13
+ export function generateItemTextureJson(itemTexturesPath: string, outputPath: string, projectName: any, userItemTextures: any): Promise<void>;
@@ -0,0 +1,103 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ /**
4
+ * 递归遍历目录,收集所有 PNG 文件的路径
5
+ * @param {string} directory - 要遍历的目录
6
+ * @param {string} basePath - 基础路径(用于计算相对路径)
7
+ * @param {string} prefix - 路径前缀(如 "textures/items/")
8
+ * @returns {Promise<Object>} - 返回一个对象,键为文件名,值为相对路径(不带 .png 后缀)
9
+ */
10
+ const traverseDirectory = async (directory, basePath, prefix = "") => {
11
+ const texturesSet = {};
12
+ const files = await fs.readdir(directory);
13
+ for (const file of files) {
14
+ const filePath = path.join(directory, file);
15
+ const fileStats = await fs.stat(filePath);
16
+ if (fileStats.isDirectory()) {
17
+ // 如果是目录,递归遍历
18
+ const subDirectoryTextures = await traverseDirectory(filePath, basePath, prefix);
19
+ Object.assign(texturesSet, subDirectoryTextures);
20
+ }
21
+ else if (file.endsWith(".png")) {
22
+ // 如果是 PNG 文件,提取文件名并生成 texture_data
23
+ const fileName = path.basename(file, ".png"); // 去掉 .png 后缀
24
+ const relativePath = path.relative(basePath, filePath).replace(/\.png$/, ""); // 去掉 .png 后缀
25
+ const normalizedPath = `${prefix}${relativePath.replace(/\\/g, "/")}`; // 确保路径使用正斜杠
26
+ texturesSet[fileName] = {
27
+ textures: normalizedPath,
28
+ };
29
+ }
30
+ }
31
+ return texturesSet;
32
+ };
33
+ /**
34
+ * 生成 JSON 文件
35
+ * @param {string} outputPath - 输出的 JSON 文件路径
36
+ * @param {Object} jsonData - 要写入的 JSON 数据
37
+ * @param {string} successMessage - 成功时的日志消息
38
+ */
39
+ const generateJsonFile = async (outputPath, jsonData, successMessage) => {
40
+ try {
41
+ const jsonString = JSON.stringify(jsonData, null, 2);
42
+ await fs.writeFile(outputPath, jsonString);
43
+ console.log(successMessage);
44
+ }
45
+ catch (err) {
46
+ console.error("Error writing JSON file:", err);
47
+ }
48
+ };
49
+ /**
50
+ * 生成 block_texture.json 文件
51
+ * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
52
+ * @param {string} outputPath - 输出的 JSON 文件路径
53
+ * @param {string} projectName - 项目名称
54
+ */
55
+ export async function generateBlockTextureJson(itemTexturesPath, outputPath, projectName, userTerrainTextures) {
56
+ try {
57
+ // 递归遍历目录,获取所有 PNG 文件的路径
58
+ const itemTexturesSet = await traverseDirectory(itemTexturesPath, itemTexturesPath, "textures/blocks/");
59
+ // 合并用户自定义的texture_data
60
+ if (userTerrainTextures) {
61
+ Object.assign(itemTexturesSet, userTerrainTextures);
62
+ }
63
+ // 生成 JSON 数据
64
+ const jsonData = {
65
+ texture_name: "atlas.terrain",
66
+ resource_pack_name: projectName,
67
+ padding: 8,
68
+ num_mip_levels: 4,
69
+ texture_data: itemTexturesSet,
70
+ };
71
+ // 写入文件
72
+ await generateJsonFile(outputPath, jsonData, "Block texture JSON file generated successfully.");
73
+ }
74
+ catch (err) {
75
+ console.error("Error generating block texture JSON:", err);
76
+ }
77
+ }
78
+ /**
79
+ * 生成 item_texture.json 文件
80
+ * @param {string} itemTexturesPath - 包含 PNG 文件的根目录
81
+ * @param {string} outputPath - 输出的 JSON 文件路径
82
+ */
83
+ export async function generateItemTextureJson(itemTexturesPath, outputPath, projectName, userItemTextures) {
84
+ try {
85
+ // 递归遍历目录,获取所有 PNG 文件的路径
86
+ const itemTexturesSet = await traverseDirectory(itemTexturesPath, itemTexturesPath, "textures/items/");
87
+ // 合并用户自定义的texture_data
88
+ if (userItemTextures) {
89
+ Object.assign(itemTexturesSet, userItemTextures);
90
+ }
91
+ // 生成 JSON 数据
92
+ const jsonData = {
93
+ resource_pack_name: projectName,
94
+ texture_name: "atlas.items",
95
+ texture_data: itemTexturesSet,
96
+ };
97
+ // 写入文件
98
+ await generateJsonFile(outputPath, jsonData, "Item texture JSON file generated successfully.");
99
+ }
100
+ catch (err) {
101
+ console.error("Error generating item texture JSON:", err);
102
+ }
103
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 同步复制文件
3
+ * @param {string} src 源文件路径
4
+ * @param {string} dest 目标文件路径
5
+ */
6
+ export function copyFileSync(src: string, dest: string): void;
7
+ export function dirname(importMeta: any): string;
8
+ export function asyncImport(path: any): Promise<any>;
9
+ export function generateUUID(): `${string}-${string}-${string}-${string}-${string}`;
10
+ export function pathNotExist(filePath: any): boolean;
11
+ export function readFile(filePath: any): string | null;
12
+ export function saveFile(filePath: string, data: string): void;
13
+ export function copyFolder(sourcePath: any, destinationPath: any): void;
@@ -0,0 +1,89 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { randomUUID } from "crypto";
4
+ import { fileURLToPath } from "node:url";
5
+ export const generateUUID = () => {
6
+ return randomUUID();
7
+ };
8
+ /**
9
+ * 同步复制文件
10
+ * @param {string} src 源文件路径
11
+ * @param {string} dest 目标文件路径
12
+ */
13
+ export function copyFileSync(src, dest) {
14
+ try {
15
+ fs.copyFileSync(src, dest);
16
+ }
17
+ catch (err) {
18
+ console.error("文件复制失败:", err);
19
+ }
20
+ }
21
+ //检查路径
22
+ export const pathNotExist = filePath => {
23
+ return !fs.existsSync(filePath);
24
+ };
25
+ //读取文件
26
+ export const readFile = filePath => {
27
+ try {
28
+ return fs.readFileSync(filePath, "utf8");
29
+ }
30
+ catch (error) {
31
+ console.log(error);
32
+ }
33
+ return null;
34
+ };
35
+ /**
36
+ * 保存文件
37
+ * @param {string} filePath 绝对路径
38
+ * @param {string} data 数据
39
+ */
40
+ export const saveFile = (filePath, data) => {
41
+ // 确保目录存在
42
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
43
+ // 创建文件并写入内容
44
+ fs.writeFile(filePath, data, err => {
45
+ if (err) {
46
+ return console.error(err);
47
+ }
48
+ });
49
+ };
50
+ export const copyFolder = (sourcePath, destinationPath) => {
51
+ // 确保目录存在
52
+ fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
53
+ // 检查源路径是否存在
54
+ if (!fs.existsSync(sourcePath)) {
55
+ console.log(`Source path ${sourcePath} does not exist.`);
56
+ return;
57
+ }
58
+ // 检查目标路径是否存在,如果不存在则创建它
59
+ if (!fs.existsSync(destinationPath)) {
60
+ fs.mkdirSync(destinationPath);
61
+ }
62
+ // 获取源路径下的所有文件和文件夹
63
+ const files = fs.readdirSync(sourcePath);
64
+ // 遍历文件和文件夹
65
+ files.forEach(file => {
66
+ const sourceFile = path.join(sourcePath, file);
67
+ const destinationFile = path.join(destinationPath, file);
68
+ // 判断是文件还是文件夹
69
+ if (fs.lstatSync(sourceFile).isDirectory()) {
70
+ // 如果是文件夹,则递归调用copyFolder函数
71
+ copyFolder(sourceFile, destinationFile);
72
+ }
73
+ else {
74
+ // 如果是文件,则直接复制到目标路径
75
+ fs.copyFileSync(sourceFile, destinationFile);
76
+ }
77
+ });
78
+ };
79
+ export function dirname(importMeta) {
80
+ const __filename = fileURLToPath(importMeta.url);
81
+ const __dirname = path.dirname(__filename);
82
+ return __dirname;
83
+ }
84
+ export function asyncImport(path) {
85
+ if (!path.startsWith('.')) {
86
+ return import('file://' + path);
87
+ }
88
+ return import(path);
89
+ }
@@ -0,0 +1,22 @@
1
+ export class AddonBiome {
2
+ constructor(format_version: any, definition: any);
3
+ format_version: any;
4
+ definition: any;
5
+ toJson(): {
6
+ format_version: any;
7
+ "minecraft:biome": any;
8
+ };
9
+ }
10
+ export class AddonBiomeDescription {
11
+ constructor(identifier: any);
12
+ identifier: any;
13
+ }
14
+ export class AddonBiomeDefinition {
15
+ /**
16
+ *
17
+ * @param {AddonBiomeDescription} description
18
+ */
19
+ constructor(description: AddonBiomeDescription, components: any);
20
+ description: AddonBiomeDescription;
21
+ components: any;
22
+ }
@@ -0,0 +1,27 @@
1
+ export class AddonBiome {
2
+ constructor(format_version, definition) {
3
+ this.format_version = format_version;
4
+ this.definition = definition;
5
+ }
6
+ toJson() {
7
+ return {
8
+ format_version: this.format_version,
9
+ ["minecraft:biome"]: this.definition
10
+ };
11
+ }
12
+ }
13
+ export class AddonBiomeDescription {
14
+ constructor(identifier) {
15
+ this.identifier = identifier;
16
+ }
17
+ }
18
+ export class AddonBiomeDefinition {
19
+ /**
20
+ *
21
+ * @param {AddonBiomeDescription} description
22
+ */
23
+ constructor(description, components) {
24
+ this.description = description;
25
+ this.components = components;
26
+ }
27
+ }
@@ -0,0 +1,41 @@
1
+ export class AddonBlock {
2
+ /**
3
+ * Addon方块类
4
+ * @param {string} format_version 格式版本
5
+ * @param {AddonBlockDefinition} definitions 方块定义
6
+ */
7
+ constructor(format_version: string, definitions: AddonBlockDefinition);
8
+ format_version: string;
9
+ definitions: AddonBlockDefinition;
10
+ toJson(): {
11
+ format_version: string;
12
+ "minecraft:block": AddonBlockDefinition;
13
+ };
14
+ }
15
+ export class AddonBlockDefinition {
16
+ /**
17
+ * 方块定义类
18
+ * @param {AddonBlockDescription} description 方块描述
19
+ * @param {Object} components 方块组件
20
+ * @param {Array} permutations 方块变体
21
+ */
22
+ constructor(description: AddonBlockDescription, components: Object, permutations?: any[]);
23
+ description: AddonBlockDescription;
24
+ components: Object;
25
+ permutations: any[];
26
+ }
27
+ export class AddonBlockDescription {
28
+ /**
29
+ * 方块描述类
30
+ * @param {string} identifier 唯一标识符
31
+ * @param {map} traits 方块特性
32
+ * @param {map} states 方块状态
33
+ * @param {AddonMenuCategory} menu_category
34
+ */
35
+ constructor(identifier: string, traits: map, states: map, menu_category: AddonMenuCategory);
36
+ identifier: string;
37
+ traits: map;
38
+ states: map;
39
+ menu_category: AddonMenuCategory;
40
+ }
41
+ import { AddonMenuCategory } from "../menuCategory.js";
@@ -0,0 +1,46 @@
1
+ import { AddonMenuCategory } from "../menuCategory.js";
2
+ export class AddonBlock {
3
+ /**
4
+ * Addon方块类
5
+ * @param {string} format_version 格式版本
6
+ * @param {AddonBlockDefinition} definitions 方块定义
7
+ */
8
+ constructor(format_version, definitions) {
9
+ this.format_version = format_version;
10
+ this.definitions = definitions;
11
+ }
12
+ toJson() {
13
+ return {
14
+ format_version: this.format_version,
15
+ ["minecraft:block"]: this.definitions
16
+ };
17
+ }
18
+ }
19
+ export class AddonBlockDefinition {
20
+ /**
21
+ * 方块定义类
22
+ * @param {AddonBlockDescription} description 方块描述
23
+ * @param {Object} components 方块组件
24
+ * @param {Array} permutations 方块变体
25
+ */
26
+ constructor(description, components, permutations = []) {
27
+ this.description = description;
28
+ this.components = components;
29
+ this.permutations = permutations;
30
+ }
31
+ }
32
+ export class AddonBlockDescription {
33
+ /**
34
+ * 方块描述类
35
+ * @param {string} identifier 唯一标识符
36
+ * @param {map} traits 方块特性
37
+ * @param {map} states 方块状态
38
+ * @param {AddonMenuCategory} menu_category
39
+ */
40
+ constructor(identifier, traits, states, menu_category) {
41
+ this.identifier = identifier;
42
+ this.traits = traits;
43
+ this.states = states;
44
+ this.menu_category = menu_category;
45
+ }
46
+ }
@@ -0,0 +1,43 @@
1
+ export class AddonAnimationController {
2
+ constructor(format_version: any, definition: any);
3
+ format_version: any;
4
+ definition: any;
5
+ toJson(): {
6
+ format_version: any;
7
+ animation_controllers: any;
8
+ };
9
+ }
10
+ export class AddonAnimationStateMachine {
11
+ constructor(identifier: any);
12
+ identifier: any;
13
+ namespace: any;
14
+ name: any;
15
+ initialState: string | null;
16
+ states: Map<any, any>;
17
+ /**
18
+ * 设置状态机的初始状态。
19
+ * @param {string} stateName - 初始状态的名称。
20
+ * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
21
+ */
22
+ setInitialState(stateName: string): AddonAnimationStateMachine;
23
+ /**
24
+ * 添加一个新状态到状态机。
25
+ * @param {string} stateName - 状态的名称。
26
+ * @param {string[]} animations - 该状态播放的动画列表。
27
+ * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
28
+ */
29
+ addState(stateName: string, animations?: string[]): AddonAnimationStateMachine;
30
+ /**
31
+ * 添加一个状态之间的过渡条件。
32
+ * @param {string} fromState - 过渡的起始状态名称。
33
+ * @param {string} toState - 过渡的目标状态名称。
34
+ * @param {string} condition - 触发过渡的条件(例如 "q.is_on_ground")。
35
+ * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
36
+ */
37
+ addTransition(fromState: string, toState: string, condition: string): AddonAnimationStateMachine;
38
+ /**
39
+ * 将整个状态机转换为 JSON 兼容的对象。
40
+ * @returns {object} - 包含格式版本的完整动画控制器定义。
41
+ */
42
+ toJson(): object;
43
+ }
@@ -0,0 +1,73 @@
1
+ export class AddonAnimationController {
2
+ constructor(format_version, definition) {
3
+ this.format_version = format_version;
4
+ this.definition = definition;
5
+ }
6
+ toJson() {
7
+ return {
8
+ format_version: this.format_version,
9
+ ["animation_controllers"]: this.definition
10
+ };
11
+ }
12
+ }
13
+ export class AddonAnimationStateMachine {
14
+ constructor(identifier) {
15
+ this.identifier = identifier; // 状态机的唯一标识符(例如 "helicopter.blade")
16
+ this.namespace = identifier.split(":")[0]; // 标识符的命名空间部分(冒号前的部分)
17
+ this.name = identifier.split(":")[1]; // 标识符的名称部分(冒号后的部分)
18
+ // 状态机属性
19
+ this.initialState = null; // 状态机的初始状态
20
+ this.states = new Map(); // 使用 Map 存储所有状态,键为状态名,值为状态数据
21
+ }
22
+ /**
23
+ * 设置状态机的初始状态。
24
+ * @param {string} stateName - 初始状态的名称。
25
+ * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
26
+ */
27
+ setInitialState(stateName) {
28
+ this.initialState = stateName;
29
+ return this; // 支持链式调用
30
+ }
31
+ /**
32
+ * 添加一个新状态到状态机。
33
+ * @param {string} stateName - 状态的名称。
34
+ * @param {string[]} animations - 该状态播放的动画列表。
35
+ * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
36
+ */
37
+ addState(stateName, animations = []) {
38
+ this.states.set(stateName, {
39
+ animations: animations, // 该状态的动画列表
40
+ transitions: [] // 该状态的过渡条件列表
41
+ });
42
+ return this; // 支持链式调用
43
+ }
44
+ /**
45
+ * 添加一个状态之间的过渡条件。
46
+ * @param {string} fromState - 过渡的起始状态名称。
47
+ * @param {string} toState - 过渡的目标状态名称。
48
+ * @param {string} condition - 触发过渡的条件(例如 "q.is_on_ground")。
49
+ * @returns {AddonAnimationStateMachine} - 返回实例以支持链式调用。
50
+ */
51
+ addTransition(fromState, toState, condition) {
52
+ if (!this.states.has(fromState)) {
53
+ throw new Error(`状态 "${fromState}" 不存在。`);
54
+ }
55
+ const state = this.states.get(fromState);
56
+ state.transitions.push({
57
+ [toState]: condition // 添加过渡条件
58
+ });
59
+ return this; // 支持链式调用
60
+ }
61
+ /**
62
+ * 将整个状态机转换为 JSON 兼容的对象。
63
+ * @returns {object} - 包含格式版本的完整动画控制器定义。
64
+ */
65
+ toJson() {
66
+ return {
67
+ [`controller.animation.${this.namespace}.${this.name}`]: {
68
+ initial_state: this.initialState,
69
+ states: Object.fromEntries(this.states)
70
+ }
71
+ };
72
+ }
73
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * 表示 Minecraft 插件中的渲染控制器组。
3
+ * 该类用于管理一组渲染控制器,并提供添加、设置和转换为 JSON 的方法。
4
+ */
5
+ export class AddonRenderControllerGroup {
6
+ /**
7
+ * 创建一个新的 AddonRenderControllerGroup 实例。
8
+ * @param {string} format_version - 渲染控制器的格式版本。
9
+ * @param {Map} [render_controllers] - 渲染控制器的 Map(可选)。默认为空 Map。
10
+ */
11
+ constructor(format_version, render_controllers) {
12
+ /**
13
+ * 渲染控制器的格式版本。
14
+ * @type {string}
15
+ */
16
+ this.format_version = format_version;
17
+ /**
18
+ * 渲染控制器的 Map,键为标识符,值为渲染控制器。
19
+ * @type {Map<string, AddonRenderController>}
20
+ */
21
+ this.render_controllers = render_controllers || new Map();
22
+ }
23
+ /**
24
+ * 设置或更新组中的渲染控制器。
25
+ * @param {string} identifier - 渲染控制器的唯一标识符。
26
+ * @param {AddonRenderController} render_controller - 要添加或更新的渲染控制器。
27
+ */
28
+ setRenderController(identifier, render_controller) {
29
+ this.render_controllers.set(identifier, render_controller);
30
+ return this; // 支持链式调用
31
+ }
32
+ /**
33
+ * 使用渲染控制器的标识符将其添加到组中。
34
+ * @param {AddonRenderController} render_controller - 要添加的渲染控制器。
35
+ */
36
+ addRenderController(render_controller) {
37
+ this.render_controllers.set(render_controller.name, render_controller.toJson());
38
+ return this; // 支持链式调用
39
+ }
40
+ /**
41
+ * 将渲染控制器组转换为 JSON 对象。
42
+ * @returns {Object} - 渲染控制器组的 JSON 表示。
43
+ */
44
+ toJson() {
45
+ return {
46
+ format_version: this.format_version,
47
+ render_controllers: Object.fromEntries(this.render_controllers)
48
+ };
49
+ }
50
+ }
51
+ /**
52
+ * 表示 Minecraft 插件中的渲染控制器。
53
+ * 该类定义了用于渲染实体的几何体、材质、纹理和数组。
54
+ */
55
+ export class AddonRenderController {
56
+ /**
57
+ * 创建一个新的 AddonRenderController 实例。
58
+ * @param {string} name - 渲染控制器的名称。
59
+ */
60
+ constructor(name) {
61
+ /**
62
+ * 渲染控制器的名称。
63
+ * @type {string}
64
+ */
65
+ this.name = `render_controller.${name}`;
66
+ /**
67
+ * 数组集合(例如纹理、几何体)。
68
+ * @type {Object}
69
+ */
70
+ this.arrays = {};
71
+ /**
72
+ * 用于渲染的默认几何体。
73
+ * @type {string}
74
+ */
75
+ this.geometry = "Geometry.default";
76
+ /**
77
+ * 用于渲染的材质列表。
78
+ * @type {Array<string>}
79
+ */
80
+ this.material = [];
81
+ /**
82
+ * 用于渲染的纹理列表。
83
+ * @type {Array<string>}
84
+ */
85
+ this.texture = [];
86
+ }
87
+ /**
88
+ * 设置渲染控制器的默认几何体。
89
+ * @param {string} geometry - 要设置的几何体。
90
+ */
91
+ setGeometry(geometry) {
92
+ this.geometry = geometry;
93
+ return this; // 支持链式调用
94
+ }
95
+ /**
96
+ * 向材质列表中添加一个材质。
97
+ * @param {string} material - 要添加的材质。
98
+ */
99
+ addMaterial(material) {
100
+ this.material.push(material);
101
+ return this; // 支持链式调用
102
+ }
103
+ /**
104
+ * 向纹理列表中添加一个纹理。
105
+ * @param {string} texture - 要添加的纹理。
106
+ */
107
+ addTexture(texture) {
108
+ this.texture.push(texture);
109
+ return this; // 支持链式调用
110
+ }
111
+ /**
112
+ * 注册一个数组。
113
+ * @param {string} name - 数组的名称。
114
+ * @param {Array} array - 要注册的数组。
115
+ */
116
+ registerArray(name, array) {
117
+ this.arrays[`Array.${name}`] = { [name]: array };
118
+ return this; // 支持链式调用
119
+ }
120
+ /**
121
+ * 注册几何体数组。
122
+ * @param {Array} array - 要注册的几何体数组。
123
+ */
124
+ registerGeometriesArray(array) {
125
+ this.registerArray("geometries", array);
126
+ return this; // 支持链式调用
127
+ }
128
+ /**
129
+ * 注册纹理数组。
130
+ * @param {Array} array - 要注册的纹理数组。
131
+ */
132
+ registerTexturesArray(array) {
133
+ this.registerArray("textures", array);
134
+ return this; // 支持链式调用
135
+ }
136
+ /**
137
+ * 将渲染控制器转换为 JSON 对象。
138
+ * @returns {Object} - 渲染控制器的 JSON 表示。
139
+ */
140
+ toJson() {
141
+ return {
142
+ arrays: this.arrays,
143
+ geometry: this.geometry,
144
+ material: this.material,
145
+ texture: this.texture
146
+ };
147
+ }
148
+ }
149
+ /*
150
+ // 示例用法
151
+ const renderControllerGroup = new AddonRenderControllerGroup("1.10.0");
152
+
153
+ const renderController = new AddonRenderController("custom_entity");
154
+ renderController.setGeometry("Geometry.custom");
155
+ renderController.addMaterial("Material.default");
156
+ renderController.addTexture("Texture.default");
157
+ renderController.registerTexturesArray(["Texture.variant_1", "Texture.variant_2"]);
158
+
159
+ renderControllerGroup.addRenderController(renderController);
160
+
161
+ console.log(JSON.stringify(renderControllerGroup.toJson(), null, 4));
162
+ */