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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import * as _minecraft_server from '@minecraft/server';
|
|
2
|
+
import { Entity, Player, InputButton } from '@minecraft/server';
|
|
3
|
+
|
|
4
|
+
declare class Optional<T = any> {
|
|
5
|
+
private value;
|
|
6
|
+
static none<T>(): Optional<T>;
|
|
7
|
+
static some<T>(value: T): Optional<T>;
|
|
8
|
+
constructor(value: T);
|
|
9
|
+
unwrap(): T;
|
|
10
|
+
isEmpty(): boolean;
|
|
11
|
+
orElse(other: T): T;
|
|
12
|
+
use(fn: (v: T) => void, self?: any): boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Component {
|
|
16
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
17
|
+
detach(manager: ComponentManager): void;
|
|
18
|
+
getManager(): ComponentManager;
|
|
19
|
+
getEntity(): Optional<Entity>;
|
|
20
|
+
}
|
|
21
|
+
interface BasicComponent extends Component {
|
|
22
|
+
onAttach(manager: ComponentManager): boolean | void | Promise<boolean | void>;
|
|
23
|
+
onDetach(manager: ComponentManager): void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
declare const REFLECT_MANAGER: unique symbol;
|
|
26
|
+
declare const REFLECT_ENTITY: unique symbol;
|
|
27
|
+
declare class CustomComponent implements Component {
|
|
28
|
+
[REFLECT_MANAGER]?: ComponentManager;
|
|
29
|
+
[REFLECT_ENTITY]: Optional<Entity>;
|
|
30
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
31
|
+
detach(manager: ComponentManager): Promise<boolean>;
|
|
32
|
+
getManager(): ComponentManager;
|
|
33
|
+
getEntity(): Optional<Entity>;
|
|
34
|
+
}
|
|
35
|
+
declare class BaseComponent extends CustomComponent implements BasicComponent {
|
|
36
|
+
onAttach(manager: ComponentManager): boolean | void | Promise<boolean | void>;
|
|
37
|
+
onDetach(manager: ComponentManager): void | Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
interface ComponentCtor<T extends Component | BasicComponent = Component> {
|
|
40
|
+
new (...args: any[]): T;
|
|
41
|
+
}
|
|
42
|
+
declare class ComponentManager {
|
|
43
|
+
#private;
|
|
44
|
+
static profilerEnable: boolean;
|
|
45
|
+
static readonly global: ComponentManager;
|
|
46
|
+
getComponentUnsafe(ctor: ComponentCtor): Component | undefined;
|
|
47
|
+
getComponent<T extends Component>(ctor: ComponentCtor<T>): Optional<T>;
|
|
48
|
+
getComponents(...ctor: ComponentCtor[]): (Component | undefined)[];
|
|
49
|
+
attachComponent(...component: Component[]): Promise<Optional<Component>[]>;
|
|
50
|
+
getOrCreate<T extends Component>(ctor: ComponentCtor<T>, ...args: any[]): Promise<Optional<T>>;
|
|
51
|
+
detachComponent(ctor: ComponentCtor): Promise<boolean>;
|
|
52
|
+
clear(): void;
|
|
53
|
+
getComponentKeys(): MapIterator<ComponentCtor<Component>>;
|
|
54
|
+
has(ctor: ComponentCtor): boolean;
|
|
55
|
+
afterTick(fn: (en: Optional<Entity>) => void): void;
|
|
56
|
+
beforeTick(fn: (en: Optional<Entity>) => void): void;
|
|
57
|
+
handleTicks(en: Entity): void;
|
|
58
|
+
update<T extends Component>(ctor: ComponentCtor<T>, fn: (component: T) => void): boolean;
|
|
59
|
+
profiler(fn: Function, component?: Component, name?: string): any;
|
|
60
|
+
}
|
|
61
|
+
type RequireComponentsParam = ComponentCtor | [ComponentCtor, ...any[]];
|
|
62
|
+
declare const REQUIRED_COMPONENTS: unique symbol;
|
|
63
|
+
interface RequiredComponent extends BasicComponent {
|
|
64
|
+
getComponent<T extends Component>(ctor: ComponentCtor): T;
|
|
65
|
+
}
|
|
66
|
+
declare function RequireComponents(...params: RequireComponentsParam[]): {
|
|
67
|
+
new (): {
|
|
68
|
+
getComponent<T extends Component>(ctor: ComponentCtor): T;
|
|
69
|
+
[REQUIRED_COMPONENTS]: Map<ComponentCtor<Component>, Component>;
|
|
70
|
+
onAttach(manager: ComponentManager): boolean | void | Promise<boolean | void>;
|
|
71
|
+
onDetach(manager: ComponentManager): void | Promise<void>;
|
|
72
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
73
|
+
detach(manager: ComponentManager): Promise<boolean>;
|
|
74
|
+
getManager(): ComponentManager;
|
|
75
|
+
getEntity(): Optional<Entity>;
|
|
76
|
+
[REFLECT_MANAGER]?: ComponentManager;
|
|
77
|
+
[REFLECT_ENTITY]: Optional<Entity>;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
declare namespace oc {
|
|
81
|
+
function addEntity(entityId: string): ComponentManager;
|
|
82
|
+
function removeEntity(entityId: string): void;
|
|
83
|
+
function getManager(entityId: string): ComponentManager;
|
|
84
|
+
function tick(): void;
|
|
85
|
+
function start(): void;
|
|
86
|
+
function toPlayer(entity: Entity): Optional<Player>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type ComponentDescriptor = string | ComponentCtor;
|
|
90
|
+
declare class Actor {
|
|
91
|
+
readonly target: Entity;
|
|
92
|
+
readonly manager: ComponentManager;
|
|
93
|
+
constructor(target: Entity, manager: ComponentManager);
|
|
94
|
+
static from(target: Entity, manager: ComponentManager): Actor;
|
|
95
|
+
/**
|
|
96
|
+
* 优先使用 `Actor.getComponent`
|
|
97
|
+
* @param ctors
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
getMinecraftComponent(...ids: string[]): (_minecraft_server.EntityComponent | undefined)[];
|
|
101
|
+
/**
|
|
102
|
+
* 优先使用 `Actor.getComponent`
|
|
103
|
+
* @param ctors
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
getCustomComponent(...ctors: ComponentCtor[]): (Component | undefined)[];
|
|
107
|
+
getComponent<T extends readonly ComponentDescriptor[] | []>(...descs: T): {
|
|
108
|
+
-readonly [K in keyof T]: Component;
|
|
109
|
+
};
|
|
110
|
+
addComponent(...components: Component[]): Promise<Optional<Component>[]>;
|
|
111
|
+
removeComponent(ctor: ComponentCtor): Promise<boolean>;
|
|
112
|
+
updateComponent<T extends Component>(ctor: ComponentCtor<T>, fn: (component: T) => void): boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare enum InputChangeState {
|
|
116
|
+
Press = 0,
|
|
117
|
+
Release = 1,
|
|
118
|
+
None = 2
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* `@minecraft/server` version 2.0.0-beta
|
|
122
|
+
* 低于此版本请不要使用此组件
|
|
123
|
+
*/
|
|
124
|
+
declare class PlayerInputComponent extends BaseComponent {
|
|
125
|
+
[InputButton.Jump]: InputChangeState;
|
|
126
|
+
[InputButton.Sneak]: InputChangeState;
|
|
127
|
+
static setup(): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* `@minecraft/server` version 1.17.0-beta
|
|
131
|
+
* 有 1tick 延迟
|
|
132
|
+
* 条件允许请使用 `PlayerInputComponent`
|
|
133
|
+
*/
|
|
134
|
+
declare class PlayerInputCompatibilityComponent extends BaseComponent {
|
|
135
|
+
[InputButton.Jump]: InputChangeState;
|
|
136
|
+
[InputButton.Sneak]: InputChangeState;
|
|
137
|
+
private _lastJump;
|
|
138
|
+
private _lastSneak;
|
|
139
|
+
onTick(manager: ComponentManager, en: Optional<Entity>): void;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { Actor, BaseComponent, type BasicComponent, type Component, type ComponentCtor, type ComponentDescriptor, ComponentManager, CustomComponent, InputChangeState, Optional, PlayerInputCompatibilityComponent, PlayerInputComponent, RequireComponents, type RequiredComponent, oc };
|
package/dist/oc/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{world as t,system as e,InputButton as n,ButtonState as s}from"@minecraft/server";class o{target;manager;constructor(t,e){this.target=t,this.manager=e}static from(t,e){return new o(t,e)}getMinecraftComponent(...t){return t.map((t=>this.target.getComponent(t)))}getCustomComponent(...t){return this.manager.getComponents(...t)}getComponent(...t){return t.map((t=>"string"==typeof t?this.target.getComponent(t):this.manager.getComponentUnsafe(t)))}addComponent(...t){return this.manager.attachComponent(...t)}removeComponent(t){return this.manager.detachComponent(t)}updateComponent(t,e){return this.manager.update(t,e)}}class r{value;static none(){return new r(null)}static some(t){return new r(t)}constructor(t){this.value=t}unwrap(){if(!this.isEmpty())return this.value;throw new Error("Optional is empty")}isEmpty(){return void 0===this.value||null===this.value}orElse(t){return this.value??t}use(t,e){return!this.isEmpty()&&(t.call(e,this.value),!0)}}const a=Symbol("reflect-manager"),i=Symbol("reflect-entity");class c{[a];[i]=r.none();onTick(t,e){}detach(t){const e=Object.getPrototypeOf(this).constructor;return t.detachComponent(e)}getManager(){return this[a]}getEntity(){return this[i]}}class p extends c{onAttach(t){}onDetach(t){}}class u{static profilerEnable=!1;static global=new u;#t=new Map;#e=[];#n=[];getComponentUnsafe(t){return this.#t.get(t)}getComponent(t){return r.some(this.#t.get(t))}getComponents(...t){return t.map((t=>this.#t.get(t)))}async#s(t,e,n=!0){let s=!this.#t.get(t);if(!s&&n&&(await this.detachComponent(t),s=!0),l in e)for(const[t,n]of e[l])this.#s(t,n,!1);return s&&"onAttach"in e&&await e.onAttach(this),this.#t.set(t,e),r.some(e)}async attachComponent(...t){const e=[];for(const n of t)e.push(await this.#s(Object.getPrototypeOf(n).constructor,n));return e}async getOrCreate(t,...e){let n=this.#t.get(t);return n?r.some(n):this.#s(t,new t(...e))}async detachComponent(t){const e=this.#t.get(t);return e&&"onDetach"in e&&await e.onDetach(this),this.#t.delete(t)}clear(){this.#t.clear()}getComponentKeys(){return this.#t.keys()}has(t){return this.#t.has(t)}afterTick(t){this.#n.push(t)}beforeTick(t){this.#e.unshift(t)}handleTicks(t){for(const e of this.#e)this.profiler((()=>e.call(null,r.some(t))));this.#e.length=0;for(const e of this.#t.values()){e[i]||(e[i]=r.some(t)),e[a]||(e[a]=this);const{onTick:n}=e;n&&this.profiler((()=>n.call(e,this,r.some(t))),e)}for(const e of this.#n)this.profiler((()=>e.call(null,r.some(t))));this.#n.length=0}update(t,e){const n=this.#t.get(t);return!!n&&(e(n),!0)}profiler(t,e,n){if(!u.profilerEnable)return t();const s=e?Object.getPrototypeOf(e).constructor.name:"",o=n||(s?`${s}.${t.name}`:t.name),r=performance.now(),a=t();return console.log(`[Profiler] ${o} took ${performance.now()-r}ms`),a}}const l=Symbol("REQUIRED_COMPONENTS");function h(...t){return class extends p{[l]=new Map;constructor(){super();for(const e of t)if(Array.isArray(e)){const[t,...n]=e;this[l].set(t,Reflect.construct(t,n))}else this[l].set(e,Reflect.construct(e,[]))}getComponent(t){return this[l].get(t)}}}var m,f;!function(n){const s=new Map;function o(t){const e=new u;return s.set(t,e),e}function a(){for(const[e,n]of s.entries()){const s=t.getEntity(e);s&&n.handleTicks(s)}}n.addEntity=o,n.removeEntity=function(t){const e=t,n=s.get(e);n?.clear(),s.delete(e)},n.getManager=function(t){return s.get(t)??o(t)},n.tick=a,n.start=function(){e.runInterval(a)},n.toPlayer=function(e){return r.some(t.getAllPlayers().find((t=>t.id===e.id)))}}(m||(m={})),function(t){t[t.Press=0]="Press",t[t.Release=1]="Release",t[t.None=2]="None"}(f||(f={}));class g extends p{[n.Jump]=f.None;[n.Sneak]=f.None;static setup(){t.afterEvents.playerButtonInput.subscribe((t=>{const e=m.getManager(t.player.id);e.getComponent(g).use((n=>{n[t.button]=t.newButtonState===s.Pressed?f.Press:f.Release,e.afterTick((()=>{n[t.button]=f.None}))}))}))}}class d extends p{[n.Jump]=f.None;[n.Sneak]=f.None;_lastJump=s.Released;_lastSneak=s.Released;onTick(t,e){const o=m.toPlayer(e.unwrap()).unwrap(),r=o.inputInfo.getButtonState(n.Jump),a=o.inputInfo.getButtonState(n.Sneak);r===s.Pressed&&this._lastJump===s.Released?this[n.Jump]=f.Press:r===s.Released&&this._lastJump===s.Pressed?this[n.Jump]=f.Release:this[n.Jump]=f.None,a===s.Pressed&&this._lastSneak===s.Released?this[n.Sneak]=f.Press:a===s.Released&&this._lastSneak===s.Pressed?this[n.Sneak]=f.Release:this[n.Sneak]=f.None,this._lastJump=r,this._lastSneak=a}}export{o as Actor,p as BaseComponent,u as ComponentManager,c as CustomComponent,f as InputChangeState,r as Optional,d as PlayerInputCompatibilityComponent,g as PlayerInputComponent,h as RequireComponents,m as oc};
|
package/doc/cli.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# `@sapdon/cli` 包
|
|
2
|
+
|
|
3
|
+
## 自定义处理器
|
|
4
|
+
```ts
|
|
5
|
+
import { devServer } from '@sapdon/cli'
|
|
6
|
+
devServer.handle('ping', () => {
|
|
7
|
+
console.log('pong')
|
|
8
|
+
})
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 拦截cli处理器
|
|
12
|
+
```ts
|
|
13
|
+
import { devServer, ServerHandles } from '@sapdon/cli'
|
|
14
|
+
|
|
15
|
+
devServer.interceptHandler(ServerHandles.WRITE_ADDON, handler => {
|
|
16
|
+
return (...args: any[]) => {
|
|
17
|
+
const now = peformance.now()
|
|
18
|
+
handler.apply(args)
|
|
19
|
+
const dt = peformance.now() - now
|
|
20
|
+
console.log(`执行耗时 ${dt}ms.`)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
package/doc/sapdon-ts.md
CHANGED
|
@@ -1,16 +1,62 @@
|
|
|
1
1
|
# sapdon with typescript
|
|
2
2
|
在使用脚手架创建项目时,默认使用的语言将会是 `ts`
|
|
3
3
|
|
|
4
|
-
但这并不意味着你需要手动去调整 tsconfig 和打包工具,我们提供了一套默认能用的ts
|
|
4
|
+
但这并不意味着你需要手动去调整 tsconfig 和打包工具,我们提供了一套默认能用的ts设置
|
|
5
5
|
|
|
6
6
|
## 和 js 版本相比有什么区别?
|
|
7
|
-
ts
|
|
7
|
+
ts版本拥有更好的类型提示,更严格的类型检查,也可以直接使用node_modules里的库(只能是js/ts)
|
|
8
8
|
|
|
9
9
|
## 听起来太酷了我们开始吧!
|
|
10
|
-
比如我们需要注册一个物品,可能你会想去找它在哪,但在ts版本中,你只需要 `@core` 就可以了
|
|
10
|
+
比如我们需要注册一个物品,可能你会想去找它在哪,但在ts版本中,你只需要 `@sapdon/core` 就可以了
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import { ItemAPI } from '@core
|
|
13
|
+
import { ItemAPI } from '@sapdon/core'
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
如果你需要更高级的功能,比如你需要一个ts打包器,或者添加命令行的功能,你可以使用 `@cli`
|
|
16
|
+
如果你需要更高级的功能,比如你需要一个ts打包器,或者添加命令行的功能,你可以使用 `@sapdon/cli`
|
|
17
|
+
|
|
18
|
+
## 从js迁移到ts
|
|
19
|
+
js 的 `main.mjs` 包含了一些预定义的代码:
|
|
20
|
+
```js
|
|
21
|
+
import { startDevServer } from '@sapdon/cli'
|
|
22
|
+
import { GRegistry, UISystemRegistry } from '@sapdon/core'
|
|
23
|
+
|
|
24
|
+
// 开启开发服务器, 不开启开发服务器无法使用文件同步和热更新
|
|
25
|
+
startDevServer(GRegistry, UISystemRegistry)
|
|
26
|
+
```
|
|
27
|
+
如果需要从js迁移到ts,删除 `startDevServer` 那行即可(不删也没事)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## OC (Object - Component)
|
|
31
|
+
sapdon通过 `@sapdon/oc` 为sapi提供了一些高级功能, 比如:
|
|
32
|
+
- 实体组件系统
|
|
33
|
+
- 组件间通信
|
|
34
|
+
|
|
35
|
+
传统的书写方式是通过事件和tick回调来实现功能, 而OC提供了更适合游戏的组件化开发方式
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { world, system } from '@minecraft/server'
|
|
39
|
+
import { oc, CustomComponent } from '@sapdon/oc'
|
|
40
|
+
|
|
41
|
+
world.afterEvents.worldInitialize.subscribe(oc.start)
|
|
42
|
+
|
|
43
|
+
class MyComponent extends CustomComponent {
|
|
44
|
+
onTick() {
|
|
45
|
+
world.sendMessage('tick')
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
是的, 我们得到了一个MyComponent, 它每刻都会给玩家发送 'tick'
|
|
51
|
+
但是如果你进入游戏, 会发现它毫无作用, 没错! 因为我们还没有把它到绑定在实体身上!
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
const manager = oc.addEntity(id)
|
|
55
|
+
manager.attachComponent(new MyComponent())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
这样就可以了, 我们已经把MyComponent绑定到了entityId为id的实体身上
|
|
59
|
+
|
|
60
|
+
你也可以动态增删改查组件! 这很方便!
|
|
61
|
+
|
|
62
|
+
如果你想看它到底是怎么回事,可以从 `examples/oc-core` 开始了解
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sapdon",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"main": "dist/core/index.js",
|
|
5
|
-
"types": "dist/core/index.d.ts",
|
|
3
|
+
"version": "3.0.3",
|
|
6
4
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"build": "node dist/cli/index.js build",
|
|
10
|
-
"dist": "tsc"
|
|
5
|
+
"build": "rollup -c",
|
|
6
|
+
"pub": "rollup -c && npm publish"
|
|
11
7
|
},
|
|
12
8
|
"keywords": [
|
|
13
9
|
"bedrock",
|
|
@@ -22,15 +18,17 @@
|
|
|
22
18
|
},
|
|
23
19
|
"description": "Sapdon is a Node.js toolkit designed for building Bedrock Edition Minecraft addon packs.",
|
|
24
20
|
"devDependencies": {
|
|
25
|
-
"@minecraft/server": "^1.
|
|
21
|
+
"@minecraft/server": "^2.0.0-beta.1.21.80-preview.20",
|
|
26
22
|
"@minecraft/server-ui": "^1.3.0",
|
|
27
23
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
28
24
|
"@rollup/plugin-json": "^6.1.0",
|
|
29
25
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
26
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
30
27
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
31
28
|
"@types/lodash": "^4.17.16",
|
|
32
29
|
"@types/node": "^22.13.8",
|
|
33
30
|
"rollup": "^4.30.1",
|
|
31
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
34
32
|
"rollup-plugin-typescript-paths": "^1.5.0",
|
|
35
33
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
36
34
|
"rollup-plugin-visualizer": "^5.14.0",
|