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.
- package/README.md +3 -2
- package/dist/cli/build.d.ts +7 -0
- package/dist/cli/build.js +236 -0
- package/dist/cli/dev-server/client.d.ts +2 -0
- package/dist/cli/dev-server/client.js +21 -0
- package/dist/cli/dev-server/config.d.ts +3 -0
- package/dist/cli/dev-server/config.js +3 -0
- package/dist/cli/dev-server/handles.d.ts +4 -0
- package/dist/cli/dev-server/handles.js +5 -0
- package/dist/cli/dev-server/hmr.d.ts +1 -0
- package/dist/cli/dev-server/hmr.js +13 -0
- package/dist/cli/dev-server/index.d.ts +4 -0
- package/dist/cli/dev-server/index.js +17 -0
- package/dist/cli/dev-server/server.d.ts +14 -0
- package/dist/cli/dev-server/server.js +59 -0
- package/dist/cli/dev-server/syncFiles.d.ts +3 -0
- package/dist/cli/dev-server/syncFiles.js +45 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +90 -0
- package/dist/cli/init.d.ts +9 -0
- package/dist/cli/init.js +80 -0
- package/dist/cli/load.d.ts +3 -0
- package/dist/cli/load.js +94 -0
- package/dist/cli/start.d.ts +2 -0
- package/dist/cli/start.js +1398 -0
- package/dist/cli/tools/textureSet.d.ts +13 -0
- package/dist/cli/tools/textureSet.js +103 -0
- package/dist/cli/utils.d.ts +13 -0
- package/dist/cli/utils.js +89 -0
- package/dist/core/addon/biome.d.ts +22 -0
- package/dist/core/addon/biome.js +27 -0
- package/dist/core/addon/block/block.d.ts +41 -0
- package/dist/core/addon/block/block.js +46 -0
- package/dist/core/addon/controllers/animationController.d.ts +43 -0
- package/dist/core/addon/controllers/animationController.js +73 -0
- package/dist/core/addon/controllers/render_controllers.js +162 -0
- package/dist/core/addon/entity/clientEntity.d.ts +107 -0
- package/dist/core/addon/entity/clientEntity.js +149 -0
- package/dist/core/addon/entity/entity.d.ts +42 -0
- package/dist/core/addon/entity/entity.js +50 -0
- package/dist/core/addon/feature/oreFeature.d.ts +19 -0
- package/dist/core/addon/feature/oreFeature.js +24 -0
- package/dist/core/addon/featureRule.d.ts +20 -0
- package/dist/core/addon/featureRule.js +25 -0
- package/dist/core/addon/item/attachable.d.ts +94 -0
- package/dist/core/addon/item/attachable.js +134 -0
- package/dist/core/addon/item/item.d.ts +19 -0
- package/dist/core/addon/item/item.js +26 -0
- package/dist/core/addon/manifest.d.ts +49 -0
- package/dist/core/addon/manifest.js +65 -0
- package/dist/core/addon/menuCategory.d.ts +6 -0
- package/dist/core/addon/menuCategory.js +7 -0
- package/dist/core/addon/recipe/baseRecipe.d.ts +12 -0
- package/dist/core/addon/recipe/baseRecipe.js +23 -0
- package/dist/core/addon/recipe/data.d.ts +66 -0
- package/dist/core/addon/recipe/data.js +74 -0
- package/dist/core/addon/recipe/furnace.d.ts +17 -0
- package/dist/core/addon/recipe/furnace.js +43 -0
- package/dist/core/addon/recipe/shaped.d.ts +26 -0
- package/dist/core/addon/recipe/shaped.js +53 -0
- package/dist/core/addon/recipe/shapeless.d.ts +18 -0
- package/dist/core/addon/recipe/shapeless.js +36 -0
- package/dist/core/biome/biome.d.ts +14 -0
- package/dist/core/biome/biome.js +23 -0
- package/dist/core/biome/biomeComponent.d.ts +46 -0
- package/dist/core/biome/biomeComponent.js +77 -0
- package/dist/core/block/basicBlock.d.ts +48 -0
- package/dist/core/block/basicBlock.js +105 -0
- package/dist/core/block/block.d.ts +32 -0
- package/dist/core/block/block.js +92 -0
- package/dist/core/block/blockComponent.d.ts +187 -0
- package/dist/core/block/blockComponent.js +500 -0
- package/dist/core/block/cropBlock.d.ts +4 -0
- package/dist/core/block/cropBlock.js +27 -0
- package/dist/core/block/geometryBlock.d.ts +12 -0
- package/dist/core/block/geometryBlock.js +16 -0
- package/dist/core/block/oreBlock.d.ts +9 -0
- package/dist/core/block/oreBlock.js +25 -0
- package/dist/core/block/rotatableBlock.d.ts +27 -0
- package/dist/core/block/rotatableBlock.js +107 -0
- package/dist/core/block/tileBlock.d.ts +17 -0
- package/dist/core/block/tileBlock.js +125 -0
- package/dist/core/entity/basicEntity.d.ts +111 -0
- package/dist/core/entity/basicEntity.js +170 -0
- package/dist/core/entity/behavior/followMob.d.ts +12 -0
- package/dist/core/entity/behavior/followMob.js +35 -0
- package/dist/core/entity/behavior/followParent.d.ts +7 -0
- package/dist/core/entity/behavior/followParent.js +15 -0
- package/dist/core/entity/behavior/randomStroll.d.ts +31 -0
- package/dist/core/entity/behavior/randomStroll.js +63 -0
- package/dist/core/entity/behavior/tempt.d.ts +73 -0
- package/dist/core/entity/behavior/tempt.js +134 -0
- package/dist/core/entity/bundles/BasicMoveBundle.js +8 -0
- package/dist/core/entity/bundles/basicBundle.d.ts +13 -0
- package/dist/core/entity/bundles/basicBundle.js +38 -0
- package/dist/core/entity/clientEntity.d.ts +20 -0
- package/dist/core/entity/clientEntity.js +37 -0
- package/dist/core/entity/componets/entityComponet.d.ts +202 -0
- package/dist/core/entity/componets/entityComponet.js +354 -0
- package/dist/core/entity/data/nativeEntityData.d.ts +9 -0
- package/dist/core/entity/data/nativeEntityData.js +38 -0
- package/dist/core/entity/dummyEntity.js +14 -0
- package/dist/core/entity/entity.d.ts +15 -0
- package/dist/core/entity/entity.js +11 -0
- package/dist/core/entity/nativeEntity.d.ts +8 -0
- package/dist/core/entity/nativeEntity.js +28 -0
- package/dist/core/entity/navigation/walk.d.ts +23 -0
- package/dist/core/entity/navigation/walk.js +56 -0
- package/dist/core/entity/projectile.d.ts +3 -0
- package/dist/core/entity/projectile.js +7 -0
- package/dist/core/factory/biomeFactory.d.ts +4 -0
- package/dist/core/factory/biomeFactory.js +13 -0
- package/dist/core/factory/blockFactory.d.ts +34 -0
- package/dist/core/factory/blockFactory.js +143 -0
- package/dist/core/factory/entityFactory.d.ts +17 -0
- package/dist/core/factory/entityFactory.js +75 -0
- package/dist/core/factory/featureFactory.d.ts +6 -0
- package/dist/core/factory/featureFactory.js +23 -0
- package/dist/core/factory/itemExtra.d.ts +8 -0
- package/dist/core/factory/itemExtra.js +9 -0
- package/dist/core/factory/itemFactory.d.ts +27 -0
- package/dist/core/factory/itemFactory.js +112 -0
- package/dist/core/factory/recipeFactory.d.ts +18 -0
- package/dist/core/factory/recipeFactory.js +39 -0
- package/dist/core/factory/uiFactory.d.ts +12 -0
- package/dist/core/factory/uiFactory.js +32 -0
- package/dist/core/feature/oreFeature.d.ts +10 -0
- package/dist/core/feature/oreFeature.js +11 -0
- package/dist/core/feature-rule/condition/biomeFilter.d.ts +26 -0
- package/dist/core/feature-rule/condition/biomeFilter.js +36 -0
- package/dist/core/feature-rule/condition/featureConditions.d.ts +27 -0
- package/dist/core/feature-rule/condition/featureConditions.js +37 -0
- package/dist/core/feature-rule/distribution/coordinateDistribution.d.ts +17 -0
- package/dist/core/feature-rule/distribution/coordinateDistribution.js +23 -0
- package/dist/core/feature-rule/distribution/featureDistribution.d.ts +31 -0
- package/dist/core/feature-rule/distribution/featureDistribution.js +41 -0
- package/dist/core/feature-rule/featureRule.d.ts +17 -0
- package/dist/core/feature-rule/featureRule.js +26 -0
- package/dist/core/index.d.ts +2241 -0
- package/dist/core/index.js +1 -0
- package/dist/core/item/armor.d.ts +21 -0
- package/dist/core/item/armor.js +90 -0
- package/dist/core/item/attachable.d.ts +6 -0
- package/dist/core/item/attachable.js +26 -0
- package/dist/core/item/food.d.ts +24 -0
- package/dist/core/item/food.js +38 -0
- package/dist/core/item/item.d.ts +36 -0
- package/dist/core/item/item.js +69 -0
- package/dist/core/item/itemComponents.d.ts +113 -0
- package/dist/core/item/itemComponents.js +225 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +17 -0
- package/dist/core/texture.d.ts +18 -0
- package/dist/core/texture.js +38 -0
- package/dist/core/ui/buttonMapping.d.ts +97 -0
- package/dist/core/ui/buttonMapping.js +132 -0
- package/dist/core/ui/dataBindingObject.d.ts +97 -0
- package/dist/core/ui/dataBindingObject.js +134 -0
- package/dist/core/ui/elements/button.d.ts +21 -0
- package/dist/core/ui/elements/button.js +101 -0
- package/dist/core/ui/elements/collectionPanel.d.ts +12 -0
- package/dist/core/ui/elements/collectionPanel.js +53 -0
- package/dist/core/ui/elements/grid.d.ts +8 -0
- package/dist/core/ui/elements/grid.js +33 -0
- package/dist/core/ui/elements/image.d.ts +13 -0
- package/dist/core/ui/elements/image.js +55 -0
- package/dist/core/ui/elements/label.d.ts +14 -0
- package/dist/core/ui/elements/label.js +61 -0
- package/dist/core/ui/elements/panel.d.ts +11 -0
- package/dist/core/ui/elements/panel.js +49 -0
- package/dist/core/ui/elements/scrollingPanel.d.ts +14 -0
- package/dist/core/ui/elements/scrollingPanel.js +59 -0
- package/dist/core/ui/elements/stackPanel.d.ts +14 -0
- package/dist/core/ui/elements/stackPanel.js +37 -0
- package/dist/core/ui/elements/uiElement.d.ts +53 -0
- package/dist/core/ui/elements/uiElement.js +129 -0
- package/dist/core/ui/properties/control.d.ts +214 -0
- package/dist/core/ui/properties/control.js +286 -0
- package/dist/core/ui/properties/dataBinding.d.ts +6 -0
- package/dist/core/ui/properties/dataBinding.js +16 -0
- package/dist/core/ui/properties/factory.d.ts +37 -0
- package/dist/core/ui/properties/factory.js +62 -0
- package/dist/core/ui/properties/gridProp.d.ts +65 -0
- package/dist/core/ui/properties/gridProp.js +90 -0
- package/dist/core/ui/properties/input.d.ts +97 -0
- package/dist/core/ui/properties/input.js +134 -0
- package/dist/core/ui/properties/layout.d.ts +105 -0
- package/dist/core/ui/properties/layout.js +145 -0
- package/dist/core/ui/properties/scrollView.d.ts +105 -0
- package/dist/core/ui/properties/scrollView.js +145 -0
- package/dist/core/ui/properties/sound.d.ts +47 -0
- package/dist/core/ui/properties/sound.js +66 -0
- package/dist/core/ui/properties/sprite.d.ts +161 -0
- package/dist/core/ui/properties/sprite.js +222 -0
- package/dist/core/ui/properties/text.d.ts +135 -0
- package/dist/core/ui/properties/text.js +187 -0
- package/dist/core/ui/registry/uiSystemRegistry.d.ts +8 -0
- package/dist/core/ui/registry/uiSystemRegistry.js +26 -0
- package/dist/core/ui/systems/chest.d.ts +5 -0
- package/dist/core/ui/systems/chest.js +21 -0
- package/dist/core/ui/systems/containerUISystem.d.ts +67 -0
- package/dist/core/ui/systems/containerUISystem.js +214 -0
- package/dist/core/ui/systems/guidebook.d.ts +9 -0
- package/dist/core/ui/systems/guidebook.js +206 -0
- package/dist/core/ui/systems/serverForm.d.ts +13 -0
- package/dist/core/ui/systems/serverForm.js +116 -0
- package/dist/core/ui/systems/system.d.ts +16 -0
- package/dist/core/ui/systems/system.js +37 -0
- package/dist/oc/actor.js +44 -0
- package/dist/oc/core.js +201 -0
- package/dist/oc/index.d.ts +142 -0
- package/dist/oc/index.js +1 -0
- package/dist/oc/input.js +67 -0
- package/dist/oc/optional.js +31 -0
- package/doc/oc/index.md +0 -0
- package/doc/sapdon-ts.md +41 -5
- package/package.json +6 -8
- package/doc/cli.md +0 -24
- /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,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);
|
|
94
|
+
static from(target: Entity): 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{value;static none(){return new o(null)}static some(t){return new o(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 r=Symbol("reflect-manager"),a=Symbol("reflect-entity");class i{[r];[a]=o.none();onTick(t,e){}detach(t){const e=Object.getPrototypeOf(this).constructor;return t.detachComponent(e)}getManager(){return this[r]}getEntity(){return this[a]}}class c extends i{onAttach(t){}onDetach(t){}}class p{static profilerEnable=!1;static global=new p;#t=new Map;#e=[];#n=[];getComponentUnsafe(t){return this.#t.get(t)}getComponent(t){return o.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),u in e)for(const[t,n]of e[u])this.#s(t,n,!1);return s&&"onAttach"in e&&await e.onAttach(this),this.#t.set(t,e),o.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?o.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,o.some(t))));this.#e.length=0;for(const e of this.#t.values()){e[a]||(e[a]=o.some(t)),e[r]||(e[r]=this);const{onTick:n}=e;n&&this.profiler((()=>n.call(e,this,o.some(t))),e)}for(const e of this.#n)this.profiler((()=>e.call(null,o.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(!p.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 u=Symbol("REQUIRED_COMPONENTS");function l(...t){return class extends c{[u]=new Map;constructor(){super();for(const e of t)if(Array.isArray(e)){const[t,...n]=e;this[u].set(t,Reflect.construct(t,n))}else this[u].set(e,Reflect.construct(e,[]))}getComponent(t){return this[u].get(t)}}}var h,m;!function(n){const s=new Map;function r(t){const e=new p;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=r,n.removeEntity=function(t){const e=t,n=s.get(e);n?.clear(),s.delete(e)},n.getManager=function(t){return s.get(t)??r(t)},n.tick=a,n.start=function(){e.runInterval(a)},n.toPlayer=function(e){return o.some(t.getAllPlayers().find((t=>t.id===e.id)))}}(h||(h={}));class f{target;manager;constructor(t){this.target=t,this.manager=h.getManager(t.id)}static from(t){return new f(t)}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)}}!function(t){t[t.Press=0]="Press",t[t.Release=1]="Release",t[t.None=2]="None"}(m||(m={}));class g extends c{[n.Jump]=m.None;[n.Sneak]=m.None;static setup(){t.afterEvents.playerButtonInput.subscribe((t=>{const e=h.getManager(t.player.id);e.getComponent(g).use((n=>{n[t.button]=t.newButtonState===s.Pressed?m.Press:m.Release,e.afterTick((()=>{n[t.button]=m.None}))}))}))}}class d extends c{[n.Jump]=m.None;[n.Sneak]=m.None;_lastJump=s.Released;_lastSneak=s.Released;onTick(t,e){const o=h.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]=m.Press:r===s.Released&&this._lastJump===s.Pressed?this[n.Jump]=m.Release:this[n.Jump]=m.None,a===s.Pressed&&this._lastSneak===s.Released?this[n.Sneak]=m.Press:a===s.Released&&this._lastSneak===s.Pressed?this[n.Sneak]=m.Release:this[n.Sneak]=m.None,this._lastJump=r,this._lastSneak=a}}export{f as Actor,c as BaseComponent,p as ComponentManager,i as CustomComponent,m as InputChangeState,o as Optional,d as PlayerInputCompatibilityComponent,g as PlayerInputComponent,l as RequireComponents,h as oc};
|
package/dist/oc/input.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ButtonState, InputButton, world } from "@minecraft/server";
|
|
2
|
+
import { BaseComponent } from "./core.js";
|
|
3
|
+
import { oc } from './core.js';
|
|
4
|
+
export var InputChangeState;
|
|
5
|
+
(function (InputChangeState) {
|
|
6
|
+
InputChangeState[InputChangeState["Press"] = 0] = "Press";
|
|
7
|
+
InputChangeState[InputChangeState["Release"] = 1] = "Release";
|
|
8
|
+
InputChangeState[InputChangeState["None"] = 2] = "None";
|
|
9
|
+
})(InputChangeState || (InputChangeState = {}));
|
|
10
|
+
/**
|
|
11
|
+
* `@minecraft/server` version 2.0.0-beta
|
|
12
|
+
* 低于此版本请不要使用此组件
|
|
13
|
+
*/
|
|
14
|
+
export class PlayerInputComponent extends BaseComponent {
|
|
15
|
+
;
|
|
16
|
+
[InputButton.Jump] = InputChangeState.None;
|
|
17
|
+
[InputButton.Sneak] = InputChangeState.None;
|
|
18
|
+
static setup() {
|
|
19
|
+
world.afterEvents.playerButtonInput.subscribe(e => {
|
|
20
|
+
const manager = oc.getManager(e.player.id);
|
|
21
|
+
const playerInput = manager.getComponent(PlayerInputComponent);
|
|
22
|
+
playerInput.use(playerInput => {
|
|
23
|
+
playerInput[e.button] = e.newButtonState === ButtonState.Pressed ? InputChangeState.Press : InputChangeState.Release;
|
|
24
|
+
manager.afterTick(() => {
|
|
25
|
+
playerInput[e.button] = InputChangeState.None;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `@minecraft/server` version 1.17.0-beta
|
|
33
|
+
* 有 1tick 延迟
|
|
34
|
+
* 条件允许请使用 `PlayerInputComponent`
|
|
35
|
+
*/
|
|
36
|
+
export class PlayerInputCompatibilityComponent extends BaseComponent {
|
|
37
|
+
;
|
|
38
|
+
[InputButton.Jump] = InputChangeState.None;
|
|
39
|
+
[InputButton.Sneak] = InputChangeState.None;
|
|
40
|
+
_lastJump = ButtonState.Released;
|
|
41
|
+
_lastSneak = ButtonState.Released;
|
|
42
|
+
onTick(manager, en) {
|
|
43
|
+
const player = oc.toPlayer(en.unwrap()).unwrap();
|
|
44
|
+
const jump = player.inputInfo.getButtonState(InputButton.Jump);
|
|
45
|
+
const sneak = player.inputInfo.getButtonState(InputButton.Sneak);
|
|
46
|
+
if (jump === ButtonState.Pressed && this._lastJump === ButtonState.Released) {
|
|
47
|
+
this[InputButton.Jump] = InputChangeState.Press;
|
|
48
|
+
}
|
|
49
|
+
else if (jump === ButtonState.Released && this._lastJump === ButtonState.Pressed) {
|
|
50
|
+
this[InputButton.Jump] = InputChangeState.Release;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this[InputButton.Jump] = InputChangeState.None;
|
|
54
|
+
}
|
|
55
|
+
if (sneak === ButtonState.Pressed && this._lastSneak === ButtonState.Released) {
|
|
56
|
+
this[InputButton.Sneak] = InputChangeState.Press;
|
|
57
|
+
}
|
|
58
|
+
else if (sneak === ButtonState.Released && this._lastSneak === ButtonState.Pressed) {
|
|
59
|
+
this[InputButton.Sneak] = InputChangeState.Release;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this[InputButton.Sneak] = InputChangeState.None;
|
|
63
|
+
}
|
|
64
|
+
this._lastJump = jump;
|
|
65
|
+
this._lastSneak = sneak;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class Optional {
|
|
2
|
+
value;
|
|
3
|
+
static none() {
|
|
4
|
+
return new Optional(null);
|
|
5
|
+
}
|
|
6
|
+
static some(value) {
|
|
7
|
+
return new Optional(value);
|
|
8
|
+
}
|
|
9
|
+
constructor(value) {
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
unwrap() {
|
|
13
|
+
if (!this.isEmpty()) {
|
|
14
|
+
return this.value;
|
|
15
|
+
}
|
|
16
|
+
throw new Error('Optional is empty');
|
|
17
|
+
}
|
|
18
|
+
isEmpty() {
|
|
19
|
+
return this.value === undefined || this.value === null;
|
|
20
|
+
}
|
|
21
|
+
orElse(other) {
|
|
22
|
+
return this.value ?? other;
|
|
23
|
+
}
|
|
24
|
+
use(fn, self) {
|
|
25
|
+
if (!this.isEmpty()) {
|
|
26
|
+
fn.call(self, this.value);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/doc/oc/index.md
ADDED
|
File without changes
|
package/doc/sapdon-ts.md
CHANGED
|
@@ -10,7 +10,7 @@ ts版本拥有更好的类型提示,更严格的类型检查,也可以直接
|
|
|
10
10
|
比如我们需要注册一个物品,可能你会想去找它在哪,但在ts版本中,你只需要 `@sapdon/core` 就可以了
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import { ItemAPI } from '@sapdon/core
|
|
13
|
+
import { ItemAPI } from '@sapdon/core'
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
如果你需要更高级的功能,比如你需要一个ts打包器,或者添加命令行的功能,你可以使用 `@sapdon/cli`
|
|
@@ -18,11 +18,47 @@ import { ItemAPI } from '@sapdon/core.js'
|
|
|
18
18
|
## 从js迁移到ts
|
|
19
19
|
js 的 `main.mjs` 包含了一些预定义的代码:
|
|
20
20
|
```js
|
|
21
|
-
import {
|
|
22
|
-
import { GRegistry, UISystemRegistry } from '@sapdon/core'
|
|
21
|
+
import { registry } from '@sapdon/core'
|
|
23
22
|
|
|
24
|
-
//
|
|
25
|
-
|
|
23
|
+
// 进行注册后需进行一次提交, 通知开发服务器更新文件
|
|
24
|
+
registry.setup()
|
|
26
25
|
```
|
|
27
26
|
如果需要从js迁移到ts,删除 `startDevServer` 那行即可(不删也没事)
|
|
28
27
|
|
|
28
|
+
|
|
29
|
+
## OC (Object - Component)
|
|
30
|
+
sapdon通过 `@sapdon/oc` 为sapi提供了一些高级功能, 比如:
|
|
31
|
+
- 实体组件系统
|
|
32
|
+
- 组件间通信
|
|
33
|
+
|
|
34
|
+
传统的书写方式是通过事件和tick回调来实现功能, 而OC提供了更适合游戏的组件化开发方式
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { world, system } from '@minecraft/server'
|
|
38
|
+
import { oc, CustomComponent } from '@sapdon/oc'
|
|
39
|
+
|
|
40
|
+
world.afterEvents.worldInitialize.subscribe(oc.start)
|
|
41
|
+
|
|
42
|
+
class MyComponent extends CustomComponent {
|
|
43
|
+
onTick() {
|
|
44
|
+
world.sendMessage('tick')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
是的, 我们得到了一个MyComponent, 它每刻都会给玩家发送 'tick'
|
|
50
|
+
但是如果你进入游戏, 会发现它毫无作用, 没错! 因为我们还没有把它到绑定在实体身上!
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const manager = oc.addEntity(id)
|
|
54
|
+
manager.attachComponent(new MyComponent())
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
这样就可以了, 我们已经把MyComponent绑定到了entityId为id的实体身上
|
|
58
|
+
|
|
59
|
+
你也可以动态增删改查组件! 这很方便!
|
|
60
|
+
|
|
61
|
+
如果你想看它到底是怎么回事,可以从 `examples/oc-core` 开始了解
|
|
62
|
+
|
|
63
|
+
## [Object - Component](./oc/index.md)
|
|
64
|
+
关于 `@sapdon/oc` 的一切
|
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.1.0",
|
|
6
4
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"build": "node dist/cli/index.js build",
|
|
10
|
-
"pub": "tsc && npm publish"
|
|
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",
|
package/doc/cli.md
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
|
|
File without changes
|