From 630c137ebccd9ff6fb6378b9b99bd4fa3296fc7b Mon Sep 17 00:00:00 2001 From: AnyBananaGAME Date: Tue, 22 Oct 2024 21:28:17 +0300 Subject: [PATCH] format --- src/Connection.ts | 7 +- src/tools/offline.ts | 6 +- src/tools/test.ts | 2 +- src/vendor/Logger.ts | 14 +- src/vendor/PacketSorter.ts | 14 +- src/vendor/packets/AddActorPacket.ts | 13 +- src/vendor/packets/ItemComponentPacket.ts | 2 +- .../packets/LegacyTelemetryEventPacket.ts | 921 +++++++++--------- src/vendor/packets/LevelEventGenericPacket.ts | 4 +- src/vendor/packets/MoveActorDeltaPacket.ts | 4 +- src/vendor/packets/SetActorDataPacket.ts | 11 +- src/vendor/packets/SyncActorPropertyPacket.ts | 4 +- .../packets/UpdateSubChunkBlocksPacket.ts | 102 +- src/vendor/packets/add-item-actor.ts | 11 +- .../current-structure-feature-packet.ts | 2 +- src/vendor/packets/game-rules-changed.ts | 2 +- src/vendor/packets/player-fog-packet.ts | 2 +- src/vendor/packets/set-difficulty-packet.ts | 2 +- src/vendor/packets/set-health.ts | 2 +- .../packets/set-spawn-position-packet.ts | 12 +- src/vendor/packets/trim-data-packet.ts | 4 +- src/vendor/packets/types/CacheableNbt.ts | 26 +- src/vendor/packets/types/ComponentItem.ts | 2 +- src/vendor/packets/types/Fogs.ts | 40 +- src/vendor/packets/types/Materials.ts | 56 +- .../packets/types/MoveActorDeltaData.ts | 211 ++-- src/vendor/packets/types/NbtLoop.ts | 80 +- src/vendor/packets/types/Patterns.ts | 51 +- .../packets/types/UnlockedRecipesEntry.ts | 69 +- src/vendor/packets/types/data-item.ts | 11 +- src/vendor/packets/unlocked-recipes.ts | 2 +- 31 files changed, 920 insertions(+), 769 deletions(-) diff --git a/src/Connection.ts b/src/Connection.ts index 4f48933..577a907 100644 --- a/src/Connection.ts +++ b/src/Connection.ts @@ -1,4 +1,7 @@ -import { Client as RakNetClient, type Advertisement } from "@sanctumterra/raknet"; +import { + Client as RakNetClient, + type Advertisement, +} from "@sanctumterra/raknet"; import { type ClientOptions, @@ -71,7 +74,7 @@ class Connection extends Listener { this.raknet = new RakNetClient({ host: this.options.host, port: this.options.port, - debug: this.options.debug + debug: this.options.debug, }); this.data = new ClientData(this); this.packetSorter = new PacketSorter(this); diff --git a/src/tools/offline.ts b/src/tools/offline.ts index 9a458eb..d7c3332 100644 --- a/src/tools/offline.ts +++ b/src/tools/offline.ts @@ -37,7 +37,11 @@ setTimeout(() => { client.on("TextPacket", handleTextPacket); client.on("spawn", handleSpawn); client.on("UpdateBlockPacket", handleUpdateBlockPacket); -client.on("StartGamePacket", (packet) => { console.log(`Logged in with UniqueID ${packet.entityId} and runtimeID ${packet.runtimeEntityId}`)}); +client.on("StartGamePacket", (packet) => { + console.log( + `Logged in with UniqueID ${packet.entityId} and runtimeID ${packet.runtimeEntityId}`, + ); +}); async function handleTextPacket(packet: TextPacket): Promise { if (!packet.parameters) return Logger.chat(packet.message); diff --git a/src/tools/test.ts b/src/tools/test.ts index 1ec7304..f35e78f 100644 --- a/src/tools/test.ts +++ b/src/tools/test.ts @@ -16,7 +16,7 @@ const client = new Client({ offline: false, username: "SanctumTerra", version: "1.21.30", - port: 19132 + port: 19132, }); try { diff --git a/src/vendor/Logger.ts b/src/vendor/Logger.ts index 405a074..16ffe35 100644 --- a/src/vendor/Logger.ts +++ b/src/vendor/Logger.ts @@ -33,8 +33,8 @@ const colors: { [key: string]: string } = { const specialFormatting: { [key: string]: string } = { l: "\u001B[1m", - o: "\u001B[3m", - k: "\u001B[5m", + o: "\u001B[3m", + k: "\u001B[5m", }; const Logger = { @@ -81,14 +81,16 @@ const Logger = { arg.replace(regex, (match, index) => { const code = match[1].toLowerCase(); - result += arg.slice(lastIndex, index) + (colors[code] || specialFormatting[code] || ""); - + result += + arg.slice(lastIndex, index) + + (colors[code] || specialFormatting[code] || ""); + if (colors[code]) { currentColor = colors[code]; currentFormat = ""; } else if (specialFormatting[code]) { currentFormat += specialFormatting[code]; - } else if (code === 'r') { + } else if (code === "r") { currentColor = ""; currentFormat = ""; } @@ -98,7 +100,7 @@ const Logger = { }); result += arg.slice(lastIndex); - return result + colors.r; + return result + colors.r; }); }, }; diff --git a/src/vendor/PacketSorter.ts b/src/vendor/PacketSorter.ts index ca90311..baf8807 100644 --- a/src/vendor/PacketSorter.ts +++ b/src/vendor/PacketSorter.ts @@ -13,7 +13,7 @@ import { getPacketId, Packet, Packets, - SetScorePacket + SetScorePacket, } from "@serenityjs/protocol"; import { deflateRawSync, inflateRawSync } from "node:zlib"; import { CraftingDataPacket } from "./packets/CraftingDataPacket"; @@ -215,27 +215,27 @@ export class PacketSorter { PacketClass = MoveActorDeltaPacket; } - if((id as number) === 162) { + if ((id as number) === 162) { PacketClass = ItemComponentPacket; } - if((id as number) === 39) { + if ((id as number) === 39) { PacketClass = SetActorDataPacket; } - if((id as number) === 13) { + if ((id as number) === 13) { PacketClass = AddEntityPacket; } - if((id as number) === 15) { + if ((id as number) === 15) { PacketClass = AddItemActorPacket; } - if((id as number) === 65) { + if ((id as number) === 65) { PacketClass = LegacyTelemetryEventPacket; } - if((id as number) === 172) { + if ((id as number) === 172) { PacketClass = UpdateSubChunkBlocksPacket; } diff --git a/src/vendor/packets/AddActorPacket.ts b/src/vendor/packets/AddActorPacket.ts index de49f8f..b9d3ae9 100644 --- a/src/vendor/packets/AddActorPacket.ts +++ b/src/vendor/packets/AddActorPacket.ts @@ -3,9 +3,16 @@ import { Float32, VarLong, VarString, - ZigZong + ZigZong, } from "@serenityjs/binarystream"; -import { DataPacket, EntityAttributes, Links, Packet, PropertySyncData, Vector3f } from "@serenityjs/protocol"; +import { + DataPacket, + EntityAttributes, + Links, + Packet, + PropertySyncData, + Vector3f, +} from "@serenityjs/protocol"; import { Serialize, Proto } from "@serenityjs/raknet"; import { DataItem } from "./types/data-item"; @@ -26,4 +33,4 @@ class AddEntityPacket extends DataPacket { @Serialize(Links) public links!: Array; } -export { AddEntityPacket }; \ No newline at end of file +export { AddEntityPacket }; diff --git a/src/vendor/packets/ItemComponentPacket.ts b/src/vendor/packets/ItemComponentPacket.ts index ec0ae2a..788400c 100644 --- a/src/vendor/packets/ItemComponentPacket.ts +++ b/src/vendor/packets/ItemComponentPacket.ts @@ -4,7 +4,7 @@ import { ComponentItem } from "./types/ComponentItem"; @Proto(Packet.ItemComponent) class ItemComponentPacket extends DataPacket { - @Serialize(ComponentItem) public items!: Array; + @Serialize(ComponentItem) public items!: Array; } export { ItemComponentPacket }; diff --git a/src/vendor/packets/LegacyTelemetryEventPacket.ts b/src/vendor/packets/LegacyTelemetryEventPacket.ts index 4ac2e72..fda3dd3 100644 --- a/src/vendor/packets/LegacyTelemetryEventPacket.ts +++ b/src/vendor/packets/LegacyTelemetryEventPacket.ts @@ -2,453 +2,498 @@ import { BinaryStream, VarInt, VarLong } from "@serenityjs/binarystream"; import { DataPacket } from "@serenityjs/protocol"; import { Proto, Serialize } from "@serenityjs/raknet"; -enum TelemetryEventType { - AchievementAwarded = 0, - EntityInteract = 1, - PortalBuilt = 2, - PortalUsed = 3, - MobKilled = 4, - CauldronUsed = 5, - PlayerDeath = 6, - BossKilled = 7, - AgentCommand = 8, - AgentCreated = 9, - BannerPatternRemoved = 10, - CommandExecuted = 11, - FishBucketed = 12, - MobBorn = 13, - PetDied = 14, - CauldronBlockUsed = 15, - ComposterBlockUsed = 16, - BellBlockUsed = 17, - ActorDefinition = 18, - RaidUpdate = 19, - PlayerMovementAnomaly = 20, - PlayerMovementCorrected = 21, - HoneyHarvested = 22, - TargetBlockHit = 23, - PiglinBarter = 24, - WaxedOrUnwaxedCopper = 25, - CodeBuilderRuntimeAction = 26, - CodeBuilderScoreboard = 27, - StriderRiddenInLavaInOverworld = 28, - SneakCloseToSculkSensor = 29, - CarefulRestoration = 30, - ItemUsed = 31 +enum TelemetryEventType { + AchievementAwarded = 0, + EntityInteract = 1, + PortalBuilt = 2, + PortalUsed = 3, + MobKilled = 4, + CauldronUsed = 5, + PlayerDeath = 6, + BossKilled = 7, + AgentCommand = 8, + AgentCreated = 9, + BannerPatternRemoved = 10, + CommandExecuted = 11, + FishBucketed = 12, + MobBorn = 13, + PetDied = 14, + CauldronBlockUsed = 15, + ComposterBlockUsed = 16, + BellBlockUsed = 17, + ActorDefinition = 18, + RaidUpdate = 19, + PlayerMovementAnomaly = 20, + PlayerMovementCorrected = 21, + HoneyHarvested = 22, + TargetBlockHit = 23, + PiglinBarter = 24, + WaxedOrUnwaxedCopper = 25, + CodeBuilderRuntimeAction = 26, + CodeBuilderScoreboard = 27, + StriderRiddenInLavaInOverworld = 28, + SneakCloseToSculkSensor = 29, + CarefulRestoration = 30, + ItemUsed = 31, } type EventData = { - AchievementAwarded: { achievementId: number }; - EntityInteract: { - interactedEntityId: bigint; - interactionType: number; - interactionActorType: number; - interactionActorVariant: number; - interactionActorColor: number; - }; - PortalBuilt: { dimensionId: number }; - PortalUsed: { fromDimensionId: number; toDimensionId: number }; - MobKilled: { - instigatorActorId: bigint; - targetActorId: bigint; - instigatorChildActorType: number; - damageSource: number; - tradeTier: number; - traderName: string; - }; - CauldronUsed: { contentsColor: number; contentsType: number; fillLevel: number }; - PlayerDeath: { - instigatorActorId: bigint; - instigatorMobVariant: number; - damageSource: number; - diedInRaid: boolean; - }; - BossKilled: { bossActorId: bigint; partySize: number; bossType: number }; - AgentCommand: { result: number; resultNumber: number; commandName: string; resultKey: string; resultString: string }; - AgentCreated: Record; - BannerPatternRemoved: Record; - CommandExecuted: { successCount: number; errorCount: number; commandName: string; errorList: string }; - FishBucketed: Record; - MobBorn: { entityType: number; entityVariant: number; color: number }; - PetDied: { - killedPetEntityType: number; - killedPetVariant: number; - killerEntityType: number; - killerVariant: number; - damageSource: number; - }; - CauldronBlockUsed: { blockInteractionType: number; itemId: number }; - ComposterBlockUsed: { blockInteractionType: number; itemId: number }; - BellBlockUsed: { itemId: number }; - ActorDefinition: { eventName: string }; - RaidUpdate: { currentRaidWave: number; totalRaidWaves: number; wonRaid: boolean }; - PlayerMovementA: Record; - PlayerMovementCorrected: Record; - HoneyHarvested: Record; - TargetBlockHit: { redstoneLevel: number }; - PiglinBarter: { itemId: number; wasTargetingBarteringPlayer: boolean }; - WaxedOrUnwaxedCopper: { playerWaxedOrUnwaxedCopperBlockId: number }; - CodeBuilderRuntimeAction: { codeBuilderRuntimeAction: string }; - CodeBuilderScoreboard: { objectiveName: string; codeBuilderScoreboardScore: number }; - StriderRiddenInLavaInOverworld: Record; - SneakCloseToSculkSensor: Record; - CarefulRestoration: Record; - ItemUsed: { itemId: number; itemAux: number; useMethod: number; useCount: number }; + AchievementAwarded: { achievementId: number }; + EntityInteract: { + interactedEntityId: bigint; + interactionType: number; + interactionActorType: number; + interactionActorVariant: number; + interactionActorColor: number; + }; + PortalBuilt: { dimensionId: number }; + PortalUsed: { fromDimensionId: number; toDimensionId: number }; + MobKilled: { + instigatorActorId: bigint; + targetActorId: bigint; + instigatorChildActorType: number; + damageSource: number; + tradeTier: number; + traderName: string; + }; + CauldronUsed: { + contentsColor: number; + contentsType: number; + fillLevel: number; + }; + PlayerDeath: { + instigatorActorId: bigint; + instigatorMobVariant: number; + damageSource: number; + diedInRaid: boolean; + }; + BossKilled: { bossActorId: bigint; partySize: number; bossType: number }; + AgentCommand: { + result: number; + resultNumber: number; + commandName: string; + resultKey: string; + resultString: string; + }; + AgentCreated: Record; + BannerPatternRemoved: Record; + CommandExecuted: { + successCount: number; + errorCount: number; + commandName: string; + errorList: string; + }; + FishBucketed: Record; + MobBorn: { entityType: number; entityVariant: number; color: number }; + PetDied: { + killedPetEntityType: number; + killedPetVariant: number; + killerEntityType: number; + killerVariant: number; + damageSource: number; + }; + CauldronBlockUsed: { blockInteractionType: number; itemId: number }; + ComposterBlockUsed: { blockInteractionType: number; itemId: number }; + BellBlockUsed: { itemId: number }; + ActorDefinition: { eventName: string }; + RaidUpdate: { + currentRaidWave: number; + totalRaidWaves: number; + wonRaid: boolean; + }; + PlayerMovementA: Record; + PlayerMovementCorrected: Record; + HoneyHarvested: Record; + TargetBlockHit: { redstoneLevel: number }; + PiglinBarter: { itemId: number; wasTargetingBarteringPlayer: boolean }; + WaxedOrUnwaxedCopper: { playerWaxedOrUnwaxedCopperBlockId: number }; + CodeBuilderRuntimeAction: { codeBuilderRuntimeAction: string }; + CodeBuilderScoreboard: { + objectiveName: string; + codeBuilderScoreboardScore: number; + }; + StriderRiddenInLavaInOverworld: Record; + SneakCloseToSculkSensor: Record; + CarefulRestoration: Record; + ItemUsed: { + itemId: number; + itemAux: number; + useMethod: number; + useCount: number; + }; }; @Proto(65) -class LegacyTelemetryEventPacket extends DataPacket { - public unique_id!: bigint; - public type!: TelemetryEventType; - public use_player_id!: number; - public event_data!: EventData[keyof EventData] | undefined; +class LegacyTelemetryEventPacket extends DataPacket { + public unique_id!: bigint; + public type!: TelemetryEventType; + public use_player_id!: number; + public event_data!: EventData[keyof EventData] | undefined; - public override serialize(): Buffer { - this.writeVarInt(65); - this.writeVarLong(this.unique_id); - this.writeVarInt(this.type); - this.writeByte(this.use_player_id); + public override serialize(): Buffer { + this.writeVarInt(65); + this.writeVarLong(this.unique_id); + this.writeVarInt(this.type); + this.writeByte(this.use_player_id); - switch(this.type) { - case TelemetryEventType.AchievementAwarded: { - this.writeVarInt((this.event_data as EventData['AchievementAwarded']).achievementId); - break; - } - case TelemetryEventType.EntityInteract: { - const ei = this.event_data as EventData['EntityInteract']; - this.writeVarLong(ei.interactedEntityId); - this.writeVarInt(ei.interactionType); - this.writeVarInt(ei.interactionActorType); - this.writeVarInt(ei.interactionActorVariant); - this.writeUint8(ei.interactionActorColor); - break; - } - case TelemetryEventType.PortalBuilt: { - this.writeVarInt((this.event_data as EventData['PortalBuilt']).dimensionId); - break; - } - case TelemetryEventType.PortalUsed: { - const pu = this.event_data as EventData['PortalUsed']; - this.writeVarInt(pu.fromDimensionId); - this.writeVarInt(pu.toDimensionId); - break; - } - case TelemetryEventType.MobKilled: { - const mk = this.event_data as EventData['MobKilled']; - this.writeVarLong(mk.instigatorActorId); - this.writeVarLong(mk.targetActorId); - this.writeVarInt(mk.instigatorChildActorType); - this.writeVarInt(mk.damageSource); - this.writeVarInt(mk.tradeTier); - this.writeVarString(mk.traderName); - break; - } - case TelemetryEventType.CauldronUsed: { - const cu = this.event_data as EventData['CauldronUsed']; - this.writeVarInt(cu.contentsColor); - this.writeVarInt(cu.contentsType); - this.writeVarInt(cu.fillLevel); - break; - } - case TelemetryEventType.PlayerDeath: { - const pd = this.event_data as EventData['PlayerDeath']; - this.writeVarLong(pd.instigatorActorId); - this.writeVarInt(pd.instigatorMobVariant); - this.writeVarInt(pd.damageSource); - this.writeBool(pd.diedInRaid); - break; - } - case TelemetryEventType.BossKilled: { - const bk = this.event_data as EventData['BossKilled']; - this.writeVarLong(bk.bossActorId); - this.writeVarInt(bk.partySize); - this.writeVarInt(bk.bossType); - break; - } - case TelemetryEventType.AgentCommand: { - const ac = this.event_data as EventData['AgentCommand']; - this.writeVarInt(ac.result); - this.writeVarInt(ac.resultNumber); - this.writeVarString(ac.commandName); - this.writeVarString(ac.resultKey); - this.writeVarString(ac.resultString); - break; - } - case TelemetryEventType.CommandExecuted: { - const ce = this.event_data as EventData['CommandExecuted']; - this.writeVarInt(ce.successCount); - this.writeVarInt(ce.errorCount); - this.writeVarString(ce.commandName); - this.writeVarString(ce.errorList); - break; - } - case TelemetryEventType.MobBorn: { - const mb = this.event_data as EventData['MobBorn']; - this.writeVarInt(mb.entityType); - this.writeVarInt(mb.entityVariant); - this.writeUint8(mb.color); - break; - } - case TelemetryEventType.PetDied: { - const petd = this.event_data as EventData['PetDied']; - this.writeVarInt(petd.killedPetEntityType); - this.writeVarInt(petd.killedPetVariant); - this.writeVarInt(petd.killerEntityType); - this.writeVarInt(petd.killerVariant); - this.writeVarInt(petd.damageSource); - break; - } - case TelemetryEventType.CauldronBlockUsed: - case TelemetryEventType.ComposterBlockUsed: { - const cbu = this.event_data as EventData['CauldronBlockUsed']; - this.writeVarInt(cbu.blockInteractionType); - this.writeVarInt(cbu.itemId); - break; - } - case TelemetryEventType.BellBlockUsed: { - this.writeVarInt((this.event_data as EventData['BellBlockUsed']).itemId); - break; - } - case TelemetryEventType.ActorDefinition: { - this.writeVarString((this.event_data as EventData['ActorDefinition']).eventName); - break; - } - case TelemetryEventType.RaidUpdate: { - const ru = this.event_data as EventData['RaidUpdate']; - this.writeVarInt(ru.currentRaidWave); - this.writeVarInt(ru.totalRaidWaves); - this.writeBool(ru.wonRaid); - break; - } - case TelemetryEventType.TargetBlockHit: { - this.writeVarInt((this.event_data as EventData['TargetBlockHit']).redstoneLevel); - break; - } - case TelemetryEventType.PiglinBarter: { - const pb = this.event_data as EventData['PiglinBarter']; - this.writeVarInt(pb.itemId); - this.writeBool(pb.wasTargetingBarteringPlayer); - break; - } - case TelemetryEventType.WaxedOrUnwaxedCopper: { - this.writeVarInt((this.event_data as EventData['WaxedOrUnwaxedCopper']).playerWaxedOrUnwaxedCopperBlockId); - break; - } - case TelemetryEventType.CodeBuilderRuntimeAction: { - this.writeVarString((this.event_data as EventData['CodeBuilderRuntimeAction']).codeBuilderRuntimeAction); - break; - } - case TelemetryEventType.CodeBuilderScoreboard: { - const cbs = this.event_data as EventData['CodeBuilderScoreboard']; - this.writeVarString(cbs.objectiveName); - this.writeVarInt(cbs.codeBuilderScoreboardScore); - break; - } - case TelemetryEventType.ItemUsed: { - const iu = this.event_data as EventData['ItemUsed']; - this.writeShort(iu.itemId); - this.writeVarInt(iu.itemAux); - this.writeVarInt(iu.useMethod); - this.writeVarInt(iu.useCount); - break; - } - case TelemetryEventType.AgentCreated: - case TelemetryEventType.BannerPatternRemoved: - case TelemetryEventType.FishBucketed: - case TelemetryEventType.PlayerMovementAnomaly: - case TelemetryEventType.PlayerMovementCorrected: - case TelemetryEventType.HoneyHarvested: - case TelemetryEventType.StriderRiddenInLavaInOverworld: - case TelemetryEventType.SneakCloseToSculkSensor: - case TelemetryEventType.CarefulRestoration: { - break; - } - default: { - break; - } - } + switch (this.type) { + case TelemetryEventType.AchievementAwarded: { + this.writeVarInt( + (this.event_data as EventData["AchievementAwarded"]).achievementId, + ); + break; + } + case TelemetryEventType.EntityInteract: { + const ei = this.event_data as EventData["EntityInteract"]; + this.writeVarLong(ei.interactedEntityId); + this.writeVarInt(ei.interactionType); + this.writeVarInt(ei.interactionActorType); + this.writeVarInt(ei.interactionActorVariant); + this.writeUint8(ei.interactionActorColor); + break; + } + case TelemetryEventType.PortalBuilt: { + this.writeVarInt( + (this.event_data as EventData["PortalBuilt"]).dimensionId, + ); + break; + } + case TelemetryEventType.PortalUsed: { + const pu = this.event_data as EventData["PortalUsed"]; + this.writeVarInt(pu.fromDimensionId); + this.writeVarInt(pu.toDimensionId); + break; + } + case TelemetryEventType.MobKilled: { + const mk = this.event_data as EventData["MobKilled"]; + this.writeVarLong(mk.instigatorActorId); + this.writeVarLong(mk.targetActorId); + this.writeVarInt(mk.instigatorChildActorType); + this.writeVarInt(mk.damageSource); + this.writeVarInt(mk.tradeTier); + this.writeVarString(mk.traderName); + break; + } + case TelemetryEventType.CauldronUsed: { + const cu = this.event_data as EventData["CauldronUsed"]; + this.writeVarInt(cu.contentsColor); + this.writeVarInt(cu.contentsType); + this.writeVarInt(cu.fillLevel); + break; + } + case TelemetryEventType.PlayerDeath: { + const pd = this.event_data as EventData["PlayerDeath"]; + this.writeVarLong(pd.instigatorActorId); + this.writeVarInt(pd.instigatorMobVariant); + this.writeVarInt(pd.damageSource); + this.writeBool(pd.diedInRaid); + break; + } + case TelemetryEventType.BossKilled: { + const bk = this.event_data as EventData["BossKilled"]; + this.writeVarLong(bk.bossActorId); + this.writeVarInt(bk.partySize); + this.writeVarInt(bk.bossType); + break; + } + case TelemetryEventType.AgentCommand: { + const ac = this.event_data as EventData["AgentCommand"]; + this.writeVarInt(ac.result); + this.writeVarInt(ac.resultNumber); + this.writeVarString(ac.commandName); + this.writeVarString(ac.resultKey); + this.writeVarString(ac.resultString); + break; + } + case TelemetryEventType.CommandExecuted: { + const ce = this.event_data as EventData["CommandExecuted"]; + this.writeVarInt(ce.successCount); + this.writeVarInt(ce.errorCount); + this.writeVarString(ce.commandName); + this.writeVarString(ce.errorList); + break; + } + case TelemetryEventType.MobBorn: { + const mb = this.event_data as EventData["MobBorn"]; + this.writeVarInt(mb.entityType); + this.writeVarInt(mb.entityVariant); + this.writeUint8(mb.color); + break; + } + case TelemetryEventType.PetDied: { + const petd = this.event_data as EventData["PetDied"]; + this.writeVarInt(petd.killedPetEntityType); + this.writeVarInt(petd.killedPetVariant); + this.writeVarInt(petd.killerEntityType); + this.writeVarInt(petd.killerVariant); + this.writeVarInt(petd.damageSource); + break; + } + case TelemetryEventType.CauldronBlockUsed: + case TelemetryEventType.ComposterBlockUsed: { + const cbu = this.event_data as EventData["CauldronBlockUsed"]; + this.writeVarInt(cbu.blockInteractionType); + this.writeVarInt(cbu.itemId); + break; + } + case TelemetryEventType.BellBlockUsed: { + this.writeVarInt( + (this.event_data as EventData["BellBlockUsed"]).itemId, + ); + break; + } + case TelemetryEventType.ActorDefinition: { + this.writeVarString( + (this.event_data as EventData["ActorDefinition"]).eventName, + ); + break; + } + case TelemetryEventType.RaidUpdate: { + const ru = this.event_data as EventData["RaidUpdate"]; + this.writeVarInt(ru.currentRaidWave); + this.writeVarInt(ru.totalRaidWaves); + this.writeBool(ru.wonRaid); + break; + } + case TelemetryEventType.TargetBlockHit: { + this.writeVarInt( + (this.event_data as EventData["TargetBlockHit"]).redstoneLevel, + ); + break; + } + case TelemetryEventType.PiglinBarter: { + const pb = this.event_data as EventData["PiglinBarter"]; + this.writeVarInt(pb.itemId); + this.writeBool(pb.wasTargetingBarteringPlayer); + break; + } + case TelemetryEventType.WaxedOrUnwaxedCopper: { + this.writeVarInt( + (this.event_data as EventData["WaxedOrUnwaxedCopper"]) + .playerWaxedOrUnwaxedCopperBlockId, + ); + break; + } + case TelemetryEventType.CodeBuilderRuntimeAction: { + this.writeVarString( + (this.event_data as EventData["CodeBuilderRuntimeAction"]) + .codeBuilderRuntimeAction, + ); + break; + } + case TelemetryEventType.CodeBuilderScoreboard: { + const cbs = this.event_data as EventData["CodeBuilderScoreboard"]; + this.writeVarString(cbs.objectiveName); + this.writeVarInt(cbs.codeBuilderScoreboardScore); + break; + } + case TelemetryEventType.ItemUsed: { + const iu = this.event_data as EventData["ItemUsed"]; + this.writeShort(iu.itemId); + this.writeVarInt(iu.itemAux); + this.writeVarInt(iu.useMethod); + this.writeVarInt(iu.useCount); + break; + } + case TelemetryEventType.AgentCreated: + case TelemetryEventType.BannerPatternRemoved: + case TelemetryEventType.FishBucketed: + case TelemetryEventType.PlayerMovementAnomaly: + case TelemetryEventType.PlayerMovementCorrected: + case TelemetryEventType.HoneyHarvested: + case TelemetryEventType.StriderRiddenInLavaInOverworld: + case TelemetryEventType.SneakCloseToSculkSensor: + case TelemetryEventType.CarefulRestoration: { + break; + } + default: { + break; + } + } - return this.getBuffer(); - } - public override deserialize(): this { - this.readVarInt(); - this.unique_id = this.readVarLong(); - this.type = this.readVarInt() as TelemetryEventType; - this.use_player_id = this.readByte(); - console.log(this.getBuffer()); - switch(this.type) { - case TelemetryEventType.AchievementAwarded: - this.event_data = { achievementId: this.readVarInt() }; - break; - case TelemetryEventType.EntityInteract: - this.event_data = { - interactedEntityId: this.readVarLong(), - interactionType: this.readVarInt(), - interactionActorType: this.readVarInt(), - interactionActorVariant: this.readVarInt(), - interactionActorColor: this.readUint8() - }; - break; - case TelemetryEventType.PortalBuilt: - this.event_data = { dimensionId: this.readVarInt() }; - break; - case TelemetryEventType.PortalUsed: - this.event_data = { - fromDimensionId: this.readVarInt(), - toDimensionId: this.readVarInt() - }; - break; - case TelemetryEventType.MobKilled: - this.event_data = { - instigatorActorId: this.readVarLong(), - targetActorId: this.readVarLong(), - instigatorChildActorType: this.readVarInt(), - damageSource: this.readVarInt(), - tradeTier: this.readVarInt(), - traderName: this.readVarString() - }; - break; - case TelemetryEventType.CauldronUsed: - this.event_data = { - contentsColor: this.readVarInt(), - contentsType: this.readVarInt(), - fillLevel: this.readVarInt() - }; - break; - case TelemetryEventType.PlayerDeath: - this.event_data = { - instigatorActorId: this.readVarLong(), - instigatorMobVariant: this.readVarInt(), - damageSource: this.readVarInt(), - diedInRaid: this.readBool() - }; - break; - case TelemetryEventType.BossKilled: - this.event_data = { - bossActorId: this.readVarLong(), - partySize: this.readVarInt(), - bossType: this.readVarInt() - }; - break; - case TelemetryEventType.AgentCommand: - this.event_data = { - result: this.readVarInt(), - resultNumber: this.readVarInt(), - commandName: this.readVarString(), - resultKey: this.readVarString(), - resultString: this.readVarString() - }; - break; - case TelemetryEventType.AgentCreated: - this.event_data = {}; - break; - case TelemetryEventType.BannerPatternRemoved: - this.event_data = {}; - break; - case TelemetryEventType.CommandExecuted: - this.event_data = { - successCount: this.readVarInt(), - errorCount: this.readVarInt(), - commandName: this.readVarString(), - errorList: this.readVarString() - }; - break; - case TelemetryEventType.FishBucketed: - this.event_data = {}; - break; - case TelemetryEventType.MobBorn: - this.event_data = { - entityType: this.readVarInt(), - entityVariant: this.readVarInt(), - color: this.readUint8() - }; - break; - case TelemetryEventType.PetDied: - this.event_data = { - killedPetEntityType: this.readVarInt(), - killedPetVariant: this.readVarInt(), - killerEntityType: this.readVarInt(), - killerVariant: this.readVarInt(), - damageSource: this.readVarInt() - }; - break; - case TelemetryEventType.CauldronBlockUsed: - this.event_data = { - blockInteractionType: this.readVarInt(), - itemId: this.readVarInt() - }; - break; - case TelemetryEventType.ComposterBlockUsed: - this.event_data = { - blockInteractionType: this.readVarInt(), - itemId: this.readVarInt() - }; - break; - case TelemetryEventType.BellBlockUsed: - this.event_data = { itemId: this.readVarInt() }; - break; - case TelemetryEventType.ActorDefinition: - this.event_data = { eventName: this.readVarString() }; - break; - case TelemetryEventType.RaidUpdate: - this.event_data = { - currentRaidWave: this.readVarInt(), - totalRaidWaves: this.readVarInt(), - wonRaid: this.readBool() - }; - break; - case TelemetryEventType.PlayerMovementAnomaly: - this.event_data = {}; - break; - case TelemetryEventType.PlayerMovementCorrected: - this.event_data = {}; - break; - case TelemetryEventType.HoneyHarvested: - this.event_data = {}; - break; - case TelemetryEventType.TargetBlockHit: - this.event_data = { redstoneLevel: this.readVarInt() }; - break; - case TelemetryEventType.PiglinBarter: - this.event_data = { - itemId: this.readVarInt(), - wasTargetingBarteringPlayer: this.readBool() - }; - break; - case TelemetryEventType.WaxedOrUnwaxedCopper: - this.event_data = { playerWaxedOrUnwaxedCopperBlockId: this.readVarInt() }; - break; - case TelemetryEventType.CodeBuilderRuntimeAction: - this.event_data = { codeBuilderRuntimeAction: this.readVarString() }; - break; - case TelemetryEventType.CodeBuilderScoreboard: - this.event_data = { - objectiveName: this.readVarString(), - codeBuilderScoreboardScore: this.readVarInt() - }; - break; - case TelemetryEventType.StriderRiddenInLavaInOverworld: - this.event_data = {}; - break; - case TelemetryEventType.SneakCloseToSculkSensor: - this.event_data = {}; - break; - case TelemetryEventType.CarefulRestoration: - this.event_data = {}; - break; - case TelemetryEventType.ItemUsed: - this.event_data = { - itemId: this.readShort(), - itemAux: this.readVarInt(), - useMethod: this.readVarInt(), - useCount: this.readVarInt() - }; - break; - default: - this.event_data = undefined; - } - return this; - } + return this.getBuffer(); + } + public override deserialize(): this { + this.readVarInt(); + this.unique_id = this.readVarLong(); + this.type = this.readVarInt() as TelemetryEventType; + this.use_player_id = this.readByte(); + console.log(this.getBuffer()); + switch (this.type) { + case TelemetryEventType.AchievementAwarded: + this.event_data = { achievementId: this.readVarInt() }; + break; + case TelemetryEventType.EntityInteract: + this.event_data = { + interactedEntityId: this.readVarLong(), + interactionType: this.readVarInt(), + interactionActorType: this.readVarInt(), + interactionActorVariant: this.readVarInt(), + interactionActorColor: this.readUint8(), + }; + break; + case TelemetryEventType.PortalBuilt: + this.event_data = { dimensionId: this.readVarInt() }; + break; + case TelemetryEventType.PortalUsed: + this.event_data = { + fromDimensionId: this.readVarInt(), + toDimensionId: this.readVarInt(), + }; + break; + case TelemetryEventType.MobKilled: + this.event_data = { + instigatorActorId: this.readVarLong(), + targetActorId: this.readVarLong(), + instigatorChildActorType: this.readVarInt(), + damageSource: this.readVarInt(), + tradeTier: this.readVarInt(), + traderName: this.readVarString(), + }; + break; + case TelemetryEventType.CauldronUsed: + this.event_data = { + contentsColor: this.readVarInt(), + contentsType: this.readVarInt(), + fillLevel: this.readVarInt(), + }; + break; + case TelemetryEventType.PlayerDeath: + this.event_data = { + instigatorActorId: this.readVarLong(), + instigatorMobVariant: this.readVarInt(), + damageSource: this.readVarInt(), + diedInRaid: this.readBool(), + }; + break; + case TelemetryEventType.BossKilled: + this.event_data = { + bossActorId: this.readVarLong(), + partySize: this.readVarInt(), + bossType: this.readVarInt(), + }; + break; + case TelemetryEventType.AgentCommand: + this.event_data = { + result: this.readVarInt(), + resultNumber: this.readVarInt(), + commandName: this.readVarString(), + resultKey: this.readVarString(), + resultString: this.readVarString(), + }; + break; + case TelemetryEventType.AgentCreated: + this.event_data = {}; + break; + case TelemetryEventType.BannerPatternRemoved: + this.event_data = {}; + break; + case TelemetryEventType.CommandExecuted: + this.event_data = { + successCount: this.readVarInt(), + errorCount: this.readVarInt(), + commandName: this.readVarString(), + errorList: this.readVarString(), + }; + break; + case TelemetryEventType.FishBucketed: + this.event_data = {}; + break; + case TelemetryEventType.MobBorn: + this.event_data = { + entityType: this.readVarInt(), + entityVariant: this.readVarInt(), + color: this.readUint8(), + }; + break; + case TelemetryEventType.PetDied: + this.event_data = { + killedPetEntityType: this.readVarInt(), + killedPetVariant: this.readVarInt(), + killerEntityType: this.readVarInt(), + killerVariant: this.readVarInt(), + damageSource: this.readVarInt(), + }; + break; + case TelemetryEventType.CauldronBlockUsed: + this.event_data = { + blockInteractionType: this.readVarInt(), + itemId: this.readVarInt(), + }; + break; + case TelemetryEventType.ComposterBlockUsed: + this.event_data = { + blockInteractionType: this.readVarInt(), + itemId: this.readVarInt(), + }; + break; + case TelemetryEventType.BellBlockUsed: + this.event_data = { itemId: this.readVarInt() }; + break; + case TelemetryEventType.ActorDefinition: + this.event_data = { eventName: this.readVarString() }; + break; + case TelemetryEventType.RaidUpdate: + this.event_data = { + currentRaidWave: this.readVarInt(), + totalRaidWaves: this.readVarInt(), + wonRaid: this.readBool(), + }; + break; + case TelemetryEventType.PlayerMovementAnomaly: + this.event_data = {}; + break; + case TelemetryEventType.PlayerMovementCorrected: + this.event_data = {}; + break; + case TelemetryEventType.HoneyHarvested: + this.event_data = {}; + break; + case TelemetryEventType.TargetBlockHit: + this.event_data = { redstoneLevel: this.readVarInt() }; + break; + case TelemetryEventType.PiglinBarter: + this.event_data = { + itemId: this.readVarInt(), + wasTargetingBarteringPlayer: this.readBool(), + }; + break; + case TelemetryEventType.WaxedOrUnwaxedCopper: + this.event_data = { + playerWaxedOrUnwaxedCopperBlockId: this.readVarInt(), + }; + break; + case TelemetryEventType.CodeBuilderRuntimeAction: + this.event_data = { codeBuilderRuntimeAction: this.readVarString() }; + break; + case TelemetryEventType.CodeBuilderScoreboard: + this.event_data = { + objectiveName: this.readVarString(), + codeBuilderScoreboardScore: this.readVarInt(), + }; + break; + case TelemetryEventType.StriderRiddenInLavaInOverworld: + this.event_data = {}; + break; + case TelemetryEventType.SneakCloseToSculkSensor: + this.event_data = {}; + break; + case TelemetryEventType.CarefulRestoration: + this.event_data = {}; + break; + case TelemetryEventType.ItemUsed: + this.event_data = { + itemId: this.readShort(), + itemAux: this.readVarInt(), + useMethod: this.readVarInt(), + useCount: this.readVarInt(), + }; + break; + default: + this.event_data = undefined; + } + return this; + } } export { LegacyTelemetryEventPacket, TelemetryEventType, type EventData }; diff --git a/src/vendor/packets/LevelEventGenericPacket.ts b/src/vendor/packets/LevelEventGenericPacket.ts index 82b9352..a2efce1 100644 --- a/src/vendor/packets/LevelEventGenericPacket.ts +++ b/src/vendor/packets/LevelEventGenericPacket.ts @@ -6,8 +6,8 @@ import { CompoundTag } from "@serenityjs/nbt"; @Proto(124) class LevelEventGenericPacket extends DataPacket { - @Serialize(VarInt) public eventId!: number; - @Serialize(NbtLoop) public nbtData!: NbtLoop; + @Serialize(VarInt) public eventId!: number; + @Serialize(NbtLoop) public nbtData!: NbtLoop; } export { LevelEventGenericPacket }; diff --git a/src/vendor/packets/MoveActorDeltaPacket.ts b/src/vendor/packets/MoveActorDeltaPacket.ts index 3026c95..681f91a 100644 --- a/src/vendor/packets/MoveActorDeltaPacket.ts +++ b/src/vendor/packets/MoveActorDeltaPacket.ts @@ -5,7 +5,7 @@ import { MoveActorDeltaData } from "./types/MoveActorDeltaData"; @Proto(111) class MoveActorDeltaPacket extends DataPacket { - @Serialize(MoveActorDeltaData) public actorData!: MoveActorDeltaData; + @Serialize(MoveActorDeltaData) public actorData!: MoveActorDeltaData; } -export { MoveActorDeltaPacket }; \ No newline at end of file +export { MoveActorDeltaPacket }; diff --git a/src/vendor/packets/SetActorDataPacket.ts b/src/vendor/packets/SetActorDataPacket.ts index a106094..a2674ef 100644 --- a/src/vendor/packets/SetActorDataPacket.ts +++ b/src/vendor/packets/SetActorDataPacket.ts @@ -1,11 +1,18 @@ import { VarLong } from "@serenityjs/binarystream"; -import { ActorDataId, ActorDataType, type ActorFlag, DataPacket, Packet, PropertySyncData } from "@serenityjs/protocol"; +import { + ActorDataId, + ActorDataType, + type ActorFlag, + DataPacket, + Packet, + PropertySyncData, +} from "@serenityjs/protocol"; import { Proto, Serialize } from "@serenityjs/raknet"; import { DataItem } from "./types/data-item"; @Proto(Packet.SetActorData) class SetActorDataPacket extends DataPacket { - @Serialize(VarLong) public runtimeEntityId!: bigint; + @Serialize(VarLong) public runtimeEntityId!: bigint; @Serialize(DataItem) public data!: Array; @Serialize(PropertySyncData) public properties!: PropertySyncData; @Serialize(VarLong) public tick!: bigint; diff --git a/src/vendor/packets/SyncActorPropertyPacket.ts b/src/vendor/packets/SyncActorPropertyPacket.ts index 2dc355a..9ef4144 100644 --- a/src/vendor/packets/SyncActorPropertyPacket.ts +++ b/src/vendor/packets/SyncActorPropertyPacket.ts @@ -6,7 +6,7 @@ import { VarInt } from "@serenityjs/binarystream"; @Proto(165) class SyncActorPropertyPacket extends DataPacket { - @Serialize(CompoundTag, true) public properties!: CompoundTag; + @Serialize(CompoundTag, true) public properties!: CompoundTag; } -export { SyncActorPropertyPacket }; \ No newline at end of file +export { SyncActorPropertyPacket }; diff --git a/src/vendor/packets/UpdateSubChunkBlocksPacket.ts b/src/vendor/packets/UpdateSubChunkBlocksPacket.ts index 061fecf..bcdd0bf 100644 --- a/src/vendor/packets/UpdateSubChunkBlocksPacket.ts +++ b/src/vendor/packets/UpdateSubChunkBlocksPacket.ts @@ -2,71 +2,69 @@ import type { BinaryStream } from "@serenityjs/binarystream"; import { BlockPosition, DataPacket } from "@serenityjs/protocol"; import { DataType, Proto, Serialize } from "@serenityjs/raknet"; - type Block = { - position: BlockPosition; - runtimeId: number; - updateFlags: number; - entityUniqueId: bigint; - message: number; -} + position: BlockPosition; + runtimeId: number; + updateFlags: number; + entityUniqueId: bigint; + message: number; +}; class BlocksChangedStandard extends DataType { - public blocks: Block[]; + public blocks: Block[]; - constructor(blocks: Block[]) { - super(); - this.blocks = blocks; - } + constructor(blocks: Block[]) { + super(); + this.blocks = blocks; + } - static override read(stream: BinaryStream): BlocksChangedStandard { - const count = stream.readVarInt(); - const blocks = []; - for(let i = 0; i < count; i++) { - const block: Block = { - position: BlockPosition.read(stream), - runtimeId: stream.readVarInt(), - updateFlags: stream.readVarInt(), - entityUniqueId: stream.readVarLong(), - message: stream.readVarInt(), - } - blocks.push(block); - } - return new BlocksChangedStandard(blocks); - } + static override read(stream: BinaryStream): BlocksChangedStandard { + const count = stream.readVarInt(); + const blocks = []; + for (let i = 0; i < count; i++) { + const block: Block = { + position: BlockPosition.read(stream), + runtimeId: stream.readVarInt(), + updateFlags: stream.readVarInt(), + entityUniqueId: stream.readVarLong(), + message: stream.readVarInt(), + }; + blocks.push(block); + } + return new BlocksChangedStandard(blocks); + } } class BlocksChangedExtra extends DataType { - public blocks: Block[]; + public blocks: Block[]; - constructor(blocks: Block[]) { - super(); - this.blocks = blocks; - } + constructor(blocks: Block[]) { + super(); + this.blocks = blocks; + } - static override read(stream: BinaryStream): BlocksChangedStandard { - const count = stream.readVarInt(); - const blocks = []; - for(let i = 0; i < count; i++) { - const block: Block = { - position: BlockPosition.read(stream), - runtimeId: stream.readVarInt(), - updateFlags: stream.readVarInt(), - entityUniqueId: stream.readVarLong(), - message: stream.readVarInt(), - } - blocks.push(block); - } - return new BlocksChangedStandard(blocks); - } + static override read(stream: BinaryStream): BlocksChangedStandard { + const count = stream.readVarInt(); + const blocks = []; + for (let i = 0; i < count; i++) { + const block: Block = { + position: BlockPosition.read(stream), + runtimeId: stream.readVarInt(), + updateFlags: stream.readVarInt(), + entityUniqueId: stream.readVarLong(), + message: stream.readVarInt(), + }; + blocks.push(block); + } + return new BlocksChangedStandard(blocks); + } } - @Proto(172) -class UpdateSubChunkBlocksPacket extends DataPacket { - @Serialize(BlockPosition) public position!: BlockPosition; - @Serialize(BlocksChangedStandard) public blocks!: BlocksChangedStandard; - @Serialize(BlocksChangedExtra) public extraBlocks!: BlocksChangedExtra; +class UpdateSubChunkBlocksPacket extends DataPacket { + @Serialize(BlockPosition) public position!: BlockPosition; + @Serialize(BlocksChangedStandard) public blocks!: BlocksChangedStandard; + @Serialize(BlocksChangedExtra) public extraBlocks!: BlocksChangedExtra; } export { UpdateSubChunkBlocksPacket }; diff --git a/src/vendor/packets/add-item-actor.ts b/src/vendor/packets/add-item-actor.ts index e88459a..f2513c0 100644 --- a/src/vendor/packets/add-item-actor.ts +++ b/src/vendor/packets/add-item-actor.ts @@ -1,10 +1,13 @@ import { Bool, VarLong, ZigZong } from "@serenityjs/binarystream"; -import { DataPacket, NetworkItemStackDescriptor, Packet, Vector3f } from "@serenityjs/protocol"; +import { + DataPacket, + NetworkItemStackDescriptor, + Packet, + Vector3f, +} from "@serenityjs/protocol"; import { Serialize, Proto } from "@serenityjs/raknet"; import { DataItem } from "./types/data-item"; - - @Proto(Packet.AddItemActor) class AddItemActorPacket extends DataPacket { @Serialize(ZigZong) public uniqueId!: bigint; @@ -18,4 +21,4 @@ class AddItemActorPacket extends DataPacket { @Serialize(Bool) public fromFishing!: boolean; } -export { AddItemActorPacket }; \ No newline at end of file +export { AddItemActorPacket }; diff --git a/src/vendor/packets/current-structure-feature-packet.ts b/src/vendor/packets/current-structure-feature-packet.ts index f720061..c15c71c 100644 --- a/src/vendor/packets/current-structure-feature-packet.ts +++ b/src/vendor/packets/current-structure-feature-packet.ts @@ -4,7 +4,7 @@ import { Proto, Serialize } from "@serenityjs/raknet"; @Proto(314) class CurrectStructureFeaturePacket extends DataPacket { - @Serialize(VarString) public featureId!: string; + @Serialize(VarString) public featureId!: string; } export { CurrectStructureFeaturePacket }; diff --git a/src/vendor/packets/game-rules-changed.ts b/src/vendor/packets/game-rules-changed.ts index e84d509..26a3a8f 100644 --- a/src/vendor/packets/game-rules-changed.ts +++ b/src/vendor/packets/game-rules-changed.ts @@ -3,7 +3,7 @@ import { Proto, Serialize } from "@serenityjs/raknet"; @Proto(72) class GameRulesChangedPacket extends DataPacket { - @Serialize(GameRules) public rules!: GameRules; + @Serialize(GameRules) public rules!: GameRules; } export { GameRulesChangedPacket }; diff --git a/src/vendor/packets/player-fog-packet.ts b/src/vendor/packets/player-fog-packet.ts index ab52167..9e2d4c2 100644 --- a/src/vendor/packets/player-fog-packet.ts +++ b/src/vendor/packets/player-fog-packet.ts @@ -5,7 +5,7 @@ import { Fogs } from "./types/Fogs"; @Proto(160) class PlayerFogPacket extends DataPacket { - @Serialize(Fogs) public stack!: Fogs; + @Serialize(Fogs) public stack!: Fogs; } export { PlayerFogPacket }; diff --git a/src/vendor/packets/set-difficulty-packet.ts b/src/vendor/packets/set-difficulty-packet.ts index 8ac795e..5c5ff31 100644 --- a/src/vendor/packets/set-difficulty-packet.ts +++ b/src/vendor/packets/set-difficulty-packet.ts @@ -5,7 +5,7 @@ import { Proto, Serialize } from "@serenityjs/raknet"; @Proto(60) class SetDifficultyPacket extends DataPacket { - @Serialize(VarInt) public difficulty!: Difficulty; + @Serialize(VarInt) public difficulty!: Difficulty; } export { SetDifficultyPacket }; diff --git a/src/vendor/packets/set-health.ts b/src/vendor/packets/set-health.ts index 7f4aef5..8741544 100644 --- a/src/vendor/packets/set-health.ts +++ b/src/vendor/packets/set-health.ts @@ -4,7 +4,7 @@ import { Proto, Serialize } from "@serenityjs/raknet"; @Proto(42) class SetHealthPacket extends DataPacket { - @Serialize(ZigZag) public health!: number; + @Serialize(ZigZag) public health!: number; } export { SetHealthPacket }; diff --git a/src/vendor/packets/set-spawn-position-packet.ts b/src/vendor/packets/set-spawn-position-packet.ts index 3bfe6d9..94adfdc 100644 --- a/src/vendor/packets/set-spawn-position-packet.ts +++ b/src/vendor/packets/set-spawn-position-packet.ts @@ -4,16 +4,16 @@ import { BlockPosition, DataPacket } from "@serenityjs/protocol"; import { ZigZag } from "@serenityjs/binarystream"; enum SpawnType { - Player = 0, - World = 1 + Player = 0, + World = 1, } @Proto(43) class SetSpawnPositionPacket extends DataPacket { - @Serialize(ZigZag) public spawnType!: SpawnType; - @Serialize(BlockPosition) public playerPosition!: BlockPosition; - @Serialize(ZigZag) public dimension!: number; - @Serialize(BlockPosition) public worldPosition!: BlockPosition; + @Serialize(ZigZag) public spawnType!: SpawnType; + @Serialize(BlockPosition) public playerPosition!: BlockPosition; + @Serialize(ZigZag) public dimension!: number; + @Serialize(BlockPosition) public worldPosition!: BlockPosition; } export { SetSpawnPositionPacket }; diff --git a/src/vendor/packets/trim-data-packet.ts b/src/vendor/packets/trim-data-packet.ts index 7917830..4909c12 100644 --- a/src/vendor/packets/trim-data-packet.ts +++ b/src/vendor/packets/trim-data-packet.ts @@ -5,8 +5,8 @@ import { Materials } from "./types/Materials"; @Proto(302) class TrimDataPacket extends DataPacket { - @Serialize(Patterns) public patterns!: Patterns; - @Serialize(Materials) public materials!: Materials; + @Serialize(Patterns) public patterns!: Patterns; + @Serialize(Materials) public materials!: Materials; } export { TrimDataPacket }; diff --git a/src/vendor/packets/types/CacheableNbt.ts b/src/vendor/packets/types/CacheableNbt.ts index 47c34ef..af340b9 100644 --- a/src/vendor/packets/types/CacheableNbt.ts +++ b/src/vendor/packets/types/CacheableNbt.ts @@ -3,22 +3,22 @@ import { BinaryStream } from "@serenityjs/binarystream"; import { CompoundTag, type Tag } from "@serenityjs/nbt"; class CacheableNbt extends DataType { - private properties: CompoundTag; + private properties: CompoundTag; - constructor(properties: CompoundTag) { - super(); - this.properties = properties; - } + constructor(properties: CompoundTag) { + super(); + this.properties = properties; + } - static override read(stream: BinaryStream): CacheableNbt { - const tempStream = new BinaryStream(stream.readRemainingBuffer()); - const tag = CompoundTag.read(tempStream, true); - return new CacheableNbt(tag); - } + static override read(stream: BinaryStream): CacheableNbt { + const tempStream = new BinaryStream(stream.readRemainingBuffer()); + const tag = CompoundTag.read(tempStream, true); + return new CacheableNbt(tag); + } - static override write(stream: BinaryStream, value: CacheableNbt): void { - CompoundTag.write(stream, value.properties, true); - } + static override write(stream: BinaryStream, value: CacheableNbt): void { + CompoundTag.write(stream, value.properties, true); + } } export { CacheableNbt }; diff --git a/src/vendor/packets/types/ComponentItem.ts b/src/vendor/packets/types/ComponentItem.ts index a80b24f..c956256 100644 --- a/src/vendor/packets/types/ComponentItem.ts +++ b/src/vendor/packets/types/ComponentItem.ts @@ -49,4 +49,4 @@ class ComponentItem extends DataType { } } -export { ComponentItem }; \ No newline at end of file +export { ComponentItem }; diff --git a/src/vendor/packets/types/Fogs.ts b/src/vendor/packets/types/Fogs.ts index 39b6657..7594d8e 100644 --- a/src/vendor/packets/types/Fogs.ts +++ b/src/vendor/packets/types/Fogs.ts @@ -2,29 +2,29 @@ import type { BinaryStream } from "@serenityjs/binarystream"; import { DataType } from "@serenityjs/raknet"; class Fogs extends DataType { - public fogs: string[]; + public fogs: string[]; - constructor(fogs: string[] = []) { - super(); - this.fogs = fogs; - } + constructor(fogs: string[] = []) { + super(); + this.fogs = fogs; + } - public static read(stream: BinaryStream): Fogs { - const fogs = new Fogs(); - const length = stream.readVarInt(); - for (let i = 0; i < length; i++) { - const fog = stream.readVarString(); - fogs.fogs.push(fog); - } - return fogs; - } + public static read(stream: BinaryStream): Fogs { + const fogs = new Fogs(); + const length = stream.readVarInt(); + for (let i = 0; i < length; i++) { + const fog = stream.readVarString(); + fogs.fogs.push(fog); + } + return fogs; + } - public static write(stream: BinaryStream, value: Fogs): void { - stream.writeVarInt(value.fogs.length); - for (const fog of value.fogs) { - stream.writeVarString(fog); - } - } + public static write(stream: BinaryStream, value: Fogs): void { + stream.writeVarInt(value.fogs.length); + for (const fog of value.fogs) { + stream.writeVarString(fog); + } + } } export { Fogs }; diff --git a/src/vendor/packets/types/Materials.ts b/src/vendor/packets/types/Materials.ts index 727907e..4ac7c72 100644 --- a/src/vendor/packets/types/Materials.ts +++ b/src/vendor/packets/types/Materials.ts @@ -2,39 +2,39 @@ import type { BinaryStream } from "@serenityjs/binarystream"; import { DataType } from "@serenityjs/raknet"; type TrimDataMaterial = { - material: string; - color: string; - item_name: string; -} + material: string; + color: string; + item_name: string; +}; class Materials extends DataType { - public materials: TrimDataMaterial[]; + public materials: TrimDataMaterial[]; - constructor(materials: TrimDataMaterial[] = []) { - super(); - this.materials = materials; - } + constructor(materials: TrimDataMaterial[] = []) { + super(); + this.materials = materials; + } - public static read(stream: BinaryStream): Materials { - const materials = new Materials(); - const length = stream.readVarInt(); - for (let i = 0; i < length; i++) { - const material = stream.readVarString(); - const color = stream.readVarString(); - const item_name = stream.readVarString(); - materials.materials.push({ material, color, item_name }); - } - return materials; - } + public static read(stream: BinaryStream): Materials { + const materials = new Materials(); + const length = stream.readVarInt(); + for (let i = 0; i < length; i++) { + const material = stream.readVarString(); + const color = stream.readVarString(); + const item_name = stream.readVarString(); + materials.materials.push({ material, color, item_name }); + } + return materials; + } - public static write(stream: BinaryStream, value: Materials): void { - stream.writeVarInt(value.materials.length); - for (const material of value.materials) { - stream.writeVarString(material.material); - stream.writeVarString(material.color); - stream.writeVarString(material.item_name); - } - } + public static write(stream: BinaryStream, value: Materials): void { + stream.writeVarInt(value.materials.length); + for (const material of value.materials) { + stream.writeVarString(material.material); + stream.writeVarString(material.color); + stream.writeVarString(material.item_name); + } + } } export { Materials }; diff --git a/src/vendor/packets/types/MoveActorDeltaData.ts b/src/vendor/packets/types/MoveActorDeltaData.ts index f92d102..d40301a 100644 --- a/src/vendor/packets/types/MoveActorDeltaData.ts +++ b/src/vendor/packets/types/MoveActorDeltaData.ts @@ -10,85 +10,166 @@ export enum MoveActorDeltaFlags { FLAG_HAS_HEAD_YAW = 0x20, FLAG_GROUND = 0x40, FLAG_TELEPORT = 0x80, - FLAG_FORCE_MOVE_LOCAL_ENTITY = 0x100 + FLAG_FORCE_MOVE_LOCAL_ENTITY = 0x100, } class MoveActorDeltaData extends DataType { - public runtimeEntityId: bigint; - public flags: number; - public xPos: number; - public yPos: number; - public zPos: number; - public pitch: number; - public yaw: number; - public headYaw: number; + public runtimeEntityId: bigint; + public flags: number; + public xPos: number; + public yPos: number; + public zPos: number; + public pitch: number; + public yaw: number; + public headYaw: number; - constructor( - runtimeEntityId: bigint, - flags: number, - xPos: number, - yPos: number, - zPos: number, - pitch: number, - yaw: number, - headYaw: number - ) { - super(); - this.runtimeEntityId = runtimeEntityId; - this.flags = flags; - this.xPos = xPos; - this.yPos = yPos; - this.zPos = zPos; - this.pitch = pitch; - this.yaw = yaw; - this.headYaw = headYaw; - } + constructor( + runtimeEntityId: bigint, + flags: number, + xPos: number, + yPos: number, + zPos: number, + pitch: number, + yaw: number, + headYaw: number, + ) { + super(); + this.runtimeEntityId = runtimeEntityId; + this.flags = flags; + this.xPos = xPos; + this.yPos = yPos; + this.zPos = zPos; + this.pitch = pitch; + this.yaw = yaw; + this.headYaw = headYaw; + } - static readPossibleCoordinate(stream: BinaryStream, flags: number, flag: number): number { - if((flags & flag) !== 0){ + static readPossibleCoordinate( + stream: BinaryStream, + flags: number, + flag: number, + ): number { + if ((flags & flag) !== 0) { return stream.readFloat32(Endianness.Little); } - return 0.0; - } - static readPossibleRotation(stream: BinaryStream, flags: number, flag: number): number { - if((flags & flag) !== 0){ - return (stream.readByte()* (360 / 256)) + return 0.0; + } + static readPossibleRotation( + stream: BinaryStream, + flags: number, + flag: number, + ): number { + if ((flags & flag) !== 0) { + return stream.readByte() * (360 / 256); } - return 0.0; - } + return 0.0; + } - static writePossibleCoordinate(stream: BinaryStream, value: number, flags: number, flag: number): void { - if((flags & flag) !== 0){ + static writePossibleCoordinate( + stream: BinaryStream, + value: number, + flags: number, + flag: number, + ): void { + if ((flags & flag) !== 0) { stream.writeFloat32(value, Endianness.Little); } - } - static writePossibleRotation(stream: BinaryStream, value: number, flags: number, flag: number): void { - if((flags & flag) !== 0){ - stream.writeByte((value / (360 / 256))); + } + static writePossibleRotation( + stream: BinaryStream, + value: number, + flags: number, + flag: number, + ): void { + if ((flags & flag) !== 0) { + stream.writeByte(value / (360 / 256)); } - } + } - static override read(stream: BinaryStream): MoveActorDeltaData { - const runtimeEntityId = stream.readVarLong(); - const flags = stream.readShort(Endianness.Little); - const xPos = MoveActorDeltaData.readPossibleCoordinate(stream, flags, MoveActorDeltaFlags.FLAG_HAS_X); - const yPos = MoveActorDeltaData.readPossibleCoordinate(stream, flags, MoveActorDeltaFlags.FLAG_HAS_Y); - const zPos = MoveActorDeltaData.readPossibleCoordinate(stream, flags, MoveActorDeltaFlags.FLAG_HAS_Z); - const pitch = MoveActorDeltaData.readPossibleRotation(stream, flags, MoveActorDeltaFlags.FLAG_HAS_PITCH); - const yaw = MoveActorDeltaData.readPossibleRotation(stream, flags, MoveActorDeltaFlags.FLAG_HAS_YAW); - const headYaw = MoveActorDeltaData.readPossibleRotation(stream, flags, MoveActorDeltaFlags.FLAG_HAS_HEAD_YAW); - return new MoveActorDeltaData(runtimeEntityId, flags, xPos, yPos, zPos, pitch, yaw, headYaw); - } + static override read(stream: BinaryStream): MoveActorDeltaData { + const runtimeEntityId = stream.readVarLong(); + const flags = stream.readShort(Endianness.Little); + const xPos = MoveActorDeltaData.readPossibleCoordinate( + stream, + flags, + MoveActorDeltaFlags.FLAG_HAS_X, + ); + const yPos = MoveActorDeltaData.readPossibleCoordinate( + stream, + flags, + MoveActorDeltaFlags.FLAG_HAS_Y, + ); + const zPos = MoveActorDeltaData.readPossibleCoordinate( + stream, + flags, + MoveActorDeltaFlags.FLAG_HAS_Z, + ); + const pitch = MoveActorDeltaData.readPossibleRotation( + stream, + flags, + MoveActorDeltaFlags.FLAG_HAS_PITCH, + ); + const yaw = MoveActorDeltaData.readPossibleRotation( + stream, + flags, + MoveActorDeltaFlags.FLAG_HAS_YAW, + ); + const headYaw = MoveActorDeltaData.readPossibleRotation( + stream, + flags, + MoveActorDeltaFlags.FLAG_HAS_HEAD_YAW, + ); + return new MoveActorDeltaData( + runtimeEntityId, + flags, + xPos, + yPos, + zPos, + pitch, + yaw, + headYaw, + ); + } - static override write(stream: BinaryStream, value: MoveActorDeltaData): void { - stream.writeShort(value.flags, Endianness.Little); - MoveActorDeltaData.writePossibleCoordinate(stream, value.xPos, value.flags, MoveActorDeltaFlags.FLAG_HAS_X); - MoveActorDeltaData.writePossibleCoordinate(stream, value.yPos, value.flags, MoveActorDeltaFlags.FLAG_HAS_Y); - MoveActorDeltaData.writePossibleCoordinate(stream, value.zPos, value.flags, MoveActorDeltaFlags.FLAG_HAS_Z); - MoveActorDeltaData.writePossibleRotation(stream, value.pitch, value.flags, MoveActorDeltaFlags.FLAG_HAS_PITCH); - MoveActorDeltaData.writePossibleRotation(stream, value.yaw, value.flags, MoveActorDeltaFlags.FLAG_HAS_YAW); - MoveActorDeltaData.writePossibleRotation(stream, value.headYaw, value.flags, MoveActorDeltaFlags.FLAG_HAS_HEAD_YAW); - } + static override write(stream: BinaryStream, value: MoveActorDeltaData): void { + stream.writeShort(value.flags, Endianness.Little); + MoveActorDeltaData.writePossibleCoordinate( + stream, + value.xPos, + value.flags, + MoveActorDeltaFlags.FLAG_HAS_X, + ); + MoveActorDeltaData.writePossibleCoordinate( + stream, + value.yPos, + value.flags, + MoveActorDeltaFlags.FLAG_HAS_Y, + ); + MoveActorDeltaData.writePossibleCoordinate( + stream, + value.zPos, + value.flags, + MoveActorDeltaFlags.FLAG_HAS_Z, + ); + MoveActorDeltaData.writePossibleRotation( + stream, + value.pitch, + value.flags, + MoveActorDeltaFlags.FLAG_HAS_PITCH, + ); + MoveActorDeltaData.writePossibleRotation( + stream, + value.yaw, + value.flags, + MoveActorDeltaFlags.FLAG_HAS_YAW, + ); + MoveActorDeltaData.writePossibleRotation( + stream, + value.headYaw, + value.flags, + MoveActorDeltaFlags.FLAG_HAS_HEAD_YAW, + ); + } } export { MoveActorDeltaData }; diff --git a/src/vendor/packets/types/NbtLoop.ts b/src/vendor/packets/types/NbtLoop.ts index 62326ef..fecaf1a 100644 --- a/src/vendor/packets/types/NbtLoop.ts +++ b/src/vendor/packets/types/NbtLoop.ts @@ -3,47 +3,45 @@ import { DataType } from "@serenityjs/raknet"; import { CompoundTag } from "@serenityjs/nbt"; class NbtLoop extends DataType { - public data: CompoundTag | null; - - constructor(data: CompoundTag | null) { - super(); - this.data = data; - } - - public static read(stream: BinaryStream): NbtLoop { - try { - const buffer = stream.readRemainingBuffer(); - const wrappedBuffer = new BinaryStream(Buffer.concat([ - Buffer.from([0x0a, 0x00]), - buffer, - Buffer.from([0x00]) - ])); - const compound = CompoundTag.read(wrappedBuffer, true); - return new NbtLoop(compound); - } catch (error) { - throw new Error(`Error reading NbtLoop: ${(error as Error).message}`); - } - } - - public static write(stream: BinaryStream, entry: NbtLoop): void { - if (entry.data === null) { - stream.writeBuffer(Buffer.from([0x00])); - return; - } - - try { - const tempStream = new BinaryStream(); - CompoundTag.write(tempStream, entry.data, true); - const buffer = tempStream.getBuffer(); - - // Remove the compound wrapper (first 2 bytes and last byte) - const unwrappedBuffer = buffer.slice(2, buffer.length - 1); - - stream.writeBuffer(unwrappedBuffer); - } catch (error) { - throw new Error(`Error writing NbtLoop: ${(error as Error).message}`); - } - } + public data: CompoundTag | null; + + constructor(data: CompoundTag | null) { + super(); + this.data = data; + } + + public static read(stream: BinaryStream): NbtLoop { + try { + const buffer = stream.readRemainingBuffer(); + const wrappedBuffer = new BinaryStream( + Buffer.concat([Buffer.from([0x0a, 0x00]), buffer, Buffer.from([0x00])]), + ); + const compound = CompoundTag.read(wrappedBuffer, true); + return new NbtLoop(compound); + } catch (error) { + throw new Error(`Error reading NbtLoop: ${(error as Error).message}`); + } + } + + public static write(stream: BinaryStream, entry: NbtLoop): void { + if (entry.data === null) { + stream.writeBuffer(Buffer.from([0x00])); + return; + } + + try { + const tempStream = new BinaryStream(); + CompoundTag.write(tempStream, entry.data, true); + const buffer = tempStream.getBuffer(); + + // Remove the compound wrapper (first 2 bytes and last byte) + const unwrappedBuffer = buffer.slice(2, buffer.length - 1); + + stream.writeBuffer(unwrappedBuffer); + } catch (error) { + throw new Error(`Error writing NbtLoop: ${(error as Error).message}`); + } + } } export { NbtLoop }; diff --git a/src/vendor/packets/types/Patterns.ts b/src/vendor/packets/types/Patterns.ts index fb34263..c42164b 100644 --- a/src/vendor/packets/types/Patterns.ts +++ b/src/vendor/packets/types/Patterns.ts @@ -2,36 +2,35 @@ import type { BinaryStream } from "@serenityjs/binarystream"; import { DataType } from "@serenityjs/raknet"; export type TrimDataPattern = { - item_name: string; - pattern: string; -} + item_name: string; + pattern: string; +}; class Patterns extends DataType { - public patterns: TrimDataPattern[]; - + public patterns: TrimDataPattern[]; - constructor(patterns: TrimDataPattern[] = []) { - super(); - this.patterns = patterns; - } + constructor(patterns: TrimDataPattern[] = []) { + super(); + this.patterns = patterns; + } - public static read(stream: BinaryStream): Patterns { - const patterns = new Patterns(); - const length = stream.readVarInt(); - for (let i = 0; i < length; i++) { - const item_name = stream.readVarString(); - const pattern = stream.readVarString(); - patterns.patterns.push({ item_name, pattern }); - } - return patterns; - } - public static write(stream: BinaryStream, value: Patterns): void { - stream.writeVarInt(value.patterns.length); - for (const pattern of value.patterns) { - stream.writeVarString(pattern.item_name); - stream.writeVarString(pattern.pattern); - } - } + public static read(stream: BinaryStream): Patterns { + const patterns = new Patterns(); + const length = stream.readVarInt(); + for (let i = 0; i < length; i++) { + const item_name = stream.readVarString(); + const pattern = stream.readVarString(); + patterns.patterns.push({ item_name, pattern }); + } + return patterns; + } + public static write(stream: BinaryStream, value: Patterns): void { + stream.writeVarInt(value.patterns.length); + for (const pattern of value.patterns) { + stream.writeVarString(pattern.item_name); + stream.writeVarString(pattern.pattern); + } + } } export { Patterns }; diff --git a/src/vendor/packets/types/UnlockedRecipesEntry.ts b/src/vendor/packets/types/UnlockedRecipesEntry.ts index 365bcb1..2d3e207 100644 --- a/src/vendor/packets/types/UnlockedRecipesEntry.ts +++ b/src/vendor/packets/types/UnlockedRecipesEntry.ts @@ -2,44 +2,43 @@ import { Endianness, type BinaryStream } from "@serenityjs/binarystream"; import { DataType, Serialize } from "@serenityjs/raknet"; enum UnlockedRecipesType { - EMPTY = 0, - INITIALLY_UNLOCKED = 1, - NEWLY_UNLOCKED = 2, - REMOVED = 3, - REMOVED_ALL = 4 + EMPTY = 0, + INITIALLY_UNLOCKED = 1, + NEWLY_UNLOCKED = 2, + REMOVED = 3, + REMOVED_ALL = 4, } class UnlockedRecipesEntry extends DataType { - public type: UnlockedRecipesType; - public recipes: string[] = []; - - public constructor(type: UnlockedRecipesType, recipes: string[]) { - super(); - this.type = type; - this.recipes = recipes; - } - - public static write(stream: BinaryStream, value: UnlockedRecipesEntry): void { - stream.writeInt32(value.type, Endianness.Little); - stream.writeVarInt(value.recipes.length); - for (const recipe of value.recipes) { - stream.writeVarString(recipe); - } - } - - public static read(stream: BinaryStream): UnlockedRecipesEntry { - const recipes = []; - const type = stream.readInt32(Endianness.Little); - const recipeCount = stream.readVarInt(); - - for (let i = 0; i < recipeCount; i++) { - recipes.push(stream.readVarString()); - } - - console.log(stream.readRemainingBuffer()); - return new UnlockedRecipesEntry(type, recipes); - } + public type: UnlockedRecipesType; + public recipes: string[] = []; + + public constructor(type: UnlockedRecipesType, recipes: string[]) { + super(); + this.type = type; + this.recipes = recipes; + } + + public static write(stream: BinaryStream, value: UnlockedRecipesEntry): void { + stream.writeInt32(value.type, Endianness.Little); + stream.writeVarInt(value.recipes.length); + for (const recipe of value.recipes) { + stream.writeVarString(recipe); + } + } + + public static read(stream: BinaryStream): UnlockedRecipesEntry { + const recipes = []; + const type = stream.readInt32(Endianness.Little); + const recipeCount = stream.readVarInt(); + + for (let i = 0; i < recipeCount; i++) { + recipes.push(stream.readVarString()); + } + + console.log(stream.readRemainingBuffer()); + return new UnlockedRecipesEntry(type, recipes); + } } export { UnlockedRecipesEntry }; - diff --git a/src/vendor/packets/types/data-item.ts b/src/vendor/packets/types/data-item.ts index 75689da..43c004c 100644 --- a/src/vendor/packets/types/data-item.ts +++ b/src/vendor/packets/types/data-item.ts @@ -1,7 +1,12 @@ import { DataType } from "@serenityjs/raknet"; import { type BinaryStream, Endianness } from "@serenityjs/binarystream"; import { CompoundTag } from "@serenityjs/nbt"; -import { type ActorDataId, ActorDataType, BlockPosition, Vector3f } from "@serenityjs/protocol"; +import { + type ActorDataId, + ActorDataType, + BlockPosition, + Vector3f, +} from "@serenityjs/protocol"; class DataItem extends DataType { /** @@ -107,7 +112,7 @@ class DataItem extends DataType { public static override write( stream: BinaryStream, - data: Array + data: Array, ): void { // Write the number of data items. stream.writeVarInt(data.length); @@ -171,4 +176,4 @@ class DataItem extends DataType { } } -export { DataItem }; \ No newline at end of file +export { DataItem }; diff --git a/src/vendor/packets/unlocked-recipes.ts b/src/vendor/packets/unlocked-recipes.ts index e892a8b..ab7f297 100644 --- a/src/vendor/packets/unlocked-recipes.ts +++ b/src/vendor/packets/unlocked-recipes.ts @@ -4,7 +4,7 @@ import { UnlockedRecipesEntry } from "./types/UnlockedRecipesEntry"; @Proto(199) class UnlockedRecipesPacket extends DataPacket { - @Serialize(UnlockedRecipesEntry) public recipes!: UnlockedRecipesEntry; + @Serialize(UnlockedRecipesEntry) public recipes!: UnlockedRecipesEntry; } export { UnlockedRecipesPacket };