sapdon 3.0.1 → 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.
- package/README.md +3 -1
- package/dist/cli/build.js +3 -1
- package/dist/cli/dev-server/client.js +2 -1
- package/dist/cli/dev-server/handles.d.ts +4 -0
- package/dist/cli/dev-server/handles.js +5 -0
- package/dist/cli/dev-server/index.d.ts +3 -2
- package/dist/cli/dev-server/index.js +12 -6
- package/dist/cli/dev-server/server.d.ts +13 -5
- package/dist/cli/dev-server/server.js +51 -42
- package/dist/cli/dev-server/syncFiles.js +2 -1
- package/dist/cli/index.d.ts +23 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/load.d.ts +1 -1
- package/dist/cli/start.js +1 -155
- package/dist/cli/utils.d.ts +1 -1
- package/dist/core/addon/block/block.d.ts +2 -2
- package/dist/core/addon/controllers/animationController.d.ts +1 -1
- package/dist/core/addon/entity/clientEntity.d.ts +11 -11
- package/dist/core/addon/entity/entity.d.ts +4 -4
- package/dist/core/addon/item/attachable.d.ts +10 -10
- package/dist/core/addon/manifest.d.ts +1 -1
- package/dist/core/biome/biomeComponent.d.ts +1 -1
- package/dist/core/block/basicBlock.d.ts +1 -1
- package/dist/core/block/blockComponent.d.ts +4 -4
- package/dist/core/block/geometryBlock.d.ts +1 -1
- package/dist/core/entity/basicEntity.d.ts +9 -9
- package/dist/core/entity/behavior/randomStroll.d.ts +1 -1
- package/dist/core/entity/behavior/tempt.d.ts +2 -2
- package/dist/core/entity/clientEntity.d.ts +2 -2
- package/dist/core/entity/componets/entityComponet.d.ts +4 -4
- package/dist/core/entity/data/nativeEntityData.d.ts +2 -2
- package/dist/core/entity/navigation/walk.d.ts +19 -19
- package/dist/core/factory/entityFactory.d.ts +3 -3
- package/dist/core/factory/itemFactory.d.ts +1 -1
- package/dist/core/factory/uiFactory.d.ts +2 -1
- package/dist/core/factory/uiFactory.js +1 -1
- package/dist/core/feature-rule/condition/biomeFilter.d.ts +2 -2
- package/dist/core/feature-rule/condition/featureConditions.d.ts +2 -2
- package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +1 -1
- package/dist/core/feature-rule/distribution/featureDistribution.d.ts +4 -4
- package/dist/core/index.d.ts +2062 -24
- package/dist/core/index.js +1 -21
- package/dist/core/item/attachable.d.ts +1 -1
- package/dist/core/item/item.d.ts +1 -1
- package/dist/core/item/itemComponents.d.ts +1 -1
- package/dist/core/texture.d.ts +1 -1
- package/dist/core/ui/buttonMapping.d.ts +3 -3
- package/dist/core/ui/dataBindingObject.d.ts +11 -11
- package/dist/core/ui/properties/control.d.ts +23 -23
- package/dist/core/ui/properties/dataBinding.d.ts +1 -1
- package/dist/core/ui/properties/factory.d.ts +1 -1
- package/dist/core/ui/properties/gridProp.d.ts +7 -7
- package/dist/core/ui/properties/input.d.ts +11 -11
- package/dist/core/ui/properties/layout.d.ts +12 -12
- package/dist/core/ui/properties/scrollView.d.ts +12 -12
- package/dist/core/ui/properties/sound.d.ts +4 -4
- package/dist/core/ui/properties/sprite.d.ts +19 -19
- package/dist/core/ui/properties/text.d.ts +15 -15
- package/dist/core/ui/systems/chest.d.ts +2 -1
- package/dist/core/ui/systems/chest.js +1 -1
- package/dist/core/ui/systems/containerUISystem.d.ts +8 -5
- package/dist/core/ui/systems/containerUISystem.js +9 -1
- package/dist/core/ui/systems/guidebook.d.ts +2 -1
- package/dist/core/ui/systems/guidebook.js +1 -1
- package/dist/core/ui/systems/serverForm.d.ts +2 -1
- package/dist/core/ui/systems/serverForm.js +1 -1
- package/dist/core/ui/systems/system.js +2 -2
- package/dist/oc/index.d.ts +142 -0
- package/dist/oc/index.js +1 -0
- package/doc/cli.md +24 -0
- package/doc/sapdon-ts.md +51 -5
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ hello_sapdon/
|
|
|
61
61
|
1. 打开 `main.mjs` 文件。
|
|
62
62
|
2. 写入以下内容以创建一个基础物品:
|
|
63
63
|
```javascript
|
|
64
|
-
import { ItemAPI } from "
|
|
64
|
+
import { ItemAPI } from "@sapdon/core";
|
|
65
65
|
|
|
66
66
|
ItemAPI.createItem("hello_sapdon:my_item", "items", "masterball");
|
|
67
67
|
```
|
|
@@ -109,3 +109,5 @@ npm update sapdon
|
|
|
109
109
|
|
|
110
110
|
- 官方 QQ 群:`810904181`
|
|
111
111
|
|
|
112
|
+
## ts支持
|
|
113
|
+
[quick start](./doc/sapdon-ts.md)
|
package/dist/cli/build.js
CHANGED
|
@@ -42,10 +42,13 @@ export const scriptBundler = {
|
|
|
42
42
|
nodeResolve({
|
|
43
43
|
preferBuiltins: true
|
|
44
44
|
}),
|
|
45
|
+
//@ts-ignore
|
|
45
46
|
ts({
|
|
46
47
|
tsconfig: path.join(scriptBundler.__projectPath, 'tsconfig.json'),
|
|
47
48
|
}),
|
|
49
|
+
//@ts-ignore
|
|
48
50
|
commonjs(),
|
|
51
|
+
//@ts-ignore
|
|
49
52
|
json(),
|
|
50
53
|
// visualizer({ open: true }), //可视化分析, 打包出问题取消注释这一行
|
|
51
54
|
],
|
|
@@ -88,7 +91,6 @@ function preload(filePath) {
|
|
|
88
91
|
const { startDevServer } = await import('@sapdon/cli')
|
|
89
92
|
const { GRegistry, UISystemRegistry } = await import('@sapdon/core')
|
|
90
93
|
startDevServer(GRegistry, UISystemRegistry)
|
|
91
|
-
process.send('initialized')
|
|
92
94
|
})();
|
|
93
95
|
`);
|
|
94
96
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { devServerConfig } from './config.js';
|
|
2
|
+
import { ServerHandles } from './handles.js';
|
|
2
3
|
const { port } = devServerConfig;
|
|
3
4
|
export async function cliRequest(path, ...params) {
|
|
4
5
|
try {
|
|
@@ -16,5 +17,5 @@ export async function cliRequest(path, ...params) {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
export async function writeAddon(modPath, buildPath, projectName) {
|
|
19
|
-
await cliRequest(
|
|
20
|
+
await cliRequest(ServerHandles.WRITE_ADDON, modPath, buildPath, projectName);
|
|
20
21
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { server };
|
|
1
|
+
import { ServerHandles } from "./handles.js";
|
|
3
2
|
import { server } from "./server.js";
|
|
3
|
+
export declare function startDevServer(GRegistry: any, UIRegistry: any): void;
|
|
4
|
+
export { server, ServerHandles, };
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { generateAddon } from "../load.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ServerHandles } from "./handles.js";
|
|
3
|
+
import { server } from "./server.js";
|
|
3
4
|
import { syncDevFilesServer } from "./syncFiles.js";
|
|
5
|
+
function startup(GRegistry, UIRegistry) {
|
|
6
|
+
server.bootstrap();
|
|
7
|
+
server.handle(ServerHandles.WRITE_ADDON, generateAddon(GRegistry, UIRegistry));
|
|
8
|
+
server.handle(ServerHandles.WRITE_GAME_DEV, syncDevFilesServer);
|
|
9
|
+
}
|
|
4
10
|
export function startDevServer(GRegistry, UIRegistry) {
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
server.handle('write-addon', generateAddon(GRegistry, UIRegistry));
|
|
8
|
-
server.handle('sync-files', syncDevFilesServer);
|
|
11
|
+
if (server.isListening()) {
|
|
12
|
+
return;
|
|
9
13
|
}
|
|
14
|
+
startup(GRegistry, UIRegistry);
|
|
15
|
+
process.send('initialized');
|
|
10
16
|
}
|
|
11
|
-
export { server, };
|
|
17
|
+
export { server, ServerHandles, };
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
export function isListening(): boolean;
|
|
2
|
-
export function bootstrap(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
3
|
-
export namespace server {
|
|
4
|
-
function handle(url: any, handler: any): void;
|
|
5
|
-
}
|
|
6
1
|
import http from 'http';
|
|
2
|
+
type ServerHandler = (...args: Transferable[]) => void;
|
|
3
|
+
type HandlerInterceptor = (handler: ServerHandler) => ServerHandler;
|
|
4
|
+
declare class DevelopmentServer {
|
|
5
|
+
readonly cliServerHandlers: Map<string, ServerHandler>;
|
|
6
|
+
listening: boolean;
|
|
7
|
+
isListening(): boolean;
|
|
8
|
+
bootstrap(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
9
|
+
handle(url: string, handler: ServerHandler): void;
|
|
10
|
+
getHandler(url: string): ServerHandler | undefined;
|
|
11
|
+
interceptHandler(url: string, interceptor: HandlerInterceptor): ServerHandler;
|
|
12
|
+
}
|
|
13
|
+
export declare const server: DevelopmentServer;
|
|
14
|
+
export {};
|
|
@@ -1,50 +1,59 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import { devServerConfig } from './config.js';
|
|
3
3
|
const { port } = devServerConfig;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
class DevelopmentServer {
|
|
5
|
+
cliServerHandlers = new Map();
|
|
6
|
+
listening = false;
|
|
7
|
+
isListening() {
|
|
8
|
+
return this.listening;
|
|
9
|
+
}
|
|
10
|
+
bootstrap() {
|
|
11
|
+
this.listening = true;
|
|
12
|
+
const svr = http.createServer(async (req, res) => {
|
|
13
|
+
const handler = this.cliServerHandlers.get((req.url ?? '/').slice(1));
|
|
14
|
+
if (handler) {
|
|
15
|
+
try {
|
|
16
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
17
|
+
let buf = Buffer.alloc(0);
|
|
18
|
+
req.on('data', chunk => buf = Buffer.concat([buf, chunk]));
|
|
19
|
+
req.on('end', () => {
|
|
20
|
+
try {
|
|
21
|
+
resolve(JSON.parse(buf));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
reject(error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
await handler(...await promise);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(error);
|
|
31
|
+
res.writeHead(500);
|
|
32
|
+
res.end();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
res.writeHead(200);
|
|
36
|
+
res.end();
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
res.writeHead(500);
|
|
38
|
+
else {
|
|
39
|
+
res.writeHead(404);
|
|
32
40
|
res.end();
|
|
33
|
-
return;
|
|
34
41
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
res.writeHead(404);
|
|
40
|
-
res.end();
|
|
41
|
-
}
|
|
42
|
-
}).listen(port, () => console.log(`Dev Server listening on port ${port}`));
|
|
43
|
-
svr.on('error', () => listening = false);
|
|
44
|
-
return svr;
|
|
45
|
-
}
|
|
46
|
-
export const server = {
|
|
42
|
+
}).listen(port, () => console.log(`Dev Server listening on port ${port}`));
|
|
43
|
+
svr.on('error', () => this.listening = false);
|
|
44
|
+
return svr;
|
|
45
|
+
}
|
|
47
46
|
handle(url, handler) {
|
|
48
|
-
cliServerHandlers.set(url, handler);
|
|
47
|
+
this.cliServerHandlers.set(url, handler);
|
|
48
|
+
}
|
|
49
|
+
getHandler(url) {
|
|
50
|
+
return this.cliServerHandlers.get(url);
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
interceptHandler(url, interceptor) {
|
|
53
|
+
const currentHandler = this.getHandler(url) ?? Function.prototype;
|
|
54
|
+
const newHandler = interceptor(currentHandler);
|
|
55
|
+
this.cliServerHandlers.set(url, newHandler);
|
|
56
|
+
return newHandler;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export const server = new DevelopmentServer();
|
|
@@ -3,8 +3,9 @@ import { cliRequest } from "./client.js";
|
|
|
3
3
|
import { copyFolder, dirname } from "../utils.js";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import fs from 'fs';
|
|
6
|
+
import { ServerHandles } from "./handles.js";
|
|
6
7
|
export async function syncDevFilesClient(projectPath, projectName) {
|
|
7
|
-
await cliRequest(
|
|
8
|
+
await cliRequest(ServerHandles.WRITE_GAME_DEV, projectPath, projectName);
|
|
8
9
|
}
|
|
9
10
|
export async function syncDevFilesServer(projectPath, projectName) {
|
|
10
11
|
const buildConfig = JSON.parse(readFileSync(path.join(projectPath, "build.config")));
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
import http from 'http';
|
|
2
|
+
|
|
3
|
+
declare enum ServerHandles {
|
|
4
|
+
WRITE_ADDON = "write-addon",
|
|
5
|
+
WRITE_GAME_DEV = "write-dev"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type ServerHandler = (...args: Transferable[]) => void;
|
|
9
|
+
type HandlerInterceptor = (handler: ServerHandler) => ServerHandler;
|
|
10
|
+
declare class DevelopmentServer {
|
|
11
|
+
readonly cliServerHandlers: Map<string, ServerHandler>;
|
|
12
|
+
listening: boolean;
|
|
13
|
+
isListening(): boolean;
|
|
14
|
+
bootstrap(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
15
|
+
handle(url: string, handler: ServerHandler): void;
|
|
16
|
+
getHandler(url: string): ServerHandler | undefined;
|
|
17
|
+
interceptHandler(url: string, interceptor: HandlerInterceptor): ServerHandler;
|
|
18
|
+
}
|
|
19
|
+
declare const server: DevelopmentServer;
|
|
20
|
+
|
|
21
|
+
declare function startDevServer(GRegistry: any, UIRegistry: any): void;
|
|
22
|
+
|
|
23
|
+
export { ServerHandles, server as devServer, startDevServer };
|
package/dist/cli/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import e from"path";import t,{readFileSync as r}from"fs";import"crypto";import"node:url";import s from"fs/promises";import n from"http";const i=(r,s)=>{t.mkdirSync(e.dirname(r),{recursive:!0}),t.writeFile(r,s,(e=>{if(e)return console.error(e)}))},o=(r,s)=>{if(t.mkdirSync(e.dirname(s),{recursive:!0}),!t.existsSync(r))return void console.log(`Source path ${r} does not exist.`);t.existsSync(s)||t.mkdirSync(s);t.readdirSync(r).forEach((n=>{const i=e.join(r,n),a=e.join(s,n);t.lstatSync(i).isDirectory()?o(i,a):t.copyFileSync(i,a)}))},a=async(t,r,n="")=>{const i={},o=await s.readdir(t);for(const c of o){const o=e.join(t,c);if((await s.stat(o)).isDirectory()){const e=await a(o,r,n);Object.assign(i,e)}else if(c.endsWith(".png")){const t=e.basename(c,".png"),s=`${n}${e.relative(r,o).replace(/\.png$/,"").replace(/\\/g,"/")}`;i[t]={textures:s}}}return i},c=async(e,t,r)=>{try{const n=JSON.stringify(t,null,2);await s.writeFile(e,n),console.log(r)}catch(e){console.error("Error writing JSON file:",e)}};class l{static item_texture_sets=new Map;static getItemTextureSet(){return this.item_texture_sets}static getItemTextures(){return Object.fromEntries(this.item_texture_sets)}static registerTextureData(e,t){this.item_texture_sets.set(e,t)}static registerTexture(e,t){this.registerTextureData(e,{textures:t})}}class u{static terrain_texture_sets=new Map;static getTerrainTextureSet(){return this.terrain_texture_sets}static getTerrainTextures(){return Object.fromEntries(this.terrain_texture_sets)}static registerTextureData(e,t){this.terrain_texture_sets.set(e,t)}static registerTexture(e,t){this.registerTextureData(e,{textures:t})}}const g={flipbook_textures:[],registerFlipbookTexture(e,t,r,s={}){const n={atlas_tile:e,flipbook_texture:t,ticks_per_frame:r};Object.assign(n,s),this.flipbook_textures.push(n)}};var _;!function(e){e.WRITE_ADDON="write-addon",e.WRITE_GAME_DEV="write-dev"}(_||(_={}));const d=(t,r)=>async(s,n,o)=>{try{const _=e.join(n,`${o}_BP`),d=e.join(n,`${o}_RP`),f=t=>e.join(d,t),x=e.join(_,"blocks.json"),p={format_version:"1.20.20"},m=f("textures/items");!async function(e,t,r,s){try{const n=await a(e,e,"textures/items/");s&&Object.assign(n,s);const i={resource_pack_name:r,texture_name:"atlas.items",texture_data:n};await c(t,i,"Item texture JSON file generated successfully.")}catch(e){console.error("Error generating item texture JSON:",e)}}(m,f("textures/item_texture.json"),o,l.getItemTextures());const h=f("textures/blocks");!async function(e,t,r,s){try{const n=await a(e,e,"textures/blocks/");s&&Object.assign(n,s);const i={texture_name:"atlas.terrain",resource_pack_name:r,padding:8,num_mip_levels:4,texture_data:n};await c(t,i,"Block texture JSON file generated successfully.")}catch(e){console.error("Error generating block texture JSON:",e)}}(h,f("textures/terrain_texture.json"),o,u.getTerrainTextures());const y=f("textures/flipbook_textures.json");i(y,JSON.stringify(g.flipbook_textures,null,2));const j=r.getUIdefList();i(f("ui/_ui_defs.json"),JSON.stringify({ui_defs:j},null,2)),r.getUISystemList().forEach((e=>{i(f(e.path,`${e.name}.json`),JSON.stringify(e.toJson(),null,2))}));t.getDataList().forEach((({name:t,root:r,path:s,data:a})=>{if("blocks/"===s){const e=(e=>{const t=e.textures;if(6!==t.length)return console.warn(`blocks.json 的 textures 数组长度不为 6,实际长度: ${t.length}`),{};const r={};return r[e.identifier]={textures:{up:t[0],down:t[1],east:t[2],west:t[3],south:t[4],north:t[5]}},r})(a);Object.assign(p,e)}const c="behavior"===r?`${o}_BP`:`${o}_RP`,l=e.join(n,c),u=e.join(l,s,`${t}.json`);i(u,JSON.stringify(a.toJson(),null,2))})),console.log("保存 blocks.json 文件:",x),i(x,JSON.stringify(p,null,2)),console.log(`已加载并执行 ${s} 文件!`)}catch(e){console.error(`加载或执行 ${s} 失败:${e.message}`),console.error(e.stack)}},{port:f}={port:49037};const x=new class{cliServerHandlers=new Map;listening=!1;isListening(){return this.listening}bootstrap(){this.listening=!0;const e=n.createServer((async(e,t)=>{const r=this.cliServerHandlers.get((e.url??"/").slice(1));if(r){try{const{promise:t,resolve:s,reject:n}=Promise.withResolvers();let i=Buffer.alloc(0);e.on("data",(e=>i=Buffer.concat([i,e]))),e.on("end",(()=>{try{s(JSON.parse(i))}catch(e){n(e)}})),await r(...await t)}catch(e){return console.error(e),t.writeHead(500),void t.end()}t.writeHead(200),t.end()}else t.writeHead(404),t.end()})).listen(f,(()=>console.log(`Dev Server listening on port ${f}`)));return e.on("error",(()=>this.listening=!1)),e}handle(e,t){this.cliServerHandlers.set(e,t)}getHandler(e){return this.cliServerHandlers.get(e)}interceptHandler(e,t){const r=t(this.getHandler(e)??Function.prototype);return this.cliServerHandlers.set(e,r),r}};async function p(t,s){const n=JSON.parse(r(e.join(t,"build.config"))),i=e.join(t,n.defaultConfig.buildDir),a=e.join(i,`${s}_BP`),c=e.join(i,`${s}_RP`);o(a,e.join(n.mojangPath,"development_behavior_packs/",`${s}_BP/`)),o(c,e.join(n.mojangPath,"development_resource_packs/",`${s}_RP/`))}function m(e,t){x.isListening()||(!function(e,t){x.bootstrap(),x.handle(_.WRITE_ADDON,d(e,t)),x.handle(_.WRITE_GAME_DEV,p)}(e,t),process.send("initialized"))}export{_ as ServerHandles,x as devServer,m as startDevServer};
|
package/dist/cli/init.d.ts
CHANGED
package/dist/cli/load.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function processBlocksData(data:
|
|
1
|
+
export function processBlocksData(data: Object): Object;
|
|
2
2
|
export function generateAddonClient(modPath: any, buildPath: any, projectName: any): Promise<void>;
|
|
3
3
|
export function generateAddon(GRegistry: any, UISystemRegistry: any): (modPath: any, buildPath: any, projectName: any) => Promise<void>;
|
package/dist/cli/start.js
CHANGED
|
@@ -1,156 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { program } from 'commander';
|
|
3
|
-
import inquirer from 'inquirer';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
import { initMojangPath, initNPMProject, initProject, readPackageJson } from './init.js';
|
|
7
|
-
import { buildProject, projectCanBuild } from './build.js';
|
|
8
|
-
import { readFile } from "./utils.js";
|
|
9
|
-
import fs from "fs";
|
|
10
|
-
import { fileURLToPath } from "url";
|
|
11
|
-
import { writeLib } from './dev-server/syncFiles.js';
|
|
12
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
-
const __dirname = path.dirname(__filename);
|
|
14
|
-
process.removeAllListeners('warning');
|
|
15
|
-
function start() {
|
|
16
|
-
// 额外添加的init方法
|
|
17
|
-
program.command("init").description("初始化一个基于NodeJS的项目").action(() => {
|
|
18
|
-
const currentDir = process.cwd();
|
|
19
|
-
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
20
|
-
let packageJsonData;
|
|
21
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
22
|
-
console.error("没有找到package.json文件,请使改用create命令进行创建。");
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
packageJsonData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error("读取package.json文件时出错:", error);
|
|
30
|
-
console.log("请使改用create命令进行创建。");
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
// 添加或更新scripts字段
|
|
34
|
-
packageJsonData.scripts = {
|
|
35
|
-
...packageJsonData.scripts,
|
|
36
|
-
init: "sapdon init",
|
|
37
|
-
pack: "sapdon pack",
|
|
38
|
-
config: "sapdon config"
|
|
39
|
-
};
|
|
40
|
-
try {
|
|
41
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonData, null, 2), 'utf-8');
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
console.error("写入package.json文件时出错:", error);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
inquirer.prompt([
|
|
48
|
-
{
|
|
49
|
-
type: "input",
|
|
50
|
-
name: "min_engine_version",
|
|
51
|
-
message: "最低引擎版本:",
|
|
52
|
-
default: "1.19.50"
|
|
53
|
-
}
|
|
54
|
-
]).then((answers) => {
|
|
55
|
-
initNPMProject(currentDir, { ...readPackageJson(currentDir), ...answers });
|
|
56
|
-
console.log("请使用命令sapdon config配置框架的build.config文件。");
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
program.command("create <project-name>").description("Create a new project").action((projectName) => {
|
|
60
|
-
inquirer.prompt([
|
|
61
|
-
{
|
|
62
|
-
type: "input",
|
|
63
|
-
name: "name",
|
|
64
|
-
message: "Project Name:",
|
|
65
|
-
default: path.basename(projectName)
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
type: "input",
|
|
69
|
-
name: "description",
|
|
70
|
-
message: "Project Description:",
|
|
71
|
-
default: "A new sapdon project"
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
type: "input",
|
|
75
|
-
name: "author",
|
|
76
|
-
message: "Author Name:",
|
|
77
|
-
default: "Sapdon"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
type: "input",
|
|
81
|
-
name: "version",
|
|
82
|
-
message: "Project Version:",
|
|
83
|
-
default: "1.0.0"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
type: "input",
|
|
87
|
-
name: "min_engine_version",
|
|
88
|
-
message: "Minimum Engine Version:",
|
|
89
|
-
default: "1.19.50",
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
type: "input",
|
|
93
|
-
name: "language",
|
|
94
|
-
message: "Language:(js/ts)",
|
|
95
|
-
default: "ts",
|
|
96
|
-
},
|
|
97
|
-
]).then((answers) => {
|
|
98
|
-
const projectPath = path.join(process.cwd(), projectName);
|
|
99
|
-
console.log('项目路径:', projectPath);
|
|
100
|
-
initProject(projectPath, answers);
|
|
101
|
-
initMojangPath(projectPath);
|
|
102
|
-
writeLib(projectPath);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
program.command("build <project-name>").description("Build the project").action((projectName) => {
|
|
106
|
-
console.log("Building the project...");
|
|
107
|
-
const projectPath = path.join(process.cwd(), projectName);
|
|
108
|
-
if (projectCanBuild(projectPath)) {
|
|
109
|
-
buildProject(projectPath, path.basename(projectPath));
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
// pack 命令
|
|
113
|
-
program.command("pack").description("Pack the current project").action(() => {
|
|
114
|
-
console.log("Packing the current project...");
|
|
115
|
-
const projectPath = process.cwd();
|
|
116
|
-
if (projectCanBuild(projectPath)) {
|
|
117
|
-
buildProject(projectPath, path.basename(projectPath));
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
// 配置build.config文件的命令
|
|
121
|
-
program.command("config").description("Configure build.config file").action(() => {
|
|
122
|
-
const buildConfigPath = path.join(__dirname, "./build.config");
|
|
123
|
-
let buildConfigData;
|
|
124
|
-
try {
|
|
125
|
-
buildConfigData = JSON.parse(readFile(buildConfigPath));
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
console.error("读取build.config文件时出错:", error);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
inquirer.prompt([
|
|
132
|
-
{
|
|
133
|
-
type: "input",
|
|
134
|
-
name: "mojangPath",
|
|
135
|
-
message: "Mojang Path (must end with LocalState/games/com.mojang/):",
|
|
136
|
-
default: path.join(os.homedir(), "AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/")
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
type: "input",
|
|
140
|
-
name: "mojangBetaPath",
|
|
141
|
-
message: "Mojang Beta Path (must end with LocalState/games/com.mojang/):",
|
|
142
|
-
default: path.join(os.homedir(), "AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/")
|
|
143
|
-
}
|
|
144
|
-
]).then((answers) => {
|
|
145
|
-
try {
|
|
146
|
-
fs.writeFileSync(buildConfigPath, JSON.stringify({ ...buildConfigData, ...answers }, null, 2), 'utf-8');
|
|
147
|
-
console.log("build.config文件已更新。");
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
console.error("写入build.config文件时出错:", error);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
program.parse(program.argv);
|
|
155
|
-
}
|
|
156
|
-
start();
|
|
2
|
+
import{program as n}from"commander";import o from"inquirer";import e from"path";import i from"os";import{fileURLToPath as t}from"url";import s from"fs";import{randomUUID as r}from"crypto";import{fileURLToPath as c}from"node:url";import a from"child_process";import"fs/promises";import{rollup as p}from"rollup";import l from"@rollup/plugin-commonjs";import{nodeResolve as m}from"@rollup/plugin-node-resolve";import d from"@rollup/plugin-typescript";import{typescriptPaths as u}from"rollup-plugin-typescript-paths";import f from"@rollup/plugin-json";import"rollup-plugin-visualizer";import g from"lodash";const j=()=>r();function y(n,o){try{s.copyFileSync(n,o)}catch(n){console.error("文件复制失败:",n)}}const h=n=>!s.existsSync(n),S=n=>{try{return s.readFileSync(n,"utf8")}catch(n){console.log(n)}return null},_=(n,o)=>{s.mkdirSync(e.dirname(n),{recursive:!0}),s.writeFile(n,o,(n=>{if(n)return console.error(n)}))},w=(n,o)=>{if(s.mkdirSync(e.dirname(o),{recursive:!0}),!s.existsSync(n))return void console.log(`Source path ${n} does not exist.`);s.existsSync(o)||s.mkdirSync(o);s.readdirSync(n).forEach((i=>{const t=e.join(n,i),r=e.join(o,i);s.lstatSync(t).isDirectory()?w(t,r):s.copyFileSync(t,r)}))};const v=t(import.meta.url),b=e.dirname(v),k={js:"test_sapdon",ts:"ts_sapdon"};const P=n=>{const o=e.join(n,"package.json");if(!s.existsSync(o))return null;try{const i=JSON.parse(s.readFileSync(o,"utf-8"));return{name:e.basename(n),description:i.description||"A new sapdon project",author:i.author||"Sapdon",version:i.version||"1.0.0"}}catch(n){return console.error("读取package.json文件时出错:",n),null}};var N;!function(n){n.WRITE_ADDON="write-addon",n.WRITE_GAME_DEV="write-dev"}(N||(N={}));const{port:O}={port:49037};async function D(n,...o){try{await fetch(`http://localhost:${O}/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})}catch(n){console.error(n),console.error("尝试在构建脚本中使用 server.startDevServer() 启动开发服务器")}}const J=async(n,o,e)=>{!async function(n,o,e){await D(N.WRITE_ADDON,n,o,e)}(n,o,e)};class M{constructor(n,o,e,i,t={}){this.name=n,this.description=o,this.version=e,this.uuid=i,this.allow_random_seed=t.allow_random_seed,this.lock_template_options=t.lock_template_options,this.pack_scope=t.pack_scope,this.base_game_version=t.base_game_version,this.min_engine_version=t.min_engine_version}}class E{constructor(n,o,e,i){this.description=n,this.type=o,this.uuid=e,this.version=i}}class x{constructor(n,o,e,i,t){this.authors=n,this.license=o,this.generated_with=e,this.product_type=i,this.url=t}}class F{constructor(n,o,e,i,t=null,s=null){this.format_version=n,this.header=o,this.modules=e,this.dependencies=i,null!=t&&(this.capabilities=t),null!=s&&(this.metadata=s)}}async function L(n){const o=e.join(n,"node_modules"),i=e.join(function(n){const o=c(n.url);return e.dirname(o)}(import.meta),"../"),t=e.join(i,"core"),r=e.join(i,"cli"),a=e.join(i,"oc"),p=e.join(o,"@sapdon/core"),l=e.join(o,"@sapdon/cli"),m=e.join(o,"@sapdon/oc");s.cpSync(t,p,{recursive:!0,force:!0}),s.cpSync(r,l,{recursive:!0,force:!0}),s.cpSync(a,m,{recursive:!0,force:!0}),s.writeFileSync(e.join(p,"package.json"),JSON.stringify({name:"@sapdon/core",main:"index.js",version:"1.0.0"})),s.writeFileSync(e.join(l,"package.json"),JSON.stringify({name:"@sapdon/cli",main:"index.js",version:"1.0.0"})),s.writeFileSync(e.join(m,"package.json"),JSON.stringify({name:"@sapdon/oc",main:"index.js",version:"1.0.0"}))}g.debounce;const R=t(import.meta.url),A=e.dirname(R),U=["rollup","typescript","@sapdon/core","@sapdon/cli","@minecraft"],I={__projectPath:e.join(A,"../../"),js:(n,o)=>{w(n,o)},ts:async(n,o,i="index.js",t="index.ts")=>{const r=e.join(I.__projectPath,".tmp",`sapdon-${crypto.randomUUID()}.js`);try{const c=await p({input:e.join(n,t),plugins:[u(),m({preferBuiltins:!0}),d({tsconfig:e.join(I.__projectPath,"tsconfig.json")}),l(),f()],external(n){for(const o of U)if(n.includes(o))return!0;return!1}});await c.write({file:r,format:"esm"}),c.close(),s.cpSync(r,e.join(o,i))}catch(n){console.error(n)}finally{s.rmSync(r,{recursive:!0,force:!0})}}};async function T(n,o,i){const t=e.join(n,i.path),s=i.type||"js";I.__projectPath=n,I[s](t,o)}async function W(n){const{promise:o,resolve:e}=Promise.withResolvers(),i=a.fork(n,{stdio:"inherit"});i.once("message",(n=>{"initialized"!==n&&i.kill(),e()})),await o}async function C(n){if(n.endsWith(".ts")){const i=crypto.randomUUID()+".js",t=e.dirname(n),r=n.replace(t,""),c=e.join(t,i);await I.ts(t,t,i,r),o=c,s.appendFileSync(o,"\n ;(async () => {\n const { startDevServer } = await import('@sapdon/cli')\n const { GRegistry, UISystemRegistry } = await import('@sapdon/core')\n startDevServer(GRegistry, UISystemRegistry)\n })();\n ");try{await W(c)}finally{s.rmSync(c,{force:!0})}}else{var o;await W(n)}}function B(n,o){return console.log("开始构建项目"),console.log("项目路径:"+n),h(n)?(console.log("项目不存在"),!1):!h(e.join(n,"build.config"))||(console.log("项目没有build.config文件"),!1)}const $=async(n,o)=>{const i=e.join(n,"build.config"),t=JSON.parse(S(i)),s=e.join(n,"mod.info"),r=JSON.parse(S(s)),c=G(r.min_engine_version),a=e.join(n,t.defaultConfig.buildDir),p=e.join(a,`${o}_BP/`),l=e.join(a,`${o}_RP/`),m=e.join(p,"manifest.json");if(h(m)){const n=V(r.name,r.description,r.version,{min_engine_version:c},t.defaultConfig.dependencies,t.defaultConfig.scriptEntry),o=z(r.name,r.description,r.version,{min_engine_version:c},[]);_(e.join(p,"manifest.json"),n),_(e.join(l,"manifest.json"),o)}const d=e.join(n,"pack_icon.png");y(d,e.join(p,"pack_icon.png")),y(d,e.join(l,"pack_icon.png"));t.resources.forEach((o=>{const i=e.join(n,o.path);w(i,l)}));const u=t.scripts,f=e.join(p,"scripts/");for(const o of u)await T(n,f,o);const g=e.join(n,t.defaultConfig.buildEntry);await C(g),"development"===t.defaultConfig.buildMode&&await J(g,a,o),async function(n,o){await D(N.WRITE_GAME_DEV,n,o)}(n,o),t.useHMR};function G(n){return n.split(".").map((n=>Number(n)))}const V=(n,o,e,i={},t=[],s)=>{console.log("开始生成behavior_packs/manifest.json"),console.log("Entry:",s);const r=new M(n+"_BP",o,G(e),j(),i),c=new E("行为模块","data",j(),G(e)),a=new E("脚本模块","script",j(),G(e));s&&(a.entry=s);const p=new x(["@sapdon"],"MIT",{sapdon:["1.0.0"]},"addon","https://github.com/junjun260/sapdon"),l=new F(2,r,[c,a],t,null,p);return JSON.stringify(l,null,2)},z=(n,o,e,i={},t=[])=>{const s=new M(n+"_RP",o,G(e),j(),i),r=new E("资源模块","resources",j(),G(e)),c=new x(["@sapdon"],"MIT",{sapdon:["1.0.0"]},"addon","https://github.com/junjun260/sapdon"),a=new F(2,s,[r],[],null,c);return JSON.stringify(a,null,2)},q=t(import.meta.url),H=e.dirname(q);process.removeAllListeners("warning"),n.command("init").description("初始化一个基于NodeJS的项目").action((()=>{const n=process.cwd(),i=e.join(n,"package.json");let t;if(s.existsSync(i)){try{t=JSON.parse(s.readFileSync(i,"utf-8"))}catch(n){return console.error("读取package.json文件时出错:",n),void console.log("请使改用create命令进行创建。")}t.scripts={...t.scripts,init:"sapdon init",pack:"sapdon pack",config:"sapdon config"};try{s.writeFileSync(i,JSON.stringify(t,null,2),"utf-8")}catch(n){return void console.error("写入package.json文件时出错:",n)}o.prompt([{type:"input",name:"min_engine_version",message:"最低引擎版本:",default:"1.19.50"}]).then((o=>{((n,o)=>{if(!(h(e.join(n,"mod.info"))&&h(e.join(n,"main.mjs"))&&h(e.join(n,"scripts"))&&h(e.join(n,"build.config"))))return void console.log("项目已存在...");const i=e.join(b,"../templates/test_sapdon");w(i,n),_(e.join(n,"mod.info"),JSON.stringify(o,null,2))})(n,{...P(n),...o}),console.log("请使用命令sapdon config配置框架的build.config文件。")}))}else console.error("没有找到package.json文件,请使改用create命令进行创建。")})),n.command("create <project-name>").description("Create a new project").action((n=>{o.prompt([{type:"input",name:"name",message:"Project Name:",default:e.basename(n)},{type:"input",name:"description",message:"Project Description:",default:"A new sapdon project"},{type:"input",name:"author",message:"Author Name:",default:"Sapdon"},{type:"input",name:"version",message:"Project Version:",default:"1.0.0"},{type:"input",name:"min_engine_version",message:"Minimum Engine Version:",default:"1.19.50"},{type:"input",name:"language",message:"Language:(js/ts)",default:"ts"}]).then((o=>{const t=e.join(process.cwd(),n);console.log("项目路径:",t),((n,o)=>{if(console.log(1,o),!h(n))return void console.log("项目名称已存在,创建项目目录失败");const i=e.join(b,`../../src/templates/${k[o.language||"js"]}`);w(i,n),_(e.join(n,"mod.info"),JSON.stringify(o,null,2)),a.execSync("npm i",{cwd:n,stdio:"inherit"})})(t,o),function(n){const o=e.join(i.homedir(),"AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/"),t=e.join(i.homedir(),"AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/"),r=e.join(n,"./build.config"),c=JSON.parse(s.readFileSync(r));c.mojangPath=o,c.betaPath=t,_(r,JSON.stringify(c,null,2))}(t),L(t)}))})),n.command("build <project-name>").description("Build the project").action((n=>{console.log("Building the project...");const o=e.join(process.cwd(),n);B(o)&&$(o,e.basename(o))})),n.command("pack").description("Pack the current project").action((()=>{console.log("Packing the current project...");const n=process.cwd();B(n)&&$(n,e.basename(n))})),n.command("lib").description("Generate lib files for development server.").action((()=>{L(process.cwd())})),n.command("config").description("Configure build.config file").action((()=>{const n=e.join(H,"./build.config");let t;try{t=JSON.parse(S(n))}catch(n){return void console.error("读取build.config文件时出错:",n)}o.prompt([{type:"input",name:"mojangPath",message:"Mojang Path (must end with LocalState/games/com.mojang/):",default:e.join(i.homedir(),"AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/")},{type:"input",name:"mojangBetaPath",message:"Mojang Beta Path (must end with LocalState/games/com.mojang/):",default:e.join(i.homedir(),"AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/")}]).then((o=>{try{s.writeFileSync(n,JSON.stringify({...t,...o},null,2),"utf-8"),console.log("build.config文件已更新。")}catch(n){console.error("写入build.config文件时出错:",n)}}))})),n.parse(n.argv);
|
package/dist/cli/utils.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export function dirname(importMeta: any): string;
|
|
|
8
8
|
export function asyncImport(path: any): Promise<any>;
|
|
9
9
|
export function generateUUID(): `${string}-${string}-${string}-${string}-${string}`;
|
|
10
10
|
export function pathNotExist(filePath: any): boolean;
|
|
11
|
-
export function readFile(filePath: any): string;
|
|
11
|
+
export function readFile(filePath: any): string | null;
|
|
12
12
|
export function saveFile(filePath: string, data: string): void;
|
|
13
13
|
export function copyFolder(sourcePath: any, destinationPath: any): void;
|
|
@@ -19,9 +19,9 @@ export class AddonBlockDefinition {
|
|
|
19
19
|
* @param {Object} components 方块组件
|
|
20
20
|
* @param {Array} permutations 方块变体
|
|
21
21
|
*/
|
|
22
|
-
constructor(description: AddonBlockDescription, components:
|
|
22
|
+
constructor(description: AddonBlockDescription, components: Object, permutations?: any[]);
|
|
23
23
|
description: AddonBlockDescription;
|
|
24
|
-
components:
|
|
24
|
+
components: Object;
|
|
25
25
|
permutations: any[];
|
|
26
26
|
}
|
|
27
27
|
export class AddonBlockDescription {
|
|
@@ -11,7 +11,7 @@ export class AddonClientEntity {
|
|
|
11
11
|
* 将对象转换为 JSON 格式
|
|
12
12
|
* @returns {Object} JSON 对象
|
|
13
13
|
*/
|
|
14
|
-
toJson():
|
|
14
|
+
toJson(): Object;
|
|
15
15
|
}
|
|
16
16
|
export class AddonClientEntityDefinition {
|
|
17
17
|
/**
|
|
@@ -37,7 +37,7 @@ export class AddonClientEntityDescription {
|
|
|
37
37
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
38
38
|
*/
|
|
39
39
|
addMaterial(name: string, material: string): AddonClientEntityDescription;
|
|
40
|
-
materials: {};
|
|
40
|
+
materials: {} | undefined;
|
|
41
41
|
/**
|
|
42
42
|
* 添加纹理
|
|
43
43
|
* @param {string} name 纹理名称
|
|
@@ -45,7 +45,7 @@ export class AddonClientEntityDescription {
|
|
|
45
45
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
46
46
|
*/
|
|
47
47
|
addTexture(name: string, texture: string): AddonClientEntityDescription;
|
|
48
|
-
textures: {};
|
|
48
|
+
textures: {} | undefined;
|
|
49
49
|
/**
|
|
50
50
|
* 添加几何体
|
|
51
51
|
* @param {string} name 几何体名称
|
|
@@ -53,7 +53,7 @@ export class AddonClientEntityDescription {
|
|
|
53
53
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
54
54
|
*/
|
|
55
55
|
addGeometry(name: string, geometry: string): AddonClientEntityDescription;
|
|
56
|
-
geometry: {};
|
|
56
|
+
geometry: {} | undefined;
|
|
57
57
|
/**
|
|
58
58
|
* 添加动画
|
|
59
59
|
* @param {string} name 动画名称
|
|
@@ -61,7 +61,7 @@ export class AddonClientEntityDescription {
|
|
|
61
61
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
62
62
|
*/
|
|
63
63
|
addAnimation(name: string, animation: string): AddonClientEntityDescription;
|
|
64
|
-
animations: {};
|
|
64
|
+
animations: {} | undefined;
|
|
65
65
|
/**
|
|
66
66
|
* 添加动画控制器
|
|
67
67
|
* @param {string} name 控制器名称
|
|
@@ -69,22 +69,22 @@ export class AddonClientEntityDescription {
|
|
|
69
69
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
70
70
|
*/
|
|
71
71
|
addAnimationController(name: string, controller: string): AddonClientEntityDescription;
|
|
72
|
-
animation_controllers: any[];
|
|
72
|
+
animation_controllers: any[] | undefined;
|
|
73
73
|
/**
|
|
74
74
|
* 添加渲染控制器
|
|
75
75
|
* @param {string} controller 渲染控制器路径
|
|
76
76
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
77
77
|
*/
|
|
78
78
|
addRenderController(controller: string): AddonClientEntityDescription;
|
|
79
|
-
render_controllers: any[];
|
|
79
|
+
render_controllers: any[] | undefined;
|
|
80
80
|
/**
|
|
81
81
|
* 添加定位器
|
|
82
82
|
* @param {string} name 定位器名称
|
|
83
83
|
* @param {Object} locator 定位器数据
|
|
84
84
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
85
85
|
*/
|
|
86
|
-
addLocator(name: string, locator:
|
|
87
|
-
locators: {};
|
|
86
|
+
addLocator(name: string, locator: Object): AddonClientEntityDescription;
|
|
87
|
+
locators: {} | undefined;
|
|
88
88
|
/**
|
|
89
89
|
* 设置生成蛋
|
|
90
90
|
* @param {string} texture 生成蛋纹理
|
|
@@ -95,7 +95,7 @@ export class AddonClientEntityDescription {
|
|
|
95
95
|
spawn_egg: {
|
|
96
96
|
texture: string;
|
|
97
97
|
texture_index: number;
|
|
98
|
-
};
|
|
98
|
+
} | undefined;
|
|
99
99
|
/**
|
|
100
100
|
* 设置脚本
|
|
101
101
|
* @param {string} key 脚本键
|
|
@@ -103,5 +103,5 @@ export class AddonClientEntityDescription {
|
|
|
103
103
|
* @returns {AddonClientEntityDescription} 返回当前实例以支持链式调用
|
|
104
104
|
*/
|
|
105
105
|
setScript(key: string, value: string): AddonClientEntityDescription;
|
|
106
|
-
scripts: {};
|
|
106
|
+
scripts: {} | undefined;
|
|
107
107
|
}
|
|
@@ -11,7 +11,7 @@ export class AddonEntity {
|
|
|
11
11
|
* 将对象转换为 JSON 格式
|
|
12
12
|
* @returns {Object} JSON 对象
|
|
13
13
|
*/
|
|
14
|
-
toJson():
|
|
14
|
+
toJson(): Object;
|
|
15
15
|
}
|
|
16
16
|
export class AddonEntityDefinition {
|
|
17
17
|
/**
|
|
@@ -19,9 +19,9 @@ export class AddonEntityDefinition {
|
|
|
19
19
|
* @param {AddonEntityDescription} description 实体描述
|
|
20
20
|
* @param {Object} components 实体组件
|
|
21
21
|
*/
|
|
22
|
-
constructor(description: AddonEntityDescription, components?:
|
|
22
|
+
constructor(description: AddonEntityDescription, components?: Object, component_groups?: {}, events?: {});
|
|
23
23
|
description: AddonEntityDescription;
|
|
24
|
-
components:
|
|
24
|
+
components: Object;
|
|
25
25
|
component_groups: {};
|
|
26
26
|
events: {};
|
|
27
27
|
}
|
|
@@ -33,7 +33,7 @@ export class AddonEntityDescription {
|
|
|
33
33
|
* @param {boolean} is_summonable 是否可召唤
|
|
34
34
|
* @param {string} runtime_identifier 复刻标识符
|
|
35
35
|
*/
|
|
36
|
-
constructor(identifier: string, is_spawnable: boolean, is_summonable: boolean, properties: {}, runtime_identifier: string);
|
|
36
|
+
constructor(identifier: string, is_spawnable: boolean | undefined, is_summonable: boolean | undefined, properties: {} | undefined, runtime_identifier: string);
|
|
37
37
|
identifier: string;
|
|
38
38
|
is_spawnable: boolean;
|
|
39
39
|
is_summonable: boolean;
|