Skip to content

Commit

Permalink
清理游戏脚本引擎快速更新时期留下来的辅助工具
Browse files Browse the repository at this point in the history
  • Loading branch information
xBoyMinemc committed Nov 4, 2024
1 parent cc5a6d8 commit 92f56b8
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 366 deletions.
216 changes: 3 additions & 213 deletions tscripts/@types/globalThis.d.ts
Original file line number Diff line number Diff line change
@@ -1,189 +1,22 @@
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 {
Location,
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.
*/
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions tscripts/lib/xboyEvents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions tscripts/lib/xboyEvents/projectileFired.ts
Original file line number Diff line number Diff line change
@@ -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;



Expand All @@ -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"
?(
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions tscripts/lib/xboyEvents/reloadFromCmd.ts
Original file line number Diff line number Diff line change
@@ -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"]>();
Expand All @@ -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)
)

Expand Down
19 changes: 0 additions & 19 deletions tscripts/lib/xboyEvents/tick.ts

This file was deleted.

Loading

0 comments on commit 92f56b8

Please sign in to comment.