From 92f56b84981b824ecd9e97a5fae462953ab87d3e Mon Sep 17 00:00:00 2001
From: xBoyMinemc <86919167+xBoyMinemc@users.noreply.github.com>
Date: Mon, 4 Nov 2024 18:04:08 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E6=B8=B8=E6=88=8F=E8=84=9A?=
 =?UTF-8?q?=E6=9C=AC=E5=BC=95=E6=93=8E=E5=BF=AB=E9=80=9F=E6=9B=B4=E6=96=B0?=
 =?UTF-8?q?=E6=97=B6=E6=9C=9F=E7=95=99=E4=B8=8B=E6=9D=A5=E7=9A=84=E8=BE=85?=
 =?UTF-8?q?=E5=8A=A9=E5=B7=A5=E5=85=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 tscripts/@types/globalThis.d.ts               | 216 +-----------------
 tscripts/lib/xboyEvents/index.ts              |   4 -
 tscripts/lib/xboyEvents/projectileFired.ts    |   9 +-
 tscripts/lib/xboyEvents/reloadFromCmd.ts      |   9 +-
 tscripts/lib/xboyEvents/tick.ts               |  19 --
 .../The law of the ancestors is immutable.ts  |  89 +-------
 tscripts/main/preload.ts                      |  17 +-
 tscripts/xTerrain/plugins/test.ts             |  19 --
 8 files changed, 16 insertions(+), 366 deletions(-)
 delete mode 100644 tscripts/lib/xboyEvents/tick.ts

diff --git a/tscripts/@types/globalThis.d.ts b/tscripts/@types/globalThis.d.ts
index 1b1aaae..72b2780 100644
--- a/tscripts/@types/globalThis.d.ts
+++ b/tscripts/@types/globalThis.d.ts
@@ -1,66 +1,12 @@
 import {
-    World as _World,
-    // Events as _Events,
     EntityEventOptions,
     Entity,
-    EntityHurtAfterEvent,
-    ChatSendBeforeEventSignal,
-    // DataDrivenEntityTriggerBeforeEventSignal,
-    ExplosionBeforeEventSignal,
-    // ItemDefinitionBeforeEventSignal,
-    ItemUseBeforeEventSignal,
-    ItemUseOnBeforeEventSignal,
-    // PistonActivateBeforeEventSignal,
-    WorldAfterEvents,
-    PlayerBreakBlockAfterEventSignal,
-    BlockExplodeAfterEventSignal,
-    PlayerPlaceBlockAfterEventSignal,
-    ButtonPushAfterEventSignal,
-    ChatSendAfterEventSignal,
-    DataDrivenEntityTriggerAfterEventSignal,
-    EffectAddAfterEventSignal,
-    EntityDieAfterEventSignal,
-    EntityHealthChangedAfterEventSignal,
-    // EntityHitAfterEventSignal,
-    EntityHurtAfterEventSignal,
-    EntityHitEntityAfterEventSignal,
-    // EntityRemovedAfterEventSignal, // matter?
-    EntityRemoveAfterEventSignal,
-    EntityRemoveBeforeEventSignal,
-    EntitySpawnAfterEventSignal,
-    ExplosionAfterEventSignal,
-    ItemCompleteUseAfterEventSignal,
-    // ItemDefinitionAfterEventSignal, // removed?
-    ItemReleaseUseAfterEventSignal,
-    ItemStartUseAfterEventSignal,
-    ItemStartUseOnAfterEventSignal,
-    ItemStopUseAfterEventSignal,
-    ItemStopUseOnAfterEventSignal,
-    ItemUseAfterEventSignal,
-    ItemUseOnAfterEventSignal,
-    LeverActionAfterEventSignal,
-    ServerMessageAfterEventSignal,
-    PistonActivateAfterEventSignal,
-    PlayerJoinAfterEventSignal,
-    PlayerLeaveAfterEventSignal,
-    PlayerSpawnAfterEventSignal,
-    PressurePlatePopAfterEventSignal,
-    PressurePlatePushAfterEventSignal,
-    // ProjectileHitAfterEventSignal,
-    ProjectileHitBlockAfterEventSignal,
-    TargetBlockHitAfterEventSignal,
-    TripWireTripAfterEventSignal,
-    WeatherChangeAfterEventSignal,
-    WorldInitializeAfterEventSignal,
-    EntityHitBlockAfterEventSignal, ProjectileHitEntityAfterEventSignal, Vector3,
+    EntityHurtAfterEvent, Vector3,
 } from "@minecraft/server";
 
-// import type {
-//     Events as _Events
-// } from "./temp"
+
 //逆码的,乱起来了
-import {
-    register as _register, SimulatedPlayer,
+import { SimulatedPlayer,
 } from "@minecraft/server-gametest";
 
 import {
@@ -68,122 +14,9 @@ import {
     BlockLocation
 } from "../lib/xboyPackage/The law of the ancestors is immutable";
 
-export type Events = _WorldBeforeEvents & _WorldAfterEvents & _Events
-
-// export { };
-declare global {
-    interface GlobalThis {
-      Location: typeof Location;
-      BlockLocation: typeof BlockLocation;
-      world: _World & {events:Events};
-      GameTest:  {"register":typeof _register};
-    }
-  }
-
 
 
 
-
-export class _Events {
-
-    /**
-     * This event fires every tick - which is 20 times per second.
-     */
-    tick: TickEventSignal;
-    /**
-     * This event fires every reload from command.
-     */
-    reloadFromCmd: reloadFromCmdEventSignal;
-    /**
-     * xBoyMinemc
-     * This event fires when an entity dead by hurt (takes damage).
-     */
-    entityDeadByHurt: EntityDeadByHurtEventSignal;
-    /**
-     * xBoyMinemc
-     * This event fires when an FishingHook spawned.
-     */
-    fishingHookSpawned: FishingHookSpawnedEventSignal;
-    /**
-     * xBoyMinemc
-     * This event fires when an FishingHook despawned.
-     */
-    fishingHookDespawned: FishingHookDespawnedEventSignal;
-    /**
-     * xBoyMinemc
-     * This event fires when a player moved.
-     */
-    playerMove: playerMoveAfterEventSignal;
-
-
-}
-export class _WorldBeforeEvents {
-    readonly beforeChat: ChatSendBeforeEventSignal;
-    // readonly beforeDataDrivenEntityTriggerEvent: DataDrivenEntityTriggerBeforeEventSignal;
-    readonly beforeExplosion: ExplosionBeforeEventSignal;
-    // readonly beforeItemDefinitionEvent: ItemDefinitionBeforeEventSignal;
-    readonly beforeItemUse: ItemUseBeforeEventSignal;
-    readonly beforeItemUseOn: ItemUseOnBeforeEventSignal;
-    // readonly beforePistonActivate: PistonActivateBeforeEventSignal;
-    readonly beforeEntityRemoved : EntityRemoveBeforeEventSignal;
-}
-export class _WorldAfterEvents {
-    readonly blockBreak: PlayerBreakBlockAfterEventSignal;
-    readonly blockExplode: BlockExplodeAfterEventSignal;
-    readonly blockPlace: PlayerPlaceBlockAfterEventSignal;
-    readonly buttonPush: ButtonPushAfterEventSignal;
-    readonly chatSend: ChatSendAfterEventSignal;
-    readonly dataDrivenEntityTriggerEvent: DataDrivenEntityTriggerAfterEventSignal;
-    readonly effectAdd: EffectAddAfterEventSignal;
-    readonly entityDie: EntityDieAfterEventSignal;
-    readonly entityHealthChanged: EntityHealthChangedAfterEventSignal;
-    readonly entityHit: EntityHitBlockAfterEventSignal;
-    readonly entityHitBlock: EntityHitBlockAfterEventSignal;
-    readonly entityHitEntity: EntityHitEntityAfterEventSignal;
-    readonly entityHurt: EntityHurtAfterEventSignal;
-    readonly entityRemoved: EntityRemoveAfterEventSignal;
-    readonly entitySpawn: EntitySpawnAfterEventSignal;
-    readonly explosion: ExplosionAfterEventSignal;
-    readonly itemCompleteCharge: ItemCompleteUseAfterEventSignal;
-    // readonly itemDefinitionEvent: ItemDefinitionAfterEventSignal;
-    readonly itemReleaseCharge: ItemReleaseUseAfterEventSignal;
-    readonly itemStartCharge: ItemStartUseAfterEventSignal;
-    readonly itemStartUseOn: ItemStartUseOnAfterEventSignal;
-    readonly itemStopCharge: ItemStopUseAfterEventSignal;
-    readonly itemStopUseOn: ItemStopUseOnAfterEventSignal;
-    readonly itemUse: ItemUseAfterEventSignal;
-    readonly itemUseOn: ItemUseOnAfterEventSignal;
-    readonly leverActivate: LeverActionAfterEventSignal;
-    readonly messageReceive: ServerMessageAfterEventSignal;
-    readonly pistonActivate: PistonActivateAfterEventSignal;
-    readonly playerJoin: PlayerJoinAfterEventSignal;
-    readonly playerLeave: PlayerLeaveAfterEventSignal;
-    readonly playerSpawn: PlayerSpawnAfterEventSignal;
-    readonly pressurePlatePop: PressurePlatePopAfterEventSignal;
-    readonly pressurePlatePush: PressurePlatePushAfterEventSignal;
-    readonly projectileHit: ProjectileHitBlockAfterEventSignal;
-    readonly ProjectileHitBlock: ProjectileHitBlockAfterEventSignal;
-    readonly ProjectileHitEntity: ProjectileHitEntityAfterEventSignal;
-    readonly targetBlockHit: TargetBlockHitAfterEventSignal;
-    readonly tripWireTrip: TripWireTripAfterEventSignal;
-    readonly weatherChange: WeatherChangeAfterEventSignal;
-    readonly worldInitialize: WorldInitializeAfterEventSignal;
-
-}
-
-// @ts-ignore
-
-export class World extends _World {
-    /**
-     * @beta
-     * Contains a set of events that are applicable to the entirety
-     * of the world.
-     */
-    // @ts-ignore
-    events: Events;
-}
-
-
 /**
  * Manages callbacks that are connected to a reloadFromCmd event.
  */
@@ -220,49 +53,6 @@ export class reloadFromCmdEvent {
 
 
 
-/**
- * Manages callbacks that are connected to a tick event.
- */
-export class TickEventSignal {
-    /**
-     * @remarks
-     * Adds a callback that will be called on every tick.
-     * @param callback
-     */
-    subscribe(callback: (arg: TickEvent) => void): void;
-    /**
-     * @remarks
-     * Removes a callback from being called every tick.
-     * @param callback
-     * @throws This function can throw errors.
-     */
-    unsubscribe(callback: (arg: TickEvent) => void): void;
-    /**
-     * @remarks
-     * Trigger a callback from being called every tick.
-     * @throws This function can throw errors.
-     */
-    trigger(TickEvent): void;
-    protected constructor();
-}
-
-
-/**
- * An event for handling updates, that fires 20 times every
- * second.
- */
-export class TickEvent {
-    // /**
-    //  * Current tick at the time this event was fired.
-    //  */
-    // readonly currentTick: number;
-    // /**
-    //  * Time since the last tick was fired.
-    //  */
-    // readonly deltaTime: number;
-    // protected constructor();
-}
-
 /**
  * xBoyMinemc
  * Manages callbacks that are connected to when an entity dead by hurt.
diff --git a/tscripts/lib/xboyEvents/index.ts b/tscripts/lib/xboyEvents/index.ts
index 4ffc99f..79a2e34 100644
--- a/tscripts/lib/xboyEvents/index.ts
+++ b/tscripts/lib/xboyEvents/index.ts
@@ -3,11 +3,7 @@ import { fishingHookSpawned, fishingHookDespawned } from "./fishingHookSpawned"
 import reloadFromCmd from "./reloadFromCmd"
 // import  "./projectileFired"; // TEST
 import { playerMove } from "./move";
-import { world } from "@minecraft/server";
 
-// import type { World } from "../../@types/globalThis.d.ts";
-
-// declare const world: World;
 const events = {
     playerMove: playerMove,
     entityDeadByHurt: entityDeadByHurt,
diff --git a/tscripts/lib/xboyEvents/projectileFired.ts b/tscripts/lib/xboyEvents/projectileFired.ts
index 15f7442..756419f 100644
--- a/tscripts/lib/xboyEvents/projectileFired.ts
+++ b/tscripts/lib/xboyEvents/projectileFired.ts
@@ -1,10 +1,9 @@
-import type { Entity, ItemUseAfterEvent, Player, Vector3 } from "@minecraft/server";
+import { world, Entity, ItemUseAfterEvent, Vector3} from "@minecraft/server";
 import EventSignal from "./EventSignal";
-import type { World,projectileFiredEvent, projectileFiredEventSignal } from "../../@types/globalThis";
+import type { projectileFiredEvent, projectileFiredEventSignal } from "../../@types/globalThis";
 import type { FishingHookDespawnedEvent, FishingHookDespawnedEventSignal } from "../../@types/globalThis";
 import {MolangVariableMap, system} from "@minecraft/server";
 
-declare const world: World;
 
 
 
@@ -19,7 +18,7 @@ const queue = {
 };
 
 const pos = {}
-world.events.itemUse.subscribe((event: ItemUseAfterEvent) => {
+world.afterEvents.itemUse.subscribe((event: ItemUseAfterEvent) => {
 
     event.itemStack.typeId === "minecraft:bow"
         ?(
@@ -42,7 +41,7 @@ const yu = ({x,y,z},{x:a,y:b,z:c})=>((x-a)**2+(y-b)**2+(z-c)**2)
 const me = ({x,y,z},{x:a,y:b,z:c},m:number)=>({x:x-a*m,y:y-b*m,z:z-c*m})
 const yume = ({x,y,z},{x:a,y:b,z:c})=>Math.sqrt((x-a)**2+(y-b)**2+(z-c)**2)
 const r3 = (o:Vector3,_o:Vector3,v:number):boolean=>o.x-_o.x<-v ||o.x-_o.x>v||  o.y-_o.y>v||o.y-_o.y<-v || o.z-_o.z>v||o.z-_o.z<-v;
-world.events.entitySpawn.subscribe(({entity: entity}) => {
+world.afterEvents.entitySpawn.subscribe(({entity: entity}) => {
     // world.getDimension("overworld").runCommandAsync("tell @a[tag=xboy] size fishingHookDespawned_HookArray=>"+queue.fishingHookDespawned_HookArray.size)
 
     // entity.runCommandAsync("me "+entity.typeId)
diff --git a/tscripts/lib/xboyEvents/reloadFromCmd.ts b/tscripts/lib/xboyEvents/reloadFromCmd.ts
index 2525ee1..d3c15c7 100644
--- a/tscripts/lib/xboyEvents/reloadFromCmd.ts
+++ b/tscripts/lib/xboyEvents/reloadFromCmd.ts
@@ -1,8 +1,7 @@
-import {Player, system} from "@minecraft/server"
+import { Player, system, world } from "@minecraft/server"
 import EventSignal from "./EventSignal"
-import type { World,reloadFromCmdEvent } from "../../@types/globalThis";
+import type { reloadFromCmdEvent } from "../../@types/globalThis";
 
-declare const world: World;
 
 class reloadFromCmdEvents extends EventSignal<reloadFromCmdEvent> {
     players = new Set<Player["id"]>();
@@ -14,12 +13,12 @@ class reloadFromCmdEvents extends EventSignal<reloadFromCmdEvent> {
 
 const reloadFromCmd = new reloadFromCmdEvents()
 
-world.events.playerJoin.subscribe(
+world.afterEvents.playerJoin.subscribe(
     event=>reloadFromCmd.players.add(event.playerId)
 )
 
 
-world.events.playerLeave.subscribe(
+world.afterEvents.playerLeave.subscribe(
     event=>reloadFromCmd.players.delete(event.playerId)
 )
 
diff --git a/tscripts/lib/xboyEvents/tick.ts b/tscripts/lib/xboyEvents/tick.ts
deleted file mode 100644
index da08d69..0000000
--- a/tscripts/lib/xboyEvents/tick.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-// Deprecated
-/// <reference path="../../@types/globalThis.d.ts" />
-import { system } from "@minecraft/server"
-import EventSignal from "./EventSignal"
-import type { World,TickEvent } from "../../@types/globalThis.d.ts";
-
-declare const world: World;
-
-  const tick = new EventSignal<TickEvent>()
-  world.events.tick = tick;
-  system.runInterval(()=> world.events.tick.trigger(null) ,1)
-
-/*
-  world.events.tick.subscribe(()=>{
-    world.getDimension("overworld").runCommandAsync("say world.events.tick.subscribe suc")
-  })
-*/
-
-// export default  tick
\ No newline at end of file
diff --git a/tscripts/lib/xboyPackage/The law of the ancestors is immutable.ts b/tscripts/lib/xboyPackage/The law of the ancestors is immutable.ts
index cb17f85..c98d9c3 100644
--- a/tscripts/lib/xboyPackage/The law of the ancestors is immutable.ts	
+++ b/tscripts/lib/xboyPackage/The law of the ancestors is immutable.ts	
@@ -1,7 +1,3 @@
-import { system } from "@minecraft/server";
-
-// import { world as _world} from "@minecraft/server";
-
 export class Location {
     x:number;
     y:number;
@@ -34,87 +30,4 @@ export class EventSignal<T> {
     trigger(ev: T) {
         this.listeners.forEach((listener: Function) => listener(ev))
     }
-}
-
-// const tick : TickEventSignal = new EventSignal<TickEvent>();
-//
-// system.runInterval(() => tick.trigger({currentTick:system.currentTick}), 1);
-//
-// // @ts-ignore
-// globalThis.tick = tick
-
-//
-// const bf = _world.beforeEvents;
-// const af = _world.afterEvents;
-// export const Events = {
-//     tick: tick,
-//
-//     beforeChat: bf.chatSend,
-//     beforeDataDrivenEntityTriggerEvent: bf.dataDrivenEntityTriggerEvent,
-//     beforeExplosion: bf.explosion,
-//     beforeItemDefinitionEvent: bf.itemDefinitionEvent,
-//     beforeItemUse: bf.itemUse,
-//     beforeItemUseOn: bf.itemUseOn,
-//     beforePistonActivate: bf.pistonActivate,
-//
-//     blockBreak: af.playerBreakBlock,
-//     blockExplode: af.blockExplode,
-//     blockPlace: af.playerPlaceBlock,
-//     buttonPush: af.buttonPush,
-//     chat: af.chatSend,
-//     dataDrivenEntityTriggerEvent: af.dataDrivenEntityTriggerEvent,
-//     effectAdd: af.effectAdd,
-//     entityDie: af.entityDie,
-//     // entityHit: af.entityHit, // pupupu 裂开
-//     entityHit: af.entityHitBlock,
-//     entityHitEntity: af.entityHitEntity,
-//     entityHitBlock: af.entityHitBlock,
-//     entityHurt: af.entityHurt,
-//     entityRemoved: af.entityRemove,
-//     entitySpawn: af.entitySpawn,
-//     explosion: af.explosion,
-//     itemCompleteCharge: af.itemCompleteUse,
-//     itemDefinitionEvent: af.itemDefinitionEvent,
-//     itemReleaseCharge: af.itemReleaseUse,
-//     itemStartCharge: af.itemStartUse,
-//     itemStartUseOn: af.itemStartUseOn,
-//     itemStopCharge: af.itemStopUse,
-//     itemStopUseOn: af.itemStopUseOn,
-//     itemUse: af.itemUse,
-//     itemUseOn: af.itemUseOn,
-//     // leverActivate: af.leverActivate,//有*?
-//     leverActivate: af.leverAction,
-//     messageReceive: af.messageReceive,
-//     pistonActivate: af.pistonActivate,
-//     playerJoin: af.playerJoin,
-//     playerLeave: af.playerLeave,
-//     playerSpawn: af.playerSpawn,
-//     pressurePlatePop: af.pressurePlatePop,
-//     pressurePlatePush: af.pressurePlatePush,
-//     projectileHit: af.projectileHitBlock,
-//     projectileHitBlock: af.projectileHitBlock,
-//     projectileHitEntity: af.projectileHitEntity,
-//     targetBlockHit: af.targetBlockHit,
-//     tripWireTrip: af.tripWireTrip,
-//     weatherChange: af.weatherChange,
-//     worldInitialize: af.worldInitialize,
-// };
-
-
-
-
-
-//   import { register } from "@minecraft/server-gametest";
-//
-  import type { TickEventSignal, TickEvent } from  "../../@types/globalThis"
-//
-  declare const globalThis: GlobalThis;
-//   declare const world: _World & {events:all_Events} ;
-//   export type World =  _World & {events:all_Events}
-//   //不会写
-//   // @ts-ignore
-//   globalThis.world = Object.assign(_world,{events:Events});
-//   globalThis.GameTest = {"register":register};
-  globalThis.Location = Location;
-  globalThis.BlockLocation = BlockLocation;
-//
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/tscripts/main/preload.ts b/tscripts/main/preload.ts
index 3398919..681c032 100644
--- a/tscripts/main/preload.ts
+++ b/tscripts/main/preload.ts
@@ -1,17 +1,6 @@
-import { register } from "@minecraft/server-gametest";
-
-
-import { Location,BlockLocation } from "../lib/xboyPackage/The law of the ancestors is immutable";
-declare const globalThis: GlobalThis;
-
-
-globalThis.GameTest = {"register":register};
-globalThis.Location = Location;
-globalThis.BlockLocation = BlockLocation;
-
 import "../lib/xboyEvents/preload.js"
 
-import ("./main.js")
+import ("./main.js") //这里是为了解决一个莫名其妙的1.21.50触发的bug,当包加载的时候,加载world的部分方法会崩。而异步可以解决
 
 
 
@@ -23,4 +12,6 @@ import ("./main.js")
 // 是真烂(捏鼻子
 // ############### 2023-05-29 ###############
 // 是真烂(捏鼻子
-// ############### 2024-03-08 ###############
\ No newline at end of file
+// ############### 2024-03-08 ###############
+// 是真烂(捏鼻子
+// ############### 2024-11-04 ###############
\ No newline at end of file
diff --git a/tscripts/xTerrain/plugins/test.ts b/tscripts/xTerrain/plugins/test.ts
index 227dcf0..e69de29 100644
--- a/tscripts/xTerrain/plugins/test.ts
+++ b/tscripts/xTerrain/plugins/test.ts
@@ -1,19 +0,0 @@
-import ScoreBase from "../../lib/xboyPackage/scoreBase/rw";
-
-import type { World } from "../../@types/globalThis";
-
-declare const world: World
-
-// for(let i = 0;i<100;i++)
-// world.setDynamicProperty(Math.random()+'8',new Array(102400).fill('1').toString())
-// world.sendMessage(world.getDynamicPropertyTotalByteCount()+" Byte")
-
-// const cow  =
-//     world.getDimension('overworld')
-//         .getEntities({name:'meow~'})[0]
-//         .scoreboardIdentity
-// if(cow.isValid())
-
-// ScoreBase.AssPartic(cow)
-
-// 主索引
\ No newline at end of file