sapdon 3.5.2 → 3.6.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 +35 -3
- package/doc/dev/architecture.md +69 -23
- package/doc/dev/cli.md +179 -43
- package/doc/dev/core.md +2 -1
- package/doc/dev/known-pitfalls.md +869 -0
- package/doc/dev/oc.md +156 -23
- package/doc/dev/ui-architecture.md +83 -0
- package/doc/dev/workflow.md +61 -19
- package/doc/guidebook.md +196 -6
- package/doc/user/api/block.md +342 -0
- package/doc/user/api/runtime.md +332 -0
- package/doc/user/faq.md +96 -14
- package/package.json +1 -1
- package/prod/cli/index.js +1 -1
- package/prod/cli/start.js +1 -1
- package/prod/core/index.d.ts +619 -73
- package/prod/core/index.js +1 -1
- package/prod/oc/index.d.ts +134 -3
- package/prod/oc/index.js +1 -1
- package/prod/templates/js_sapdon/mod.info +1 -1
- package/prod/templates/js_sapdon/package.json +4 -5
- package/prod/templates/js_sapdon/res/models/blocks/cube.geo.json +35 -0
- package/prod/templates/js_sapdon/scripts/custom_components/index.js +4 -0
- package/prod/templates/js_sapdon/scripts/custom_components/registry.js +0 -5
- package/prod/templates/ts_sapdon/package.json +5 -5
- package/prod/templates/ts_sapdon/res/models/blocks/cube.geo.json +35 -0
- package/prod/templates/ts_sapdon/scripts/custom_components/index.js +3 -0
package/prod/oc/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entity, StartupEvent, Player, ScriptEventCommandMessageAfterEvent } from '@minecraft/server';
|
|
1
|
+
import { BlockCustomComponent, ItemCustomComponent, Entity, StartupEvent, Player, ScriptEventCommandMessageAfterEvent, Vector3 as Vector3$1 } from '@minecraft/server';
|
|
2
2
|
|
|
3
3
|
declare const isOptional: unique symbol;
|
|
4
4
|
declare class Optional<T = any> {
|
|
@@ -88,6 +88,46 @@ declare function RequireComponents<Actor>(...params: RequireComponentsParam<Acto
|
|
|
88
88
|
*/
|
|
89
89
|
declare function lazyGet<T extends ComponentCtor<unknown>>(component: Component<unknown>, ctor: T): InstanceType<T>;
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* 注册方块自定义组件(自动保证 `system.beforeEvents.startup` 时机)。
|
|
93
|
+
* 在方块 JSON 里仍须用 `BlockComponent.setCustomComponents(['<id>'])` 声明同名组件。
|
|
94
|
+
*/
|
|
95
|
+
declare function registerBlockComponent(id: string, handlers: BlockCustomComponent): void;
|
|
96
|
+
/**
|
|
97
|
+
* 注册物品自定义组件(自动保证 `system.beforeEvents.startup` 时机)。
|
|
98
|
+
* ⚠️ 物品要能触发 `onUse`,还必须在物品上声明 `minecraft:interact_button`(见 AGENTS.md)。
|
|
99
|
+
*/
|
|
100
|
+
declare function registerItemComponent(id: string, handlers: ItemCustomComponent): void;
|
|
101
|
+
/**
|
|
102
|
+
* 注册**框架内置的兜底**方块自定义组件:只有当项目**没有**自己注册同一 id 时才真正注册。
|
|
103
|
+
*
|
|
104
|
+
* 语义(判定发生在 `system.beforeEvents.startup`,见文件头注释):
|
|
105
|
+
* - 项目没注册该 id → 内置实现生效;
|
|
106
|
+
* - 项目注册了该 id → **项目实现生效**,内置实现被跳过,并打一条 warn(不是错误);
|
|
107
|
+
* - 重复登记同一个内置 id(`registerBuiltinComponents()` 被调两次)→ **幂等**,只算一次。
|
|
108
|
+
*
|
|
109
|
+
* ⚠️ 与 `registerBlockComponent` 的差别只有「撞 id 时的方向」:
|
|
110
|
+
* 前者是「项目说了算」,后者是「项目之间重复 = 编程错误 → 抛」。
|
|
111
|
+
* 框架内置组件必须用本函数,否则每一个在历史上手工注册过该 id 的项目升级后都会开不了机。
|
|
112
|
+
*
|
|
113
|
+
* @param id 组件 id,必须与方块 JSON 里写的那个键完全相同
|
|
114
|
+
* @param handlers 处理器对象(与 `registerBlockComponent` 同一套事件名)
|
|
115
|
+
*/
|
|
116
|
+
declare function registerFallbackBlockComponent(id: string, handlers: BlockCustomComponent): void;
|
|
117
|
+
/** 物品侧的兜底注册(与 `registerFallbackBlockComponent` 语义完全一致,见其注释) */
|
|
118
|
+
declare function registerFallbackItemComponent(id: string, handlers: ItemCustomComponent): void;
|
|
119
|
+
/** 已排队但尚未注册的组件数(启动前 > 0 属正常;不含框架兜底组件) */
|
|
120
|
+
declare function pendingComponentCount(): number;
|
|
121
|
+
/** 已成功注册的组件列表(形如 `block:fz:machine`),用于运行期自检 */
|
|
122
|
+
declare function registeredComponents(): string[];
|
|
123
|
+
/**
|
|
124
|
+
* 因「项目已注册同 id」而被跳过的**内置兜底**组件列表(形如 `block:sapdon:block_with_entity`)。
|
|
125
|
+
*
|
|
126
|
+
* 用途:运行期自检时区分「内置实现生效」与「项目实现生效」
|
|
127
|
+
* (两者都正常,但排查「方块行为不对」时第一个要看的就是它)。
|
|
128
|
+
*/
|
|
129
|
+
declare function skippedFallbackComponents(): string[];
|
|
130
|
+
|
|
91
131
|
type AxisValue = number | [number, number] | [number, number, number];
|
|
92
132
|
interface IKeyState {
|
|
93
133
|
pressing: boolean;
|
|
@@ -379,7 +419,98 @@ declare const ScriptEvent: {
|
|
|
379
419
|
(evType: string): MethodDecorator;
|
|
380
420
|
};
|
|
381
421
|
|
|
422
|
+
/**
|
|
423
|
+
* 分块动态属性读写(`world` / `Entity` / `ItemStack` 通用)。
|
|
424
|
+
*
|
|
425
|
+
* ## 为什么框架要内建
|
|
426
|
+
* Bedrock 单个动态属性值长度有上限(约 **32KB** 量级),超限时 `setDynamicProperty` **抛错**。
|
|
427
|
+
* 项目侧手写时一旦把这段包进 `try-catch`,就会变成**静默丢存档**(症状:重进世界后数据回到早期快照)。
|
|
428
|
+
* AGENTS.md 记的 `digitCircuit` 事故与 `lr-framework` 的 `BaseEngine.save` 都是这个坑。
|
|
429
|
+
* 所以这里把「分块 + 清理残留 + 不吞异常」固化成框架接口。
|
|
430
|
+
*
|
|
431
|
+
* ## 存储格式(与既有实现互通)
|
|
432
|
+
* - 小数据(≤ {@link CHUNK_SIZE}):主 key 直接存**原字符串**。
|
|
433
|
+
* - 大数据:数据块 `"<key>#0" … "<key>#N-1"`,主 key 存 `{"_chunks":N}`。
|
|
434
|
+
* 与 `examples/lr-framework/.../BaseEngine.ts` 的 `save/load`、
|
|
435
|
+
* `digitCircuit` 的 `CIRCUIT_CHUNK=24000` 方案**完全一致**,可互相读取。
|
|
436
|
+
* - **提交点**:数据块先写、主 key 后写。中途失败时主 key 仍指向上一份完整数据,
|
|
437
|
+
* 不会留下「半新半旧」的可读结果。
|
|
438
|
+
*
|
|
439
|
+
* ## 空值语义(★ 与 `BaseEngine` 的坑不同)
|
|
440
|
+
* `loadChunked` 返回 `undefined` = **从没存过**;返回 `''` = **存过空串**。
|
|
441
|
+
* ⚠️ 判断时请用 `=== undefined`,**不要**用真值判断(`if (!v)` 会把空串当没存过)。
|
|
442
|
+
*
|
|
443
|
+
* ## 异常约定
|
|
444
|
+
* **本模块不吞任何异常**:写入失败、分块缺失、类型不符一律抛出。
|
|
445
|
+
* 调用方若确实要容错,请自行 catch 并**至少打印日志**,不要静默忽略。
|
|
446
|
+
*/
|
|
447
|
+
/** 单个数据块的字符数上限(与 BaseEngine / digitCircuit 一致,安全低于约 32KB 的引擎上限) */
|
|
448
|
+
declare const CHUNK_SIZE = 24000;
|
|
449
|
+
/** 分块键后缀:`<key>#<index>` */
|
|
450
|
+
declare const CHUNK_SUFFIX = "#";
|
|
451
|
+
/**
|
|
452
|
+
* 无 `getDynamicPropertyIds()` 时的兜底扫描上界。
|
|
453
|
+
* 有该 API 时按实际存在的键精确清理,不受此值限制。
|
|
454
|
+
*/
|
|
455
|
+
declare const MAX_CHUNK_SCAN = 256;
|
|
456
|
+
/** `setDynamicProperty` 允许的取值 */
|
|
457
|
+
type DynamicPropertyValue = boolean | number | string | Vector3$1;
|
|
458
|
+
/**
|
|
459
|
+
* 分块读写所需的最小目标接口。
|
|
460
|
+
* `world`(World)/ `Entity` / `ItemStack` / 容器槽位均满足;单测里可用内存对象顶替。
|
|
461
|
+
*/
|
|
462
|
+
interface DynamicPropertyTarget {
|
|
463
|
+
getDynamicProperty(identifier: string): DynamicPropertyValue | undefined;
|
|
464
|
+
setDynamicProperty(identifier: string, value?: DynamicPropertyValue): void;
|
|
465
|
+
/** 可选:@minecraft/server 的 World/Entity/ItemStack 均提供,用于精确清理残留分块 */
|
|
466
|
+
getDynamicPropertyIds?(): string[];
|
|
467
|
+
}
|
|
468
|
+
/** 第 index 个数据块的键名 */
|
|
469
|
+
declare function chunkKey(key: string, index: number): string;
|
|
470
|
+
/** 主 key 里表示「已分块」的元数据 JSON,如 `{"_chunks":3}` */
|
|
471
|
+
declare function chunkMetaJson(count: number): string;
|
|
472
|
+
/**
|
|
473
|
+
* 解析主 key 的分块元数据。
|
|
474
|
+
* 只有「恰好是一个仅含整型 `_chunks` 的对象」才算分块,其余一律返回 undefined。
|
|
475
|
+
*/
|
|
476
|
+
declare function parseChunkCount(raw: unknown): number | undefined;
|
|
477
|
+
/**
|
|
478
|
+
* 该字符串是否**长得像**分块元数据。
|
|
479
|
+
* 这类值必须强制分块,否则 `{"_chunks":2}` 这样的原文会被 `loadChunked` 误判成元数据。
|
|
480
|
+
*/
|
|
481
|
+
declare function looksLikeChunkMeta(value: string): boolean;
|
|
482
|
+
/** 按 size 切分字符串(纯函数,可单测) */
|
|
483
|
+
declare function splitValue(value: string, size?: number): string[];
|
|
484
|
+
/**
|
|
485
|
+
* 分块写入字符串(幂等:同一份数据连存两次结果一致)。
|
|
486
|
+
*
|
|
487
|
+
* @throws 值不是字符串、或底层 `setDynamicProperty` 抛错(如超限)时**原样抛出**
|
|
488
|
+
*/
|
|
489
|
+
declare function saveChunked(target: DynamicPropertyTarget, key: string, value: string): void;
|
|
490
|
+
/**
|
|
491
|
+
* 读取字符串。
|
|
492
|
+
* @returns `undefined` = 从没存过;`''` = 存过空串
|
|
493
|
+
* @throws 分块数据缺失/损坏,或主 key 被非字符串占用时
|
|
494
|
+
*/
|
|
495
|
+
declare function loadChunked(target: DynamicPropertyTarget, key: string): string | undefined;
|
|
496
|
+
/**
|
|
497
|
+
* 彻底清除:主 key + **所有**数据块(含旧存档残留的更高序号块)。
|
|
498
|
+
* 清完 `loadChunked` 返回 `undefined`(回到「从没存过」)。
|
|
499
|
+
*/
|
|
500
|
+
declare function clearChunked(target: DynamicPropertyTarget, key: string): void;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* 注册框架内置的自定义组件。
|
|
504
|
+
*
|
|
505
|
+
* ★ `sapdon:block_with_entity` 走的是**兜底**通道(`registerFallbackBlockComponent`):
|
|
506
|
+
* `TileBlock` 会给**每个**带实体方块挂上这个组件(`src/core/block/tileBlock.js:184`),
|
|
507
|
+
* 而历史上框架自己从不注册它 —— 忘了手工注册的项目会**整份方块被引擎丢掉**
|
|
508
|
+
* (`this component was found in the input, but is not present in the Schema`)。
|
|
509
|
+
* 走兜底而不是直接注册,是为了**不打断既有项目**:项目自己注册了同一个 id 时,
|
|
510
|
+
* **项目实现生效**、内置实现被跳过(并打一条 warn)。
|
|
511
|
+
* 完整理由与三种场景见 `src/oc/components/registry.ts` 的文件头注释。
|
|
512
|
+
*/
|
|
382
513
|
declare function registerBuiltinComponents(): void;
|
|
383
514
|
|
|
384
|
-
export { ActorSpawned, BaseComponent, ComponentManager, CustomComponent, EntitySpawned, GameInstance, HudComponent, MathExt, Matrix, Minecraft, MinecraftGameInstance, MinecraftLevel, MinecraftMain, MinecraftMethod, MinecraftPlayerInputComponent, MinecraftTickingScheduler, Optional, PlayerHudComponent, PlayerInputComponent, PlayerSpawned, RequireComponents, ScriptEvent, SpawnFilter, Vec3, Vec4, assertInMinecraft, finalize, getGameInstance, getGameInstanceClass, initialize, lazyGet, registerBuiltinComponents, utils };
|
|
385
|
-
export type { AxisValue, BasicComponent, Component, ComponentCtor, IKeyState, InputAxisMapping, InputKeyMapping, RequiredComponent, Vector3, Vector4 };
|
|
515
|
+
export { ActorSpawned, BaseComponent, CHUNK_SIZE, CHUNK_SUFFIX, ComponentManager, CustomComponent, EntitySpawned, GameInstance, HudComponent, MAX_CHUNK_SCAN, MathExt, Matrix, Minecraft, MinecraftGameInstance, MinecraftLevel, MinecraftMain, MinecraftMethod, MinecraftPlayerInputComponent, MinecraftTickingScheduler, Optional, PlayerHudComponent, PlayerInputComponent, PlayerSpawned, RequireComponents, ScriptEvent, SpawnFilter, Vec3, Vec4, assertInMinecraft, chunkKey, chunkMetaJson, clearChunked, finalize, getGameInstance, getGameInstanceClass, initialize, lazyGet, loadChunked, looksLikeChunkMeta, parseChunkCount, pendingComponentCount, registerBlockComponent, registerBuiltinComponents, registerFallbackBlockComponent, registerFallbackItemComponent, registerItemComponent, registeredComponents, saveChunked, skippedFallbackComponents, splitValue, utils };
|
|
516
|
+
export type { AxisValue, BasicComponent, Component, ComponentCtor, DynamicPropertyTarget, DynamicPropertyValue, IKeyState, InputAxisMapping, InputKeyMapping, RequiredComponent, Vector3, Vector4 };
|
package/prod/oc/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{system as t,world as e,ButtonState as s,EquipmentSlot as n,GameMode as r}from"@minecraft/server";import{ActionFormData as i}from"@minecraft/server-ui";const o=Symbol("isOptional");class a{value;static none(){return new a(null)}static some(t){return new a(t)}constructor(t){this.value=t}[o]=o;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){if(!this.isEmpty()){const s=t.call(e,this.value);return s[o]?s:a.some(t.call(e,this.value))}return a.none()}}const m=Symbol("reflect-manager"),c=Symbol("reflect-entity");class h{[m];[c]=a.none();onTick(t){}detach(){const t=Object.getPrototypeOf(this).constructor;return this.getManager().detachComponent(t)}getManager(){return this[m]}getEntity(){return this[c]}lazyGet(t){return f(this,t)}}class u extends h{onAttach(t){}onDetach(t){}}class l{static profilerEnable=!1;static global=new l;#t=new Map;#e=[];#s=[];getComponentUnsafe(t){return this.#t.get(t)}getComponent(t){return a.some(this.#t.get(t))}getComponents(...t){return t.map(t=>this.#t.get(t))}#n(t,e,s=!0){e[m]||(e[m]=this);let n=!this.#t.get(t);if(!n&&s&&(this.detachComponent(t),n=!0),p in e)for(const[t,s]of e[p])e.getManager().getComponentUnsafe(t)||this.#n(t,s,!1);return n&&"onAttach"in e&&e.onAttach(this),this.#t.set(t,e),a.some(e)}attachComponent(...t){const e=[];for(const s of t)e.push(this.#n(Object.getPrototypeOf(s).constructor,s));return e}async getOrCreate(t,...e){let s=this.#t.get(t);return s?a.some(s):this.#n(t,new t(...e))}detachComponent(t){const e=this.#t.get(t);return e&&"onDetach"in e&&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.#s.push(t)}beforeTick(t){this.#e.unshift(t)}handleTicks(t,e){for(const e of this.#e)this.profiler(()=>e.call(null,a.some(t)));this.#e.length=0;for(const s of this.#t.values()){s[c].isEmpty()&&(s[c]=a.some(t));const{onTick:n}=s;n&&this.profiler(()=>n.call(s,e),s)}for(const e of this.#s)this.profiler(()=>e.call(null,a.some(t)));this.#s.length=0}update(t,e){const s=this.#t.get(t);return!!s&&(e(s),!0)}profiler(t,e,s){if(!l.profilerEnable)return t();const n=e?Object.getPrototypeOf(e).constructor.name:"",r=s||(n?`${n}.${t.name}`:t.name),i=performance.now(),o=t();return console.log(`[Profiler] ${r} took ${performance.now()-i}ms`),o}}const p=Symbol("REQUIRED_COMPONENTS");function d(...t){return class extends u{[p]=new Map;constructor(){super();for(const e of t){if(Array.isArray(e)){const[t,...s]=e;this[p].set(t,Reflect.construct(t,s));continue}this[p].set(e,Reflect.construct(e,[]))}}getComponent(t){return this[p].get(t)}}}function f(t,e){let s=null;return new Proxy(Object.create(Object.prototype),{get:(n,r)=>(s||(s=t.getManager().getComponentUnsafe(e)),s[r]),set:(n,r,i)=>s?(s[r]=i,!0):(s=t.getManager().getComponentUnsafe(e),s[r]=i,!0)})}class y extends Array{constructor(t){super(),Array.isArray(t)&&this.set(t)}set(t){let e=0;for(const s of t)this[e]=s,e++}}class g extends y{x=0;y=0;z=0;constructor(t){super(t),this.x=t[0]||0,this.y=t[1]||0,this.z=t[2]||0}static fromXYZ(t,e,s){return new g([t,e,s])}static fromVec3(t){return new g([t.x,t.y,t.z])}static m(t){const{x:e,y:s,z:n}=t;return Math.sqrt(e*e+s*s+n*n)}m(){return g.m(this)}static isZero(t){return 0===t.x&&0===t.y&&0===t.z}isZero(){return g.isZero(this)}static normalize(t){if(this.isZero(t))return!1;const{x:e,y:s,z:n}=t,r=this.m(t);t.x=e/r,t.y=s/r,t.z=n/r}n(){return g.normalize(this)}static add(t,e){return new g([t.x+e.x,t.y+e.y,t.z+e.z])}add(t){return g.add(this,t)}static sub(t,e){return new g([t.x-e.x,t.y-e.y,t.z-e.z])}sub(t){return g.sub(this,t)}static mul(t,e){return new g([t.x*e,t.y*e,t.z*e])}mul(t){return g.mul(this,t)}static div(t,e){return new g([t.x/e,t.y/e,t.z/e])}div(t){return g.div(this,t)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}dot(t){return g.dot(this,t)}static cross(t,e){return new g([t.y*e.z-t.z*e.y,t.z*e.x-t.x*e.z,t.x*e.y-t.y*e.x])}cross(t){return g.cross(this,t)}valueOf(){return new y([this.x,this.y,this.z])}toString(){return`(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.z.toFixed(2)})`}}class x extends y{constructor(){super([].fill(0,0,16)),this.fill(0)}get m11(){return this[0]}get m12(){return this[1]}get m13(){return this[2]}get m14(){return this[3]}get m21(){return this[4]}get m22(){return this[5]}get m23(){return this[6]}get m24(){return this[7]}get m31(){return this[8]}get m32(){return this[9]}get m33(){return this[10]}get m34(){return this[11]}get m41(){return this[12]}get m42(){return this[13]}get m43(){return this[14]}get m44(){return this[15]}set m11(t){this[0]=t}set m12(t){this[1]=t}set m13(t){this[2]=t}set m14(t){this[3]=t}set m21(t){this[4]=t}set m22(t){this[5]=t}set m23(t){this[6]=t}set m24(t){this[7]=t}set m31(t){this[8]=t}set m32(t){this[9]=t}set m33(t){this[10]=t}set m34(t){this[11]=t}set m41(t){this[12]=t}set m42(t){this[13]=t}set m43(t){this[14]=t}set m44(t){this[15]=t}get a(){return this.m11}get b(){return this.m12}get c(){return this.m21}get d(){return this.m22}get e(){return this.m41}get f(){return this.m42}set a(t){this.m11=t}set b(t){this.m12=t}set c(t){this.m21=t}set d(t){this.m22=t}set e(t){this.m41=t}set f(t){this.m42=t}static init(t,e,s){const n=y.from(t,e,s),r=new x;return r.set(n),r}clone(){return x.init(this.slice(),t=>t)}setIdentity(){return this.set([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this}static identity(){const t=new x;return t.setIdentity(),t}static add(t,e){const s=new x;return s.set(t.map((t,s)=>t+e[s])),s}add(t){return x.add(this,t)}static sub(t,e){const s=new x;return s.set(t.map((t,s)=>t-e[s])),s}sub(t){return x.sub(this,t)}setTranslation(t,e,s){return this.m14=t,this.m24=e,this.m34=s,this}setRotation(t,e){g.normalize(e);const s=Math.sin(t),n=Math.cos(t),r=e.x,i=e.y,o=e.z,a=1-n,m=a*r*r+n,c=a*r*i-s*o,h=a*r*o+s*i,u=a*r*i+s*o,l=a*i*i+n,p=a*i*o-s*r,d=a*r*o-s*i,f=a*i*o+s*r,y=a*o*o+n;return this.m11=m,this.m12=c,this.m13=h,this.m21=u,this.m22=l,this.m23=p,this.m31=d,this.m32=f,this.m33=y,this}setScale(t,e,s){return this.m11*=t,this.m22*=e,this.m33*=s,this}setRotationX(t){const e=Math.sin(t),s=Math.cos(t);return this.m11=1,this.m12=0,this.m13=0,this.m21=0,this.m22=s,this.m23=e,this.m31=0,this.m32=-e,this.m33=s,this}setRotationY(t){const e=Math.sin(t),s=Math.cos(t);return this.m11=s,this.m12=0,this.m13=-e,this.m21=0,this.m22=1,this.m23=0,this.m31=e,this.m32=0,this.m33=s,this}setRotationZ(t){const e=Math.sin(t),s=Math.cos(t);return this.m11=s,this.m12=e,this.m13=0,this.m21=-e,this.m22=s,this.m23=0,this.m31=0,this.m32=0,this.m33=1,this}setRotationXYZ(t,e,s){const n=Math.sin(t),r=Math.cos(t),i=Math.sin(e),o=Math.cos(e),a=Math.sin(s),m=Math.cos(s);return this.m11=r*m+n*i*a,this.m12=r*a-n*i*m,this.m13=n*o,this.m21=n*m-r*i*a,this.m22=r*m-n*i*m,this.m23=r*i,this.m31=n*a+r*i*m,this.m32=-n*m+r*i*a,this.m33=r*o,this}static translate(t,e){const{x:s,y:n,z:r}=e,i=t.clone();return i.m14=i.m11*s+i.m21*n+i.m31*r+s,i.m24=i.m21*s+i.m22*n+i.m32*r+n,i.m34=i.m31*s+i.m32*n+i.m33*r+r,i}translate(t){return x.translate(this,t)}static transpose(t){return this.from([t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44])}transpose(){return x.transpose(this)}static multiply(t,e){return e instanceof x?this.from([t.m11*e.m11+t.m12*e.m21+t.m13*e.m31+t.m14*e.m41,t.m11*e.m12+t.m12*e.m22+t.m13*e.m32+t.m14*e.m42,t.m11*e.m13+t.m12*e.m23+t.m13*e.m33+t.m14*e.m43,t.m11*e.m14+t.m12*e.m24+t.m13*e.m34+t.m14*e.m44,t.m21*e.m11+t.m22*e.m21+t.m23*e.m31+t.m24*e.m41,t.m21*e.m12+t.m22*e.m22+t.m23*e.m32+t.m24*e.m42,t.m21*e.m13+t.m22*e.m23+t.m23*e.m33+t.m24*e.m43,t.m21*e.m14+t.m22*e.m24+t.m23*e.m34+t.m24*e.m44,t.m31*e.m11+t.m32*e.m21+t.m33*e.m31+t.m34*e.m41,t.m31*e.m12+t.m32*e.m22+t.m33*e.m32+t.m34*e.m42,t.m31*e.m13+t.m32*e.m23+t.m33*e.m33+t.m34*e.m43,t.m31*e.m14+t.m32*e.m24+t.m33*e.m34+t.m34*e.m44,t.m41*e.m11+t.m42*e.m21+t.m43*e.m31+t.m44*e.m41,t.m41*e.m12+t.m42*e.m22+t.m43*e.m32+t.m44*e.m42,t.m41*e.m13+t.m42*e.m23+t.m43*e.m33+t.m44*e.m43,t.m41*e.m14+t.m42*e.m24+t.m43*e.m34+t.m44*e.m44]):new w([t.m11*e.x+t.m12*e.y+t.m13*e.z+t.m14*e.w,t.m21*e.x+t.m22*e.y+t.m23*e.z+t.m24*e.w,t.m31*e.x+t.m32*e.y+t.m33*e.z+t.m34*e.w,t.m41*e.x+t.m42*e.y+t.m43*e.z+t.m44*e.w])}multiply(t){return x.multiply(this,t)}valueOf(){return new y(this)}toString(){return`${this.m11.toFixed(2)}\t${this.m12.toFixed(2)}\t${this.m13.toFixed(2)}\t${this.m14.toFixed(2)}\n${this.m21.toFixed(2)}\t${this.m22.toFixed(2)}\t${this.m23.toFixed(2)}\t${this.m24.toFixed(2)}\n${this.m31.toFixed(2)}\t${this.m32.toFixed(2)}\t${this.m33.toFixed(2)}\t${this.m34.toFixed(2)}\n${this.m41.toFixed(2)}\t${this.m42.toFixed(2)}\t${this.m43.toFixed(2)}\t${this.m44.toFixed(2)}\n`}static perspective(t,e,s,n){const r=Math.tan(t/2),i=r*e;return x.from([s/i,0,0,0,0,1/r,0,0,0,0,-(s+n)/(n-s),-2*n*s/(n-s),0,0,-1,0])}static orthographic(t,e,s,n){return x.from([1/t,0,0,0,0,1/e,0,0,0,0,-2/(n-s),-(n+s)/(n-s),0,0,0,1])}static lookAt(t,e,s){const n=g.sub(e,t);n.n();const r=g.cross(s,n);r.n();const i=g.cross(n,r);return i.n(),x.from([r.x,r.y,r.z,-g.dot(r,t),i.x,i.y,i.z,-g.dot(i,t),n.x,n.y,n.z,-g.dot(n,t),0,0,0,1])}}class w extends y{x=0;y=0;z=0;w=0;constructor(t){super(t),this.x=t[0]||0,this.y=t[1]||0,this.z=t[2]||0,this.w=t[3]||0}static fromXYZW(t,e,s,n){return new w([t,e,s,n])}static fromVec3(t){return new w([t.x,t.y,t.z])}static fromVec4(t){return new w([t.x,t.y,t.z,t.w])}static m(t){const{x:e,y:s,z:n,w:r}=t;return Math.sqrt(e*e+s*s+n*n+r*r)}m(){return w.m(this)}static isZero(t){return 0===t.x&&0===t.y&&0===t.z&&0===t.w}isZero(){return w.isZero(this)}static normalize(t){if(this.isZero(t))return!1;const{x:e,y:s,z:n,w:r}=t,i=this.m(t);t.x=e/i,t.y=s/i,t.z=n/i,t.w=r/i}n(){return w.normalize(this)}static add(t,e){return new w([t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w])}add(t){return w.add(this,t)}static sub(t,e){return new w([t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w])}sub(t){return w.sub(this,t)}static mul(t,e){return new w([t.x*e,t.y*e,t.z*e,t.w*e])}mul(t){return w.mul(this,t)}static div(t,e){return new w([t.x/e,t.y/e,t.z/e,t.w/e])}div(t){return w.div(this,t)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}dot(t){return w.dot(this,t)}static multiply(t,e){return x.multiply(e,t)}multiply(t){return w.multiply(this,t)}valueOf(){return new y([this.x,this.y,this.z,this.w])}toString(){return`(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.z.toFixed(2)}, ${this.w.toFixed(2)})`}}var v;!function(t){function e(t,e,s){return t+(e-t)*s}function s(t,s,n){return g.fromXYZ(e(t.x,s.x,n),e(t.y,s.y,n),e(t.z,s.z,n))}function n(t,s,n){return w.fromXYZW(e(t.x,s.x,n),e(t.y,s.y,n),e(t.z,s.z,n),e(t.w,s.w,n))}t.clamp=function(t,e,s){return Math.min(Math.max(t,e),s)},t.lerps=e,t.lerpVec3=s,t.lerpVec4=n,t.lerp=function(t,r,i){return"number"==typeof t?e(t,r,i):"w"in t?n(t,r,i):s(t,r,i)}}(v||(v={}));class b{pressing;times;constructor(t=!1,e=0){this.pressing=t,this.times=e}consume(){this.times--}}class _ extends u{keyStateMapping=new Map;axisMapping=new Map;inputKey(t,e){let s=this.keyStateMapping.get(t)??new b;e?(s.pressing=!0,s.times++):(s.pressing=!1,s.times--),this.keyStateMapping.set(t,s)}inputAxis(t,e){this.axisMapping.set(t,e)}getKeyState(t){return this.keyStateMapping.get(t)}getAxis(t){return this.axisMapping.get(t)}getKeyPressing(t){return this.getKeyState(t)?.pressing??!1}getKeyPressTimes(t){return this.getKeyState(t)?.times??0}exhaust(t){const e=this.getKeyState(t);e&&(e.times=0)}combineAxis(t,e){return Array.isArray(t)||(t=[t]),Array.isArray(e)||(e=[e]),t.concat(e)}splitAxis(t,e,s){return e=v.clamp(e,0,t.length-1),s||(s=t.length-e),[t.slice(0,e),t.slice(e,e+s)]}}let z,M;function k(t,e={}){M=Reflect.construct(t,[]),M?.onStart?.(e)}function E(t){t?.shutdown?.()}const S=t=>{z=t};function C(){return z}function A(){return M}var R=function(t,e,s,n){var r,i=arguments.length,o=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,s):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,s,n);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(i<3?r(o):i>3?r(e,s,o):r(e,s))||o);return i>3&&o&&Object.defineProperty(e,s,o),o};function L(t,e,s){const n=s.value;return s.value=(...e)=>(F(),n.apply(t,e)),s}class T{toPlayer(t){return a.some(t)}start(){t?.beforeEvents?.startup&&(t.beforeEvents.startup.subscribe(t=>{const e=C();if(!e)throw new Error("No game instance class found");k(e,t)}),t.beforeEvents.shutdown.subscribe(t=>{const e=A();e&&E(e)})),e?.beforeEvents?.worldInitialize&&e.beforeEvents.worldInitialize.subscribe(t=>{const e=C();if(!e)throw new Error("No game instance class found");k(e,t)})}}R([L],T.prototype,"toPlayer",null),R([L],T.prototype,"start",null);const P=new T;function $(t){return t?.[Symbol.metadata]}function F(){if(!e)throw new Error("Not running in the Minecraft host environment. required @minecraft/server")}Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));const O=t=>new Proxy(t,{construct:(t,e)=>(F(),Reflect.construct(t,e))}),D=t=>{F(),S(t),P.start(),e.afterEvents.playerSpawn.subscribe(t=>A()?.getLevel().getManager(t.player.id).attachComponent(...I(j).filter(e=>$(e)?.spawnFilter?.(t.player)??!0).map(t=>Reflect.construct(t,[])))),e.afterEvents.entitySpawn.subscribe(t=>{"minecraft:player"!==t.entity.typeId&&A()?.getLevel().getManager(t.entity.id).attachComponent(...I(Z).filter(e=>$(e)?.spawnFilter?.(t.entity)??!0).map(t=>Reflect.construct(t,[])))})};function I(t){return Array.from(new Set(t))}const j=[],Z=[],N=(...t)=>e=>{j.push(...t,e)},H=(...t)=>e=>{Z.push(...t,e)},K=(...t)=>e=>{j.push(...t,e),Z.push(...t,e)},V=t=>e=>{const s=function(t){if(null==t)return;return t?.[Symbol.metadata]??(t[Symbol.metadata]={})}(e);s.spawnFilter=t};class U{table=new Map;addEntity(t){const e=new l;return this.table.set(t,e),e}removeEntity(t){const e=t,s=this.table.get(e);s?.clear(),this.table.delete(e)}getManager(t){return this.table.get(t)??this.addEntity(t)}start(){this.getScheduler().start(this.table)}stop(){this.getScheduler().stop()}}var q=function(t,e,s,n){var r,i=arguments.length,o=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,s):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,s,n);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(i<3?r(o):i>3?r(e,s,o):r(e,s))||o);return i>3&&o&&Object.defineProperty(e,s,o),o};let X=class{_run=0;_currentTick=0;_timeStamp=0;get currentTick(){return this._currentTick}_handleTick(t,s){for(const[n,r]of t.entries()){const t=e.getEntity(n);t&&r.handleTicks(t,s)}}executeTick(t){if(!this.timeDilation)return;const e=this._currentTick;if((this._currentTick+=this.timeDilation)-e<1)return;const s=this._timeStamp,n=((this._timeStamp=Date.now())-s)*this.timeDilation;this._handleTick(t,n)}start(e){this._timeStamp=Date.now(),this._run=t.runInterval(this.executeTick.bind(this,e))}stop(){t.clearRun(this._run)}timeDilation=1};X=q([O],X);let Y=class extends U{scheduler=new X;getScheduler(){return this.scheduler}};Y=q([O],Y);class B{level;setLevel(t){return this.level?.stop?.(),t.start(),this.level=t}getLevel(){return this.level}onStart(e){this.setLevel(new Y),t.runTimeout(()=>this.afterStart(),1)}shutdown(){this.level?.stop?.()}afterStart(){}}class W extends _{playerRef=a.none();static{e.afterEvents.playerButtonInput.subscribe(t=>{const e=A()?.getLevel()?.getManager(t.player.id).getComponentUnsafe(W);e?.inputKey(t.button,t.newButtonState===s.Pressed)})}onTick(){this.playerRef.isEmpty()?this.getEntity().use(t=>this.playerRef=P.toPlayer(t)):this.syncAxisAndButtons()}syncAxisAndButtons(){const t=this.playerRef.unwrap().inputInfo,{x:e,y:s}=t.getMovementVector();this.inputAxis("Movement",[e,s])}}class G extends h{hud;actor=a.none();onTick(t){this.hud=this.render(),this.draw()}}class Q extends G{draw(){if(this.actor.isEmpty())return void(this.actor=P.toPlayer(this.getEntity().unwrap()));this.actor.unwrap().runCommand(`title @s actionbar ${this.hud}`)}}class J{static map=new Map;HEAD={prev:null,next:null};END=this.HEAD;count=0;append(t,e){const s=this.END,n={prev:s,listener:t,rawListener:e,next:null};return n.prev=s,n.listener=t,n.rawListener=e,n.next=null,s.next=n,this.END=n,J.map.set(e||t,n),this.count++,this}prepend(t,e){const s=this.HEAD,n=s.next,r={prev:s,listener:t,rawListener:e,next:n};return s.next=r,n&&(n.prev=r),J.map.set(e||t,r),this.count++,this}delete(t){let e=J.map,s=e.get(t);if(!s)return;let n=s.prev;return n.next=s.next,s.next&&(s.next.prev=n),e.delete(t),this.count--,requestIdleCallback(()=>{s.prev=null,s.next=null}),this}deleteAll(){let t=this.HEAD;for(;t=t.next;)t.prev=null,t.next=null,J.map.delete(t.rawListener||t.listener);return this.HEAD.next=null,this.count=0,this}[Symbol.iterator](){let t=this.HEAD;return{next:()=>t.next?(t=t.next,{value:t,done:!1}):{value:t,done:!0}}}}const tt=new class{_events={};maxListeners=-1;thisArg=void 0;captureRejections=!1;setMaxListeners(t){return this.maxListeners=t,this}getMaxListeners(){return this.maxListeners}_addListener(t,e,s=!1){let n;if(!~this.maxListeners&&this.listenerCount(t)===this.maxListeners){const t=RangeError(`Exceeded maximum capacity(${this.maxListeners}).`);if(!this.listenerCount("error"))throw t;this._emitError(t)}this._events[t]||(this._events[t]=new J),n=this._events[t],s?n.prepend(e):n.append(e)}addListener(t,e){return this._addListener(t,e),this}on(t,e){return this._addListener(t,e),this}prependListener(t,e){return this._addListener(t,e,!0),this}_removeListener(t,e){let s;(s=this._events[t])&&(s.delete(e),s.count||delete this._events[t])}removeListener(t,e){return this._removeListener(t,e),this}off(t,e){return this._removeListener(t,e),this}removeAllListeners(t){let e;(e=this._events[t])&&(e.deleteAll(),delete this._events[t])}_emit(t,e,s){let n;if(n=this._events[t],n)try{let t=this.captureRejections,r=n.HEAD;for(;r=r.next;){const n=r.listener.apply(e,s);t&&n instanceof Promise&&n.catch(t=>{if(!this.listenerCount("error"))throw t;this._emitError(t)})}}catch(t){if(!this.listenerCount("error"))throw t;this._emitError(t)}}_emitError(t){this._emit("error",void 0,[t])}emit(t,...e){this._emit(t,this.thisArg,e)}emitNone(t,...e){this._emit(t,void 0,e)}bind(t){return this.thisArg=t,this}_onceWrapper(t,e){return(...s)=>{this._removeListener(t,e);return e.apply(this.thisArg,s)}}_once(t,e,s=!1){if(!~this.maxListeners&&this.listenerCount(t)===this.maxListeners){const t=RangeError(`Exceeded maximum capacity(${this.maxListeners}).`);if(!this.listenerCount("error"))throw t;this._emitError(t)}const n=this._onceWrapper(t,e);let r;this._events[t]||(this._events[t]=new J),r=this._events[t],s?r.prepend(n,e):r.append(n,e)}once(t,e){return this._once(t,e),this}prependOnceListener(t,e){return this._once(t,e,!0),this}listenerCount(t){let e;return e=this._events[t],e?e.count:0}listeners(t){let e,s=[];if(e=this._events[t],!e)return s;let n=e.HEAD;for(;n=n.next;)s.push(n.listener);return s}rawListeners(t){let e,s=[];if(e=this._events[t],!e)return s;let n=e.HEAD;for(;n=n.next;)n.rawListener&&s.push(n.rawListener);return s}eventNames(){return Object.getOwnPropertyNames(this._events)}constructor(t){if(t){const{thisArg:e,captureRejections:s}=t;void 0!==e&&(this.thisArg=e),s&&(this.captureRejections=!0)}}};t.afterEvents.scriptEventReceive.subscribe(t=>{tt.emitNone(t.id,t)});const et=t=>(e,s)=>{tt.on(t,e[s])};et.on=(t,e)=>{tt.on(t,e)},et.off=(t,e)=>{tt.off(t,e)};const st={onRandomTick({block:t}){if(Math.random()>1/3)return;const e=t.permutation.getState("sapdon:block_variant_tag");t.setPermutation(t.permutation.withState("sapdon:block_variant_tag",e+1))},onPlayerInteract({block:t,dimension:e,player:s}){if(!s)return;const i=s.getComponent("minecraft:equippable");if(!i)return;const o=i.getEquipmentSlot(n.Mainhand);if(!o.hasItem()||"minecraft:bone_meal"!==o.typeId)return;if(s.getGameMode()===r.Creative)t.setPermutation(t.permutation.withState("sapdon:block_variant_tag",3));else{let e=t.permutation.getState("sapdon:block_variant_tag");e+=(a=1,m=3-e,Math.floor(Math.random()*(m-a+1))+a),t.setPermutation(t.permutation.withState("sapdon:block_variant_tag",e)),o.amount>1?o.amount--:o.setItem(void 0)}var a,m;const c=t.center();e.playSound("item.bone_meal.use",c),e.spawnParticle("minecraft:crop_growth_emitter",c)}},nt={onTick(s){const{block:n,dimension:r}=s;if(!n.below()||!n.below()?.isAir)return;e.sendMessage("是空气");const i={x:n.location.x+.5,y:n.location.y,z:n.location.z+.5};n.setType("minecraft:air"),t.runTimeout(()=>{const s=r.spawnEntity("sapdon:fallingblock_entity",i);s.applyImpulse({x:0,y:-.5,z:0});const n=t.runInterval(()=>{if(!s?.isValid)return e.sendMessage("实体无效移除"),void t.clearRun(n);{const i=s.getVelocity(),o=s.location;0===i.y&&(e.sendMessage("在地面上,速度为零"),r.setBlockType(o,"sapdon:fallingblock"),s.remove(),t.clearRun(n))}},10)},1)}},rt={onPlayerInteract({block:t,dimension:e,player:s}){if(!s)return;const n=t.permutation,r=((n.getState("sapdon:head_rotation")??0)+1)%16;t.setPermutation(n.withState("sapdon:head_rotation",r)),e.playSound("random.click",t.center())}};const it={beforeOnPlayerPlace(t,{params:e}){const{player:s}=t;if(!s)return;const n=e?.y_rotation_offset??0,r=function(t){return(t%=360)<0&&(t+=360),Math.round(t/22.5)%16}(s.getRotation().y+n);t.permutationToPlace=t.permutationToPlace.withState("sapdon:head_rotation",r)}},ot={"sapdon:neo_guidebook":"neo_guidebook","minecraft:stick":"test_book"};let at=0;function mt(t,s){const n=(new i).title(s).body("page_index"+at).button("prev_button").button("next_button").button("test3").button("test4");0!=at&&n.button("home_button"),n.show(t).then(n=>{0===n.selection?(at--,e.sendMessage("上一页"),mt(t,s)):1===n.selection?(at++,e.sendMessage("下一页"),mt(t,s)):2===n.selection?(at=1,e.sendMessage("章节跳转至 章节1"),mt(t,s)):3===n.selection?(at=2,e.sendMessage("章节跳转至 章节2"),mt(t,s)):4===n.selection&&(at=0,e.sendMessage("返回目录"),mt(t,s))})}const ct={onUse({itemStack:t,source:e}){"minecraft:player"==e.typeId&&t&&mt(e,ot[t.typeId])}};function ht(){t.beforeEvents.startup.subscribe(t=>{t.blockComponentRegistry.registerCustomComponent("sapdon:crop_growth",st),t.blockComponentRegistry.registerCustomComponent("sapdon:fallingblock",nt),t.blockComponentRegistry.registerCustomComponent("sapdon:head_rotation",rt),t.blockComponentRegistry.registerCustomComponent("sapdon:intercardinal_orientation",it),t.itemComponentRegistry.registerCustomComponent("sapdon:guibook",ct)})}export{K as ActorSpawned,u as BaseComponent,l as ComponentManager,h as CustomComponent,H as EntitySpawned,S as GameInstance,G as HudComponent,v as MathExt,x as Matrix,O as Minecraft,B as MinecraftGameInstance,Y as MinecraftLevel,D as MinecraftMain,L as MinecraftMethod,W as MinecraftPlayerInputComponent,X as MinecraftTickingScheduler,a as Optional,Q as PlayerHudComponent,_ as PlayerInputComponent,N as PlayerSpawned,d as RequireComponents,et as ScriptEvent,V as SpawnFilter,g as Vec3,w as Vec4,F as assertInMinecraft,E as finalize,A as getGameInstance,C as getGameInstanceClass,k as initialize,f as lazyGet,ht as registerBuiltinComponents,P as utils};
|
|
1
|
+
import{system as t,world as e,ButtonState as n,EquipmentSlot as s,GameMode as r}from"@minecraft/server";import{ActionFormData as i}from"@minecraft/server-ui";const o=Symbol("isOptional");class a{value;static none(){return new a(null)}static some(t){return new a(t)}constructor(t){this.value=t}[o]=o;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){if(!this.isEmpty()){const n=t.call(e,this.value);return n[o]?n:a.some(t.call(e,this.value))}return a.none()}}const c=Symbol("reflect-manager"),m=Symbol("reflect-entity");class h{[c];[m]=a.none();onTick(t){}detach(){const t=Object.getPrototypeOf(this).constructor;return this.getManager().detachComponent(t)}getManager(){return this[c]}getEntity(){return this[m]}lazyGet(t){return f(this,t)}}class u extends h{onAttach(t){}onDetach(t){}}class l{static profilerEnable=!1;static global=new l;#t=new Map;#e=[];#n=[];getComponentUnsafe(t){return this.#t.get(t)}getComponent(t){return a.some(this.#t.get(t))}getComponents(...t){return t.map(t=>this.#t.get(t))}#s(t,e,n=!0){e[c]||(e[c]=this);let s=!this.#t.get(t);if(!s&&n&&(this.detachComponent(t),s=!0),p in e)for(const[t,n]of e[p])e.getManager().getComponentUnsafe(t)||this.#s(t,n,!1);return s&&"onAttach"in e&&e.onAttach(this),this.#t.set(t,e),a.some(e)}attachComponent(...t){const e=[];for(const n of t)e.push(this.#s(Object.getPrototypeOf(n).constructor,n));return e}async getOrCreate(t,...e){let n=this.#t.get(t);return n?a.some(n):this.#s(t,new t(...e))}detachComponent(t){const e=this.#t.get(t);return e&&"onDetach"in e&&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,e){for(const e of this.#e)this.profiler(()=>e.call(null,a.some(t)));this.#e.length=0;for(const n of this.#t.values()){n[m].isEmpty()&&(n[m]=a.some(t));const{onTick:s}=n;s&&this.profiler(()=>s.call(n,e),n)}for(const e of this.#n)this.profiler(()=>e.call(null,a.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(!l.profilerEnable)return t();const s=e?Object.getPrototypeOf(e).constructor.name:"",r=n||(s?`${s}.${t.name}`:t.name),i=performance.now(),o=t();return console.log(`[Profiler] ${r} took ${performance.now()-i}ms`),o}}const p=Symbol("REQUIRED_COMPONENTS");function d(...t){return class extends u{[p]=new Map;constructor(){super();for(const e of t){if(Array.isArray(e)){const[t,...n]=e;this[p].set(t,Reflect.construct(t,n));continue}this[p].set(e,Reflect.construct(e,[]))}}getComponent(t){return this[p].get(t)}}}function f(t,e){let n=null;return new Proxy(Object.create(Object.prototype),{get:(s,r)=>(n||(n=t.getManager().getComponentUnsafe(e)),n[r]),set:(s,r,i)=>n?(n[r]=i,!0):(n=t.getManager().getComponentUnsafe(e),n[r]=i,!0)})}const y=["onBlockStateChange","onBreak","onEntity","onEntityFallOn","onPlace","onPlayerBreak","onPlayerInteract","onRandomTick","onRedstoneUpdate","onStepOff","onStepOn","onTick","beforeOnPlayerPlace"],g=["onBeforeDurabilityDamage","onCompleteUse","onConsume","onHitEntity","onMineBlock","onUse","onUseOn"];function w(t,e,n,s){if(!e||"string"!=typeof e)throw new Error(`register${"block"===t?"Block":"Item"}Component: id 必须是非空字符串`);if("object"!=typeof n||null===n||Array.isArray(n))throw new Error(`register${"block"===t?"Block":"Item"}Component("${e}"): handlers 必须是对象`);const r=Object.keys(n);if(0===r.length)throw new Error(`register${"block"===t?"Block":"Item"}Component("${e}"): handlers 不能为空对象`);for(const i of r){if("function"!=typeof n[i])throw new Error(`register${"block"===t?"Block":"Item"}Component("${e}"): handler "${i}" 不是函数`);s.includes(i)||console.warn(`[sapdon] 组件 "${e}" 的 handler "${i}" 不在已知的${"block"===t?"方块":"物品"}事件里,可能是拼写错误。已知:${s.join(", ")}`)}}const x=new Set,b=new Set,v=new Set,k=new Set,_=[],E=[];let $=!1,C=!1;const z=[],M=[];function S(){if($)return;$=!0;const e=t?.beforeEvents?.startup;if(!e||"function"!=typeof e.subscribe)throw new Error("[sapdon] 当前 @minecraft/server 没有 system.beforeEvents.startup,无法保证自定义组件的注册时机。\n请把 build.config 的 dependencies 里 @minecraft/server 升级到 2.x;或改用构建期路线 A(BlockCustomComponentBuilder + CLI 生成的 scripts/custom_components/index.js)。");e.subscribe(t=>{C=!0;for(const e of _)P(t,e);_.length=0;for(const e of E){if(("block"===e.kind?x:b).has(e.id)){const t=`${e.kind}:${e.id}`;M.push(t),console.warn(`[sapdon] 内置组件 "${t}" 已由项目注册 —— 跳过框架内置实现,**项目的实现生效**。(这是正常的,不是错误:项目实现取代内置实现。)`);continue}P(t,e)}E.length=0})}function P(t,e){("block"===e.kind?t.blockComponentRegistry:t.itemComponentRegistry).registerCustomComponent(e.id,e.handlers),z.push(`${e.kind}:${e.id}`)}function A(t,e,n,s=!1){if(C)throw new Error(`[sapdon] 自定义组件 "${e}" 注册得太晚:system.beforeEvents.startup 已经触发过了。\n组件只能在脚本**模块加载期**声明(顶层语句)。请把 registerBlockComponent/registerItemComponent 移到脚本顶层,不要在事件回调/定时器里调用。`);if(s){const s="block"===t?v:k;if(s.has(e))return;return s.add(e),S(),void E.push({kind:t,id:e,handlers:n})}const r="block"===t?x:b;if(r.has(e))throw new Error(`[sapdon] 自定义组件 "${e}" 被重复注册(同一个 id 只能用一条路线注册一次)`);r.add(e),S(),_.push({kind:t,id:e,handlers:n})}function R(t,e){w("block",t,e,y),A("block",t,e)}function L(t,e){w("item",t,e,g),A("item",t,e)}function T(t,e){w("block",t,e,y),A("block",t,e,!0)}function D(t,e){w("item",t,e,g),A("item",t,e,!0)}function I(){return _.length}function O(){return[...z]}function F(){return[...M]}class j extends Array{constructor(t){super(),Array.isArray(t)&&this.set(t)}set(t){let e=0;for(const n of t)this[e]=n,e++}}class B extends j{x=0;y=0;z=0;constructor(t){super(t),this.x=t[0]||0,this.y=t[1]||0,this.z=t[2]||0}static fromXYZ(t,e,n){return new B([t,e,n])}static fromVec3(t){return new B([t.x,t.y,t.z])}static m(t){const{x:e,y:n,z:s}=t;return Math.sqrt(e*e+n*n+s*s)}m(){return B.m(this)}static isZero(t){return 0===t.x&&0===t.y&&0===t.z}isZero(){return B.isZero(this)}static normalize(t){if(this.isZero(t))return!1;const{x:e,y:n,z:s}=t,r=this.m(t);t.x=e/r,t.y=n/r,t.z=s/r}n(){return B.normalize(this)}static add(t,e){return new B([t.x+e.x,t.y+e.y,t.z+e.z])}add(t){return B.add(this,t)}static sub(t,e){return new B([t.x-e.x,t.y-e.y,t.z-e.z])}sub(t){return B.sub(this,t)}static mul(t,e){return new B([t.x*e,t.y*e,t.z*e])}mul(t){return B.mul(this,t)}static div(t,e){return new B([t.x/e,t.y/e,t.z/e])}div(t){return B.div(this,t)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}dot(t){return B.dot(this,t)}static cross(t,e){return new B([t.y*e.z-t.z*e.y,t.z*e.x-t.x*e.z,t.x*e.y-t.y*e.x])}cross(t){return B.cross(this,t)}valueOf(){return new j([this.x,this.y,this.z])}toString(){return`(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.z.toFixed(2)})`}}class N extends j{constructor(){super([].fill(0,0,16)),this.fill(0)}get m11(){return this[0]}get m12(){return this[1]}get m13(){return this[2]}get m14(){return this[3]}get m21(){return this[4]}get m22(){return this[5]}get m23(){return this[6]}get m24(){return this[7]}get m31(){return this[8]}get m32(){return this[9]}get m33(){return this[10]}get m34(){return this[11]}get m41(){return this[12]}get m42(){return this[13]}get m43(){return this[14]}get m44(){return this[15]}set m11(t){this[0]=t}set m12(t){this[1]=t}set m13(t){this[2]=t}set m14(t){this[3]=t}set m21(t){this[4]=t}set m22(t){this[5]=t}set m23(t){this[6]=t}set m24(t){this[7]=t}set m31(t){this[8]=t}set m32(t){this[9]=t}set m33(t){this[10]=t}set m34(t){this[11]=t}set m41(t){this[12]=t}set m42(t){this[13]=t}set m43(t){this[14]=t}set m44(t){this[15]=t}get a(){return this.m11}get b(){return this.m12}get c(){return this.m21}get d(){return this.m22}get e(){return this.m41}get f(){return this.m42}set a(t){this.m11=t}set b(t){this.m12=t}set c(t){this.m21=t}set d(t){this.m22=t}set e(t){this.m41=t}set f(t){this.m42=t}static init(t,e,n){const s=j.from(t,e,n),r=new N;return r.set(s),r}clone(){return N.init(this.slice(),t=>t)}setIdentity(){return this.set([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this}static identity(){const t=new N;return t.setIdentity(),t}static add(t,e){const n=new N;return n.set(t.map((t,n)=>t+e[n])),n}add(t){return N.add(this,t)}static sub(t,e){const n=new N;return n.set(t.map((t,n)=>t-e[n])),n}sub(t){return N.sub(this,t)}setTranslation(t,e,n){return this.m14=t,this.m24=e,this.m34=n,this}setRotation(t,e){B.normalize(e);const n=Math.sin(t),s=Math.cos(t),r=e.x,i=e.y,o=e.z,a=1-s,c=a*r*r+s,m=a*r*i-n*o,h=a*r*o+n*i,u=a*r*i+n*o,l=a*i*i+s,p=a*i*o-n*r,d=a*r*o-n*i,f=a*i*o+n*r,y=a*o*o+s;return this.m11=c,this.m12=m,this.m13=h,this.m21=u,this.m22=l,this.m23=p,this.m31=d,this.m32=f,this.m33=y,this}setScale(t,e,n){return this.m11*=t,this.m22*=e,this.m33*=n,this}setRotationX(t){const e=Math.sin(t),n=Math.cos(t);return this.m11=1,this.m12=0,this.m13=0,this.m21=0,this.m22=n,this.m23=e,this.m31=0,this.m32=-e,this.m33=n,this}setRotationY(t){const e=Math.sin(t),n=Math.cos(t);return this.m11=n,this.m12=0,this.m13=-e,this.m21=0,this.m22=1,this.m23=0,this.m31=e,this.m32=0,this.m33=n,this}setRotationZ(t){const e=Math.sin(t),n=Math.cos(t);return this.m11=n,this.m12=e,this.m13=0,this.m21=-e,this.m22=n,this.m23=0,this.m31=0,this.m32=0,this.m33=1,this}setRotationXYZ(t,e,n){const s=Math.sin(t),r=Math.cos(t),i=Math.sin(e),o=Math.cos(e),a=Math.sin(n),c=Math.cos(n);return this.m11=r*c+s*i*a,this.m12=r*a-s*i*c,this.m13=s*o,this.m21=s*c-r*i*a,this.m22=r*c-s*i*c,this.m23=r*i,this.m31=s*a+r*i*c,this.m32=-s*c+r*i*a,this.m33=r*o,this}static translate(t,e){const{x:n,y:s,z:r}=e,i=t.clone();return i.m14=i.m11*n+i.m21*s+i.m31*r+n,i.m24=i.m21*n+i.m22*s+i.m32*r+s,i.m34=i.m31*n+i.m32*s+i.m33*r+r,i}translate(t){return N.translate(this,t)}static transpose(t){return this.from([t.m11,t.m21,t.m31,t.m41,t.m12,t.m22,t.m32,t.m42,t.m13,t.m23,t.m33,t.m43,t.m14,t.m24,t.m34,t.m44])}transpose(){return N.transpose(this)}static multiply(t,e){return e instanceof N?this.from([t.m11*e.m11+t.m12*e.m21+t.m13*e.m31+t.m14*e.m41,t.m11*e.m12+t.m12*e.m22+t.m13*e.m32+t.m14*e.m42,t.m11*e.m13+t.m12*e.m23+t.m13*e.m33+t.m14*e.m43,t.m11*e.m14+t.m12*e.m24+t.m13*e.m34+t.m14*e.m44,t.m21*e.m11+t.m22*e.m21+t.m23*e.m31+t.m24*e.m41,t.m21*e.m12+t.m22*e.m22+t.m23*e.m32+t.m24*e.m42,t.m21*e.m13+t.m22*e.m23+t.m23*e.m33+t.m24*e.m43,t.m21*e.m14+t.m22*e.m24+t.m23*e.m34+t.m24*e.m44,t.m31*e.m11+t.m32*e.m21+t.m33*e.m31+t.m34*e.m41,t.m31*e.m12+t.m32*e.m22+t.m33*e.m32+t.m34*e.m42,t.m31*e.m13+t.m32*e.m23+t.m33*e.m33+t.m34*e.m43,t.m31*e.m14+t.m32*e.m24+t.m33*e.m34+t.m34*e.m44,t.m41*e.m11+t.m42*e.m21+t.m43*e.m31+t.m44*e.m41,t.m41*e.m12+t.m42*e.m22+t.m43*e.m32+t.m44*e.m42,t.m41*e.m13+t.m42*e.m23+t.m43*e.m33+t.m44*e.m43,t.m41*e.m14+t.m42*e.m24+t.m43*e.m34+t.m44*e.m44]):new Z([t.m11*e.x+t.m12*e.y+t.m13*e.z+t.m14*e.w,t.m21*e.x+t.m22*e.y+t.m23*e.z+t.m24*e.w,t.m31*e.x+t.m32*e.y+t.m33*e.z+t.m34*e.w,t.m41*e.x+t.m42*e.y+t.m43*e.z+t.m44*e.w])}multiply(t){return N.multiply(this,t)}valueOf(){return new j(this)}toString(){return`${this.m11.toFixed(2)}\t${this.m12.toFixed(2)}\t${this.m13.toFixed(2)}\t${this.m14.toFixed(2)}\n${this.m21.toFixed(2)}\t${this.m22.toFixed(2)}\t${this.m23.toFixed(2)}\t${this.m24.toFixed(2)}\n${this.m31.toFixed(2)}\t${this.m32.toFixed(2)}\t${this.m33.toFixed(2)}\t${this.m34.toFixed(2)}\n${this.m41.toFixed(2)}\t${this.m42.toFixed(2)}\t${this.m43.toFixed(2)}\t${this.m44.toFixed(2)}\n`}static perspective(t,e,n,s){const r=Math.tan(t/2),i=r*e;return N.from([n/i,0,0,0,0,1/r,0,0,0,0,-(n+s)/(s-n),-2*s*n/(s-n),0,0,-1,0])}static orthographic(t,e,n,s){return N.from([1/t,0,0,0,0,1/e,0,0,0,0,-2/(s-n),-(s+n)/(s-n),0,0,0,1])}static lookAt(t,e,n){const s=B.sub(e,t);s.n();const r=B.cross(n,s);r.n();const i=B.cross(s,r);return i.n(),N.from([r.x,r.y,r.z,-B.dot(r,t),i.x,i.y,i.z,-B.dot(i,t),s.x,s.y,s.z,-B.dot(s,t),0,0,0,1])}}class Z extends j{x=0;y=0;z=0;w=0;constructor(t){super(t),this.x=t[0]||0,this.y=t[1]||0,this.z=t[2]||0,this.w=t[3]||0}static fromXYZW(t,e,n,s){return new Z([t,e,n,s])}static fromVec3(t){return new Z([t.x,t.y,t.z])}static fromVec4(t){return new Z([t.x,t.y,t.z,t.w])}static m(t){const{x:e,y:n,z:s,w:r}=t;return Math.sqrt(e*e+n*n+s*s+r*r)}m(){return Z.m(this)}static isZero(t){return 0===t.x&&0===t.y&&0===t.z&&0===t.w}isZero(){return Z.isZero(this)}static normalize(t){if(this.isZero(t))return!1;const{x:e,y:n,z:s,w:r}=t,i=this.m(t);t.x=e/i,t.y=n/i,t.z=s/i,t.w=r/i}n(){return Z.normalize(this)}static add(t,e){return new Z([t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w])}add(t){return Z.add(this,t)}static sub(t,e){return new Z([t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w])}sub(t){return Z.sub(this,t)}static mul(t,e){return new Z([t.x*e,t.y*e,t.z*e,t.w*e])}mul(t){return Z.mul(this,t)}static div(t,e){return new Z([t.x/e,t.y/e,t.z/e,t.w/e])}div(t){return Z.div(this,t)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z+t.w*e.w}dot(t){return Z.dot(this,t)}static multiply(t,e){return N.multiply(e,t)}multiply(t){return Z.multiply(this,t)}valueOf(){return new j([this.x,this.y,this.z,this.w])}toString(){return`(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.z.toFixed(2)}, ${this.w.toFixed(2)})`}}var U;!function(t){function e(t,e,n){return t+(e-t)*n}function n(t,n,s){return B.fromXYZ(e(t.x,n.x,s),e(t.y,n.y,s),e(t.z,n.z,s))}function s(t,n,s){return Z.fromXYZW(e(t.x,n.x,s),e(t.y,n.y,s),e(t.z,n.z,s),e(t.w,n.w,s))}t.clamp=function(t,e,n){return Math.min(Math.max(t,e),n)},t.lerps=e,t.lerpVec3=n,t.lerpVec4=s,t.lerp=function(t,r,i){return"number"==typeof t?e(t,r,i):"w"in t?s(t,r,i):n(t,r,i)}}(U||(U={}));class H{pressing;times;constructor(t=!1,e=0){this.pressing=t,this.times=e}consume(){this.times--}}class K extends u{keyStateMapping=new Map;axisMapping=new Map;inputKey(t,e){let n=this.keyStateMapping.get(t)??new H;e?(n.pressing=!0,n.times++):(n.pressing=!1,n.times--),this.keyStateMapping.set(t,n)}inputAxis(t,e){this.axisMapping.set(t,e)}getKeyState(t){return this.keyStateMapping.get(t)}getAxis(t){return this.axisMapping.get(t)}getKeyPressing(t){return this.getKeyState(t)?.pressing??!1}getKeyPressTimes(t){return this.getKeyState(t)?.times??0}exhaust(t){const e=this.getKeyState(t);e&&(e.times=0)}combineAxis(t,e){return Array.isArray(t)||(t=[t]),Array.isArray(e)||(e=[e]),t.concat(e)}splitAxis(t,e,n){return e=U.clamp(e,0,t.length-1),n||(n=t.length-e),[t.slice(0,e),t.slice(e,e+n)]}}let V,q;function X(t,e={}){q=Reflect.construct(t,[]),q?.onStart?.(e)}function Y(t){t?.shutdown?.()}const W=t=>{V=t};function G(){return V}function J(){return q}var Q=function(t,e,n,s){var r,i=arguments.length,o=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(i<3?r(o):i>3?r(e,n,o):r(e,n))||o);return i>3&&o&&Object.defineProperty(e,n,o),o};function tt(t,e,n){const s=n.value;return n.value=(...e)=>(rt(),s.apply(t,e)),n}class et{toPlayer(t){return a.some(t)}start(){t?.beforeEvents?.startup&&(t.beforeEvents.startup.subscribe(t=>{const e=G();if(!e)throw new Error("No game instance class found");X(e,t)}),t.beforeEvents.shutdown.subscribe(t=>{const e=J();e&&Y(e)})),e?.beforeEvents?.worldInitialize&&e.beforeEvents.worldInitialize.subscribe(t=>{const e=G();if(!e)throw new Error("No game instance class found");X(e,t)})}}Q([tt],et.prototype,"toPlayer",null),Q([tt],et.prototype,"start",null);const nt=new et;function st(t){return t?.[Symbol.metadata]}function rt(){if(!e)throw new Error("Not running in the Minecraft host environment. required @minecraft/server")}Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));const it=t=>new Proxy(t,{construct:(t,e)=>(rt(),Reflect.construct(t,e))}),ot=t=>{rt(),W(t),nt.start(),e.afterEvents.playerSpawn.subscribe(t=>J()?.getLevel().getManager(t.player.id).attachComponent(...at(ct).filter(e=>st(e)?.spawnFilter?.(t.player)??!0).map(t=>Reflect.construct(t,[])))),e.afterEvents.entitySpawn.subscribe(t=>{"minecraft:player"!==t.entity.typeId&&J()?.getLevel().getManager(t.entity.id).attachComponent(...at(mt).filter(e=>st(e)?.spawnFilter?.(t.entity)??!0).map(t=>Reflect.construct(t,[])))})};function at(t){return Array.from(new Set(t))}const ct=[],mt=[],ht=(...t)=>e=>{ct.push(...t,e)},ut=(...t)=>e=>{mt.push(...t,e)},lt=(...t)=>e=>{ct.push(...t,e),mt.push(...t,e)},pt=t=>e=>{const n=function(t){if(null==t)return;return t?.[Symbol.metadata]??(t[Symbol.metadata]={})}(e);n.spawnFilter=t};class dt{table=new Map;addEntity(t){const e=new l;return this.table.set(t,e),e}removeEntity(t){const e=t,n=this.table.get(e);n?.clear(),this.table.delete(e)}getManager(t){return this.table.get(t)??this.addEntity(t)}start(){this.getScheduler().start(this.table)}stop(){this.getScheduler().stop()}}var ft=function(t,e,n,s){var r,i=arguments.length,o=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(i<3?r(o):i>3?r(e,n,o):r(e,n))||o);return i>3&&o&&Object.defineProperty(e,n,o),o};let yt=class{_run=0;_currentTick=0;_timeStamp=0;get currentTick(){return this._currentTick}_handleTick(t,n){for(const[s,r]of t.entries()){const t=e.getEntity(s);t&&r.handleTicks(t,n)}}executeTick(t){if(!this.timeDilation)return;const e=this._currentTick;if((this._currentTick+=this.timeDilation)-e<1)return;const n=this._timeStamp,s=((this._timeStamp=Date.now())-n)*this.timeDilation;this._handleTick(t,s)}start(e){this._timeStamp=Date.now(),this._run=t.runInterval(this.executeTick.bind(this,e))}stop(){t.clearRun(this._run)}timeDilation=1};yt=ft([it],yt);let gt=class extends dt{scheduler=new yt;getScheduler(){return this.scheduler}};gt=ft([it],gt);class wt{level;setLevel(t){return this.level?.stop?.(),t.start(),this.level=t}getLevel(){return this.level}onStart(e){this.setLevel(new gt),t.runTimeout(()=>this.afterStart(),1)}shutdown(){this.level?.stop?.()}afterStart(){}}class xt extends K{playerRef=a.none();static{e.afterEvents.playerButtonInput.subscribe(t=>{const e=J()?.getLevel()?.getManager(t.player.id).getComponentUnsafe(xt);e?.inputKey(t.button,t.newButtonState===n.Pressed)})}onTick(){this.playerRef.isEmpty()?this.getEntity().use(t=>this.playerRef=nt.toPlayer(t)):this.syncAxisAndButtons()}syncAxisAndButtons(){const t=this.playerRef.unwrap().inputInfo,{x:e,y:n}=t.getMovementVector();this.inputAxis("Movement",[e,n])}}class bt extends h{hud;actor=a.none();onTick(t){this.hud=this.render(),this.draw()}}class vt extends bt{draw(){if(this.actor.isEmpty())return void(this.actor=nt.toPlayer(this.getEntity().unwrap()));this.actor.unwrap().runCommand(`title @s actionbar ${this.hud}`)}}class kt{static map=new Map;HEAD={prev:null,next:null};END=this.HEAD;count=0;append(t,e){const n=this.END,s={prev:n,listener:t,rawListener:e,next:null};return s.prev=n,s.listener=t,s.rawListener=e,s.next=null,n.next=s,this.END=s,kt.map.set(e||t,s),this.count++,this}prepend(t,e){const n=this.HEAD,s=n.next,r={prev:n,listener:t,rawListener:e,next:s};return n.next=r,s&&(s.prev=r),kt.map.set(e||t,r),this.count++,this}delete(t){let e=kt.map,n=e.get(t);if(!n)return;let s=n.prev;return s.next=n.next,n.next&&(n.next.prev=s),e.delete(t),this.count--,requestIdleCallback(()=>{n.prev=null,n.next=null}),this}deleteAll(){let t=this.HEAD;for(;t=t.next;)t.prev=null,t.next=null,kt.map.delete(t.rawListener||t.listener);return this.HEAD.next=null,this.count=0,this}[Symbol.iterator](){let t=this.HEAD;return{next:()=>t.next?(t=t.next,{value:t,done:!1}):{value:t,done:!0}}}}const _t=new class{_events={};maxListeners=-1;thisArg=void 0;captureRejections=!1;setMaxListeners(t){return this.maxListeners=t,this}getMaxListeners(){return this.maxListeners}_addListener(t,e,n=!1){let s;if(!~this.maxListeners&&this.listenerCount(t)===this.maxListeners){const t=RangeError(`Exceeded maximum capacity(${this.maxListeners}).`);if(!this.listenerCount("error"))throw t;this._emitError(t)}this._events[t]||(this._events[t]=new kt),s=this._events[t],n?s.prepend(e):s.append(e)}addListener(t,e){return this._addListener(t,e),this}on(t,e){return this._addListener(t,e),this}prependListener(t,e){return this._addListener(t,e,!0),this}_removeListener(t,e){let n;(n=this._events[t])&&(n.delete(e),n.count||delete this._events[t])}removeListener(t,e){return this._removeListener(t,e),this}off(t,e){return this._removeListener(t,e),this}removeAllListeners(t){let e;(e=this._events[t])&&(e.deleteAll(),delete this._events[t])}_emit(t,e,n){let s;if(s=this._events[t],s)try{let t=this.captureRejections,r=s.HEAD;for(;r=r.next;){const s=r.listener.apply(e,n);t&&s instanceof Promise&&s.catch(t=>{if(!this.listenerCount("error"))throw t;this._emitError(t)})}}catch(t){if(!this.listenerCount("error"))throw t;this._emitError(t)}}_emitError(t){this._emit("error",void 0,[t])}emit(t,...e){this._emit(t,this.thisArg,e)}emitNone(t,...e){this._emit(t,void 0,e)}bind(t){return this.thisArg=t,this}_onceWrapper(t,e){return(...n)=>{this._removeListener(t,e);return e.apply(this.thisArg,n)}}_once(t,e,n=!1){if(!~this.maxListeners&&this.listenerCount(t)===this.maxListeners){const t=RangeError(`Exceeded maximum capacity(${this.maxListeners}).`);if(!this.listenerCount("error"))throw t;this._emitError(t)}const s=this._onceWrapper(t,e);let r;this._events[t]||(this._events[t]=new kt),r=this._events[t],n?r.prepend(s,e):r.append(s,e)}once(t,e){return this._once(t,e),this}prependOnceListener(t,e){return this._once(t,e,!0),this}listenerCount(t){let e;return e=this._events[t],e?e.count:0}listeners(t){let e,n=[];if(e=this._events[t],!e)return n;let s=e.HEAD;for(;s=s.next;)n.push(s.listener);return n}rawListeners(t){let e,n=[];if(e=this._events[t],!e)return n;let s=e.HEAD;for(;s=s.next;)s.rawListener&&n.push(s.rawListener);return n}eventNames(){return Object.getOwnPropertyNames(this._events)}constructor(t){if(t){const{thisArg:e,captureRejections:n}=t;void 0!==e&&(this.thisArg=e),n&&(this.captureRejections=!0)}}};t.afterEvents.scriptEventReceive.subscribe(t=>{_t.emitNone(t.id,t)});const Et=t=>(e,n)=>{_t.on(t,e[n])};Et.on=(t,e)=>{_t.on(t,e)},Et.off=(t,e)=>{_t.off(t,e)};const $t=24e3,Ct="#",zt=256;function Mt(t,e){return`${t}${Ct}${e}`}function St(t){return JSON.stringify({_chunks:t})}function Pt(t){if("string"!=typeof t||t.length<2||"{"!==t[0])return;let e;try{e=JSON.parse(t)}catch{return}if("object"!=typeof e||null===e||Array.isArray(e))return;const n=Object.keys(e);if(1!==n.length||"_chunks"!==n[0])return;const s=e._chunks;return"number"!=typeof s||!Number.isInteger(s)||s<0?void 0:s}function At(t){return void 0!==Pt(t)}function Rt(t,e=24e3){if(!Number.isInteger(e)||e<1)throw new Error(`splitValue: size 必须是正整数,收到 ${e}`);if(0===t.length)return[""];const n=[];for(let s=0;s<t.length;s+=e)n.push(t.slice(s,s+e));return n}function Lt(t,e){if(!e.startsWith(t+Ct))return!1;const n=e.slice(t.length+1);return n.length>0&&/^\d+$/.test(n)}function Tt(t,e,n){if(function(t){return"function"==typeof t.getDynamicPropertyIds}(t))for(const s of t.getDynamicPropertyIds())Lt(e,s)&&(Number(s.slice(e.length+1))<n||t.setDynamicProperty(s,void 0));else for(let s=n;s<256;s++){const n=Mt(e,s);void 0!==t.getDynamicProperty(n)&&t.setDynamicProperty(n,void 0)}}function Dt(t,e,n){if(!e)throw new Error("saveChunked: key 不能为空");if("string"!=typeof n)throw new Error(`saveChunked: value 必须是字符串(收到 ${typeof n}),请自行序列化后再存`);if(n.length>$t||At(n)){const s=Rt(n,$t);for(let n=0;n<s.length;n++)t.setDynamicProperty(Mt(e,n),s[n]);return t.setDynamicProperty(e,St(s.length)),void Tt(t,e,s.length)}t.setDynamicProperty(e,n),Tt(t,e,0)}function It(t,e){if(!e)throw new Error("loadChunked: key 不能为空");const n=t.getDynamicProperty(e);if(void 0===n)return;if("string"!=typeof n)throw new Error(`loadChunked: 主 key "${e}" 存的是 ${typeof n},本接口只读写字符串`);const s=Pt(n);if(void 0===s)return n;if(0===s)return"";let r="";for(let n=0;n<s;n++){const i=t.getDynamicProperty(Mt(e,n));if("string"!=typeof i)throw new Error(`loadChunked: 分块存档损坏 —— 主 key "${e}" 声明 ${s} 块,但 "${Mt(e,n)}" 是 ${void 0===i?"缺失":typeof i}`);r+=i}return r}function Ot(t,e){if(!e)throw new Error("clearChunked: key 不能为空");Tt(t,e,0),t.setDynamicProperty(e,void 0)}const Ft={onPlace:function(t){const e=t.block;try{const t=`${e.typeId}_entity`,n=function(t,e){let n;try{n=t.dimension.getEntitiesAtBlockLocation(t.location)}catch(e){return void console.warn(`[sapdon] block_with_entity: 读 ${t.typeId} @${t.location.x},${t.location.y},${t.location.z} 的实体失败,本次不 spawn 承载实体(宁可没有容器,也不要两个容器)`,e)}for(const t of n)try{if(t.typeId===e)return!0}catch{}return!1}(e,t);if(!1!==n)return;const s=e.center(),r={x:s.x,y:s.y-.5,z:s.z};try{e.dimension.spawnEntity(t,r)}catch(n){console.warn(`[sapdon] block_with_entity: spawnEntity("${t}") 失败(${e.typeId} @${e.location.x},${e.location.y},${e.location.z})。请确认 ${t} 的**行为**文件存在(createTileBlock 会生成 entities/${t.replace(":","_")}.json)`,n)}}catch(t){console.warn(`[sapdon] block_with_entity.onPlace @${e?.typeId??"?"}`,t)}}},jt={onRandomTick({block:t}){if(Math.random()>1/3)return;const e=t.permutation.getState("sapdon:block_variant_tag");t.setPermutation(t.permutation.withState("sapdon:block_variant_tag",e+1))},onPlayerInteract({block:t,dimension:e,player:n}){if(!n)return;const i=n.getComponent("minecraft:equippable");if(!i)return;const o=i.getEquipmentSlot(s.Mainhand);if(!o.hasItem()||"minecraft:bone_meal"!==o.typeId)return;if(n.getGameMode()===r.Creative)t.setPermutation(t.permutation.withState("sapdon:block_variant_tag",3));else{let e=t.permutation.getState("sapdon:block_variant_tag");e+=(a=1,c=3-e,Math.floor(Math.random()*(c-a+1))+a),t.setPermutation(t.permutation.withState("sapdon:block_variant_tag",e)),o.amount>1?o.amount--:o.setItem(void 0)}var a,c;const m=t.center();e.playSound("item.bone_meal.use",m),e.spawnParticle("minecraft:crop_growth_emitter",m)}},Bt={onTick(n){const{block:s,dimension:r}=n;if(!s.below()||!s.below()?.isAir)return;e.sendMessage("是空气");const i={x:s.location.x+.5,y:s.location.y,z:s.location.z+.5};s.setType("minecraft:air"),t.runTimeout(()=>{const n=r.spawnEntity("sapdon:fallingblock_entity",i);n.applyImpulse({x:0,y:-.5,z:0});const s=t.runInterval(()=>{if(!n?.isValid)return e.sendMessage("实体无效移除"),void t.clearRun(s);{const i=n.getVelocity(),o=n.location;0===i.y&&(e.sendMessage("在地面上,速度为零"),r.setBlockType(o,"sapdon:fallingblock"),n.remove(),t.clearRun(s))}},10)},1)}},Nt={onPlayerInteract({block:t,dimension:e,player:n}){if(!n)return;const s=t.permutation,r=((s.getState("sapdon:head_rotation")??0)+1)%16;t.setPermutation(s.withState("sapdon:head_rotation",r)),e.playSound("random.click",t.center())}};const Zt={beforeOnPlayerPlace(t,{params:e}){const{player:n}=t;if(!n)return;const s=e?.y_rotation_offset??0,r=function(t){return(t%=360)<0&&(t+=360),Math.round(t/22.5)%16}(n.getRotation().y+s);t.permutationToPlace=t.permutationToPlace.withState("sapdon:head_rotation",r)}},Ut={"sapdon:neo_guidebook":"neo_guidebook","minecraft:stick":"test_book"};let Ht=0;function Kt(t,n){const s=(new i).title(n).body("page_index"+Ht).button("prev_button").button("next_button").button("test3").button("test4");0!=Ht&&s.button("home_button"),s.show(t).then(s=>{0===s.selection?(Ht--,e.sendMessage("上一页"),Kt(t,n)):1===s.selection?(Ht++,e.sendMessage("下一页"),Kt(t,n)):2===s.selection?(Ht=1,e.sendMessage("章节跳转至 章节1"),Kt(t,n)):3===s.selection?(Ht=2,e.sendMessage("章节跳转至 章节2"),Kt(t,n)):4===s.selection&&(Ht=0,e.sendMessage("返回目录"),Kt(t,n))})}const Vt={onUse({itemStack:t,source:e}){"minecraft:player"==e.typeId&&t&&Kt(e,Ut[t.typeId])}};function qt(){T("sapdon:block_with_entity",Ft),t.beforeEvents.startup.subscribe(t=>{t.blockComponentRegistry.registerCustomComponent("sapdon:crop_growth",jt),t.blockComponentRegistry.registerCustomComponent("sapdon:fallingblock",Bt),t.blockComponentRegistry.registerCustomComponent("sapdon:head_rotation",Nt),t.blockComponentRegistry.registerCustomComponent("sapdon:intercardinal_orientation",Zt),t.itemComponentRegistry.registerCustomComponent("sapdon:guibook",Vt)})}export{lt as ActorSpawned,u as BaseComponent,$t as CHUNK_SIZE,Ct as CHUNK_SUFFIX,l as ComponentManager,h as CustomComponent,ut as EntitySpawned,W as GameInstance,bt as HudComponent,zt as MAX_CHUNK_SCAN,U as MathExt,N as Matrix,it as Minecraft,wt as MinecraftGameInstance,gt as MinecraftLevel,ot as MinecraftMain,tt as MinecraftMethod,xt as MinecraftPlayerInputComponent,yt as MinecraftTickingScheduler,a as Optional,vt as PlayerHudComponent,K as PlayerInputComponent,ht as PlayerSpawned,d as RequireComponents,Et as ScriptEvent,pt as SpawnFilter,B as Vec3,Z as Vec4,rt as assertInMinecraft,Mt as chunkKey,St as chunkMetaJson,Ot as clearChunked,Y as finalize,J as getGameInstance,G as getGameInstanceClass,X as initialize,f as lazyGet,It as loadChunked,At as looksLikeChunkMeta,Pt as parseChunkCount,I as pendingComponentCount,R as registerBlockComponent,qt as registerBuiltinComponents,T as registerFallbackBlockComponent,D as registerFallbackItemComponent,L as registerItemComponent,O as registeredComponents,Dt as saveChunked,F as skippedFallbackComponents,Rt as splitValue,nt as utils};
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"main": "main.mjs",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "sapdon build ./",
|
|
7
|
-
"postinstall": "sapdon lib"
|
|
6
|
+
"build": "npx sapdon build ./",
|
|
7
|
+
"postinstall": "npx sapdon lib"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"bedrock",
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"
|
|
18
|
-
"@minecraft/server": "^1.
|
|
19
|
-
"@minecraft/server-ui": "^1.3.0"
|
|
17
|
+
"@minecraft/server": "^2.8.0",
|
|
18
|
+
"@minecraft/server-ui": "^2.1.0"
|
|
20
19
|
}
|
|
21
20
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format_version": "1.21.20",
|
|
3
|
+
"minecraft:geometry": [
|
|
4
|
+
{
|
|
5
|
+
"description": {
|
|
6
|
+
"identifier": "geometry.cube",
|
|
7
|
+
"texture_width": 16,
|
|
8
|
+
"texture_height": 16,
|
|
9
|
+
"visible_bounds_width": 2,
|
|
10
|
+
"visible_bounds_height": 2.5,
|
|
11
|
+
"visible_bounds_offset": [0, 0.75, 0]
|
|
12
|
+
},
|
|
13
|
+
"bones": [
|
|
14
|
+
{
|
|
15
|
+
"name": "cube",
|
|
16
|
+
"pivot": [0, 0, 0],
|
|
17
|
+
"cubes": [
|
|
18
|
+
{
|
|
19
|
+
"origin": [-8, 0, -8],
|
|
20
|
+
"size": [16, 16, 16],
|
|
21
|
+
"uv": {
|
|
22
|
+
"north": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
23
|
+
"east": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
24
|
+
"south": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
25
|
+
"west": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
26
|
+
"up": {"uv": [16, 16], "uv_size": [-16, -16]},
|
|
27
|
+
"down": {"uv": [16, 16], "uv_size": [-16, -16]}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
import { BlockWithEntityComponent } from "./block/block_with_entity.js";
|
|
3
2
|
import { CustomCropGrowthBlockComponent } from "./cropComponent.js";
|
|
4
3
|
import { GuiBookItemComponent } from "./items/gui_book.js";
|
|
5
4
|
import { world } from "@minecraft/server";
|
|
@@ -12,10 +11,6 @@ export const registerCustomItemComponent = ()=>{
|
|
|
12
11
|
|
|
13
12
|
export const registerCustomBlockComponent = ()=>{
|
|
14
13
|
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
|
|
15
|
-
blockComponentRegistry.registerCustomComponent(
|
|
16
|
-
"sapdon:block_with_entity",
|
|
17
|
-
BlockWithEntityComponent
|
|
18
|
-
);
|
|
19
14
|
blockComponentRegistry.registerCustomComponent(
|
|
20
15
|
"sapdon:crop_growth",
|
|
21
16
|
CustomCropGrowthBlockComponent
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"main": "main.ts",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "sapdon build ./",
|
|
7
|
-
"postinstall": "sapdon lib"
|
|
6
|
+
"build": "npx sapdon build ./",
|
|
7
|
+
"postinstall": "npx sapdon lib"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"bedrock",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"
|
|
18
|
-
"@minecraft/server": "^1.
|
|
19
|
-
"@
|
|
17
|
+
"@minecraft/server": "^2.8.0",
|
|
18
|
+
"@minecraft/server-ui": "^2.1.0",
|
|
19
|
+
"@types/node": "^22.0.0"
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"format_version": "1.21.20",
|
|
3
|
+
"minecraft:geometry": [
|
|
4
|
+
{
|
|
5
|
+
"description": {
|
|
6
|
+
"identifier": "geometry.cube",
|
|
7
|
+
"texture_width": 16,
|
|
8
|
+
"texture_height": 16,
|
|
9
|
+
"visible_bounds_width": 2,
|
|
10
|
+
"visible_bounds_height": 2.5,
|
|
11
|
+
"visible_bounds_offset": [0, 0.75, 0]
|
|
12
|
+
},
|
|
13
|
+
"bones": [
|
|
14
|
+
{
|
|
15
|
+
"name": "cube",
|
|
16
|
+
"pivot": [0, 0, 0],
|
|
17
|
+
"cubes": [
|
|
18
|
+
{
|
|
19
|
+
"origin": [-8, 0, -8],
|
|
20
|
+
"size": [16, 16, 16],
|
|
21
|
+
"uv": {
|
|
22
|
+
"north": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
23
|
+
"east": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
24
|
+
"south": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
25
|
+
"west": {"uv": [0, 0], "uv_size": [16, 16]},
|
|
26
|
+
"up": {"uv": [16, 16], "uv_size": [-16, -16]},
|
|
27
|
+
"down": {"uv": [16, 16], "uv_size": [-16, -16]}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|