sapdon 3.3.3 → 3.4.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.
@@ -379,5 +379,7 @@ declare const ScriptEvent: {
379
379
  (evType: string): MethodDecorator;
380
380
  };
381
381
 
382
- 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, utils };
382
+ declare function registerBuiltinComponents(): void;
383
+
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 };
383
385
  export type { AxisValue, BasicComponent, Component, ComponentCtor, 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}from"@minecraft/server";const n=Symbol("isOptional");class r{value;static none(){return new r(null)}static some(t){return new r(t)}constructor(t){this.value=t}[n]=n;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[n]?s:r.some(t.call(e,this.value))}return r.none()}}const i=Symbol("reflect-manager"),o=Symbol("reflect-entity");class m{[i];[o]=r.none();onTick(t){}detach(){const t=Object.getPrototypeOf(this).constructor;return this.getManager().detachComponent(t)}getManager(){return this[i]}getEntity(){return this[o]}lazyGet(t){return l(this,t)}}class h extends m{onAttach(t){}onDetach(t){}}class a{static profilerEnable=!1;static global=new a;#t=new Map;#e=[];#s=[];getComponentUnsafe(t){return this.#t.get(t)}getComponent(t){return r.some(this.#t.get(t))}getComponents(...t){return t.map(t=>this.#t.get(t))}#n(t,e,s=!0){e[i]||(e[i]=this);let n=!this.#t.get(t);if(!n&&s&&(this.detachComponent(t),n=!0),c in e)for(const[t,s]of e[c])e.getManager().getComponentUnsafe(t)||this.#n(t,s,!1);return n&&"onAttach"in e&&e.onAttach(this),this.#t.set(t,e),r.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?r.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,r.some(t)));this.#e.length=0;for(const s of this.#t.values()){s[o].isEmpty()&&(s[o]=r.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,r.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(!a.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 c=Symbol("REQUIRED_COMPONENTS");function u(...t){return class extends h{[c]=new Map;constructor(){super();for(const e of t){if(Array.isArray(e)){const[t,...s]=e;this[c].set(t,Reflect.construct(t,s));continue}this[c].set(e,Reflect.construct(e,[]))}}getComponent(t){return this[c].get(t)}}}function l(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 p 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 d extends p{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 d([t,e,s])}static fromVec3(t){return new d([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 d.m(this)}static isZero(t){return 0===t.x&&0===t.y&&0===t.z}isZero(){return d.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 d.normalize(this)}static add(t,e){return new d([t.x+e.x,t.y+e.y,t.z+e.z])}add(t){return d.add(this,t)}static sub(t,e){return new d([t.x-e.x,t.y-e.y,t.z-e.z])}sub(t){return d.sub(this,t)}static mul(t,e){return new d([t.x*e,t.y*e,t.z*e])}mul(t){return d.mul(this,t)}static div(t,e){return new d([t.x/e,t.y/e,t.z/e])}div(t){return d.div(this,t)}static dot(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}dot(t){return d.dot(this,t)}static cross(t,e){return new d([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 d.cross(this,t)}valueOf(){return new p([this.x,this.y,this.z])}toString(){return`(${this.x.toFixed(2)}, ${this.y.toFixed(2)}, ${this.z.toFixed(2)})`}}class f extends p{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=p.from(t,e,s),r=new f;return r.set(n),r}clone(){return f.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 f;return t.setIdentity(),t}static add(t,e){const s=new f;return s.set(t.map((t,s)=>t+e[s])),s}add(t){return f.add(this,t)}static sub(t,e){const s=new f;return s.set(t.map((t,s)=>t-e[s])),s}sub(t){return f.sub(this,t)}setTranslation(t,e,s){return this.m14=t,this.m24=e,this.m34=s,this}setRotation(t,e){d.normalize(e);const s=Math.sin(t),n=Math.cos(t),r=e.x,i=e.y,o=e.z,m=1-n,h=m*r*r+n,a=m*r*i-s*o,c=m*r*o+s*i,u=m*r*i+s*o,l=m*i*i+n,p=m*i*o-s*r,f=m*r*o-s*i,y=m*i*o+s*r,x=m*o*o+n;return this.m11=h,this.m12=a,this.m13=c,this.m21=u,this.m22=l,this.m23=p,this.m31=f,this.m32=y,this.m33=x,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),m=Math.sin(s),h=Math.cos(s);return this.m11=r*h+n*i*m,this.m12=r*m-n*i*h,this.m13=n*o,this.m21=n*h-r*i*m,this.m22=r*h-n*i*h,this.m23=r*i,this.m31=n*m+r*i*h,this.m32=-n*h+r*i*m,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 f.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 f.transpose(this)}static multiply(t,e){return e instanceof f?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 y([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 f.multiply(this,t)}valueOf(){return new p(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 f.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 f.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=d.sub(e,t);n.n();const r=d.cross(s,n);r.n();const i=d.cross(n,r);return i.n(),f.from([r.x,r.y,r.z,-d.dot(r,t),i.x,i.y,i.z,-d.dot(i,t),n.x,n.y,n.z,-d.dot(n,t),0,0,0,1])}}class y extends p{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 y([t,e,s,n])}static fromVec3(t){return new y([t.x,t.y,t.z])}static fromVec4(t){return new y([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 y.m(this)}static isZero(t){return 0===t.x&&0===t.y&&0===t.z&&0===t.w}isZero(){return y.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 y.normalize(this)}static add(t,e){return new y([t.x+e.x,t.y+e.y,t.z+e.z,t.w+e.w])}add(t){return y.add(this,t)}static sub(t,e){return new y([t.x-e.x,t.y-e.y,t.z-e.z,t.w-e.w])}sub(t){return y.sub(this,t)}static mul(t,e){return new y([t.x*e,t.y*e,t.z*e,t.w*e])}mul(t){return y.mul(this,t)}static div(t,e){return new y([t.x/e,t.y/e,t.z/e,t.w/e])}div(t){return y.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 y.dot(this,t)}static multiply(t,e){return f.multiply(e,t)}multiply(t){return y.multiply(this,t)}valueOf(){return new p([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 x;!function(t){function e(t,e,s){return t+(e-t)*s}function s(t,s,n){return d.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 y.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)}}(x||(x={}));class g{pressing;times;constructor(t=!1,e=0){this.pressing=t,this.times=e}consume(){this.times--}}class w extends h{keyStateMapping=new Map;axisMapping=new Map;inputKey(t,e){let s=this.keyStateMapping.get(t)??new g;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=x.clamp(e,0,t.length-1),s||(s=t.length-e),[t.slice(0,e),t.slice(e,e+s)]}}let v,b;function z(t,e={}){b=Reflect.construct(t,[]),b?.onStart?.(e)}function E(t){t?.shutdown?.()}const _=t=>{v=t};function M(){return v}function A(){return b}var S=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 m=t.length-1;m>=0;m--)(r=t[m])&&(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)=>($(),n.apply(t,e)),s}class k{toPlayer(t){return r.some(t)}start(){t?.beforeEvents?.startup&&(t.beforeEvents.startup.subscribe(t=>{const e=M();if(!e)throw new Error("No game instance class found");z(e,t)}),t.beforeEvents.shutdown.subscribe(t=>{const e=A();e&&E(e)})),e?.beforeEvents?.worldInitialize&&e.beforeEvents.worldInitialize.subscribe(t=>{const e=M();if(!e)throw new Error("No game instance class found");z(e,t)})}}S([L],k.prototype,"toPlayer",null),S([L],k.prototype,"start",null);const R=new k;function C(t){return t?.[Symbol.metadata]}function $(){if(!e)throw new Error("Not running in the Minecraft host environment. required @minecraft/server")}Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));const T=t=>new Proxy(t,{construct:(t,e)=>($(),Reflect.construct(t,e))}),F=t=>{$(),_(t),R.start(),e.afterEvents.playerSpawn.subscribe(t=>A()?.getLevel().getManager(t.player.id).attachComponent(...O(D).filter(e=>C(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(...O(P).filter(e=>C(e)?.spawnFilter?.(t.entity)??!0).map(t=>Reflect.construct(t,[])))})};function O(t){return Array.from(new Set(t))}const D=[],P=[],j=(...t)=>e=>{D.push(...t,e)},Z=(...t)=>e=>{P.push(...t,e)},N=(...t)=>e=>{D.push(...t,e),P.push(...t,e)},I=t=>e=>{const s=function(t){if(null==t)return;return t?.[Symbol.metadata]??(t[Symbol.metadata]={})}(e);s.spawnFilter=t};class H{table=new Map;addEntity(t){const e=new a;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 K=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 m=t.length-1;m>=0;m--)(r=t[m])&&(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 U=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};U=K([T],U);let V=class extends H{scheduler=new U;getScheduler(){return this.scheduler}};V=K([T],V);class X{level;setLevel(t){return this.level?.stop?.(),t.start(),this.level=t}getLevel(){return this.level}onStart(e){this.setLevel(new V),t.runTimeout(()=>this.afterStart(),1)}shutdown(){this.level?.stop?.()}afterStart(){}}class Y extends w{playerRef=r.none();static{e.afterEvents.playerButtonInput.subscribe(t=>{const e=A()?.getLevel()?.getManager(t.player.id).getComponentUnsafe(Y);e?.inputKey(t.button,t.newButtonState===s.Pressed)})}onTick(){this.playerRef.isEmpty()?this.getEntity().use(t=>this.playerRef=R.toPlayer(t)):this.syncAxisAndButtons()}syncAxisAndButtons(){const t=this.playerRef.unwrap().inputInfo,{x:e,y:s}=t.getMovementVector();this.inputAxis("Movement",[e,s])}}class q extends m{hud;actor=r.none();onTick(t){this.hud=this.render(),this.draw()}}class B extends q{draw(){if(this.actor.isEmpty())return void(this.actor=R.toPlayer(this.getEntity().unwrap()));this.actor.unwrap().runCommand(`title @s actionbar ${this.hud}`)}}class W{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,W.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),W.map.set(e||t,r),this.count++,this}delete(t){let e=W.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,W.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 G=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 W),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 W),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=>{G.emitNone(t.id,t)});const Q=t=>(e,s)=>{G.on(t,e[s])};Q.on=(t,e)=>{G.on(t,e)},Q.off=(t,e)=>{G.off(t,e)};export{N as ActorSpawned,h as BaseComponent,a as ComponentManager,m as CustomComponent,Z as EntitySpawned,_ as GameInstance,q as HudComponent,x as MathExt,f as Matrix,T as Minecraft,X as MinecraftGameInstance,V as MinecraftLevel,F as MinecraftMain,L as MinecraftMethod,Y as MinecraftPlayerInputComponent,U as MinecraftTickingScheduler,r as Optional,B as PlayerHudComponent,w as PlayerInputComponent,j as PlayerSpawned,u as RequireComponents,Q as ScriptEvent,I as SpawnFilter,d as Vec3,y as Vec4,$ as assertInMinecraft,E as finalize,A as getGameInstance,M as getGameInstanceClass,z as initialize,l as lazyGet,R as utils};
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};
@@ -25,13 +25,6 @@ interface ISerializer {
25
25
  declare function jsonEncoderReplacer(_: string, v: any): any;
26
26
  declare const defaultSerializer: ISerializer;
27
27
  declare function Serializable(serializer?: ISerializer): (_: any, ctx: DecoratorContext) => void;
28
- /**
29
- * 只能应用一个 Serializer
30
- *
31
- * 重复的 Serializer 会被覆盖
32
- * @param target
33
- * @param ctx
34
- */
35
28
  declare const Serializer: MethodDecorator;
36
29
  declare function serialize<R, T extends object>(inst: T): R;
37
30
  declare const jsonEncodeDecoder: EncodeDecoder<any, string>;
@@ -1 +1 @@
1
- function t(t){return t?.[Symbol.metadata]}function e(t){if(null==t)return;return t?.[Symbol.metadata]??(t[Symbol.metadata]={})}function r(t,...e){return Object.assign(t,...e)}Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));class n{empty;constructor(t){this.empty=t}clear(){this.map.clear()}delete(t){return this.map.delete(t)}forEach(t,e){this.map.forEach(t,e)}get(t){const e=this.map.get(t);if(null==e){const e=this.empty();return this.map.set(t,e),e}return e}set(t,e){return this.map.set(t,e),this}has(t){return this.map.has(t)}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}[Symbol.iterator](){return this.map[Symbol.iterator]()}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}map=new Map}const a=Symbol("isRawJSON"),o=t=>{const e=JSON.rawJSON(t).rawJSON;return{[a]:!0,rawJSON:e,valueOf:()=>parseFloat(t)}};function s(t){return!0===t?.[a]}const i=["boolean","number"],u=["string","undefined"];function c(t,e){const r=typeof e;if(null===r)return null;if(u.includes(r))return e;if(i.includes(r))return JSON.rawJSON(e);if("object"===r)return JSON.isRawJSON(e)?e:s(e)?JSON.rawJSON(e.rawJSON):e;if("bigint"===r)return JSON.rawJSON(e.toString());throw new Error("Unexpected value")}const l=t=>structuredClone(t),m=Symbol("serializer"),S=new WeakMap;function f(t=l){return(r,n)=>{if("class"!==n.kind)throw new Error("Serializable decorator can only be applied to classes");e(n)[m]=t}}const p=(t,e)=>{const r=t.constructor;if(!r)throw new Error("Cannot serialize an instance of an anonymous class");S.set(r,t[e])};function h(e){const r=Reflect.getPrototypeOf(e)?.constructor;if(!r)throw new Error("Cannot serialize an instance of an anonymous class");return(t(r)?.[m]??S.get(r)??l).call(e,e)}const d={encode:t=>JSON.stringify(t,c),decode:JSON.parse};function y(t,e=d){return e.encode(t)}function b(t,e=d){return e.decode(t)}export{n as NonNullMap,f as Serializable,p as Serializer,b as decode,l as defaultSerializer,y as encode,o as f64,t as getMetadata,e as getOrCreateMetadata,s as isRawJSON,d as jsonEncodeDecoder,c as jsonEncoderReplacer,r as mixin,h as serialize};
1
+ function t(t){return t?.[Symbol.metadata]}function e(t){if(null==t)return;return t?.[Symbol.metadata]??(t[Symbol.metadata]={})}function r(t,...e){return Object.assign(t,...e)}Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));class n{empty;constructor(t){this.empty=t}clear(){this.map.clear()}delete(t){return this.map.delete(t)}forEach(t,e){this.map.forEach(t,e)}get(t){const e=this.map.get(t);if(null==e){const e=this.empty();return this.map.set(t,e),e}return e}set(t,e){return this.map.set(t,e),this}has(t){return this.map.has(t)}get size(){return this.map.size}entries(){return this.map.entries()}keys(){return this.map.keys()}values(){return this.map.values()}[Symbol.iterator](){return this.map[Symbol.iterator]()}get[Symbol.toStringTag](){return this.map[Symbol.toStringTag]}map=new Map}const a=Symbol("isRawJSON"),o=t=>{const e=JSON.rawJSON(t).rawJSON;return{[a]:!0,rawJSON:e,valueOf:()=>parseFloat(t)}};function s(t){return!0===t?.[a]}const i=["boolean","number"],u=["string","undefined"];function c(t,e){const r=typeof e;if(null===r)return null;if(u.includes(r))return e;if(i.includes(r))return JSON.rawJSON(e);if("object"===r)return JSON.isRawJSON(e)?e:s(e)?JSON.rawJSON(e.rawJSON):e;if("bigint"===r)return JSON.rawJSON(e.toString());throw new Error("Unexpected value")}const l=t=>structuredClone(t),m=Symbol("serializer"),f=new WeakMap;function S(t=l){return(r,n)=>{if("class"!==n.kind)throw new Error("Serializable decorator can only be applied to classes");e(n)[m]=t}}const p=(t,e)=>{const r=t.constructor;if(!r)throw new Error("Cannot serialize an instance of an anonymous class");f.set(r,t[e])};function d(e){let r=Reflect.getPrototypeOf(e);for(;r;){const n=r.constructor;if(!n)break;const a=t(n)?.[m]??f.get(n);if(a)return a.call(e,e);r=Reflect.getPrototypeOf(r)}return l(e)}const h={encode:t=>JSON.stringify(t,c),decode:JSON.parse};function y(t,e=h){return e.encode(t)}function b(t,e=h){return e.decode(t)}export{n as NonNullMap,S as Serializable,p as Serializer,b as decode,l as defaultSerializer,y as encode,o as f64,t as getMetadata,e as getOrCreateMetadata,s as isRawJSON,h as jsonEncodeDecoder,c as jsonEncoderReplacer,r as mixin,d as serialize};