Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to ModAPI 1.0 #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as serverbound_location_v1 from './packets/serverbound/v1/location'
import * as serverbound_party_info_v1 from './packets/serverbound/v1/party_info'
import * as serverbound_register_v1 from './packets/serverbound/v1/register'
import * as serverbound_party_info_v2 from './packets/serverbound/v2/party_info'
import * as serverbound_ping_v1 from './packets/serverbound/v1/ping'
import * as serverbound_player_info_v1 from './packets/serverbound/v1/player_info'

import * as clientbound_location_v1 from './packets/clientbound/v1/location'
import * as clientbound_party_info_v1 from './packets/clientbound/v1/party_info'
import * as clientbound_location_v1 from './packets/clientbound/v1/event/location'
import * as clientbound_hello_v1 from './packets/clientbound/v1/hello'
import * as clientbound_party_info_v2 from './packets/clientbound/v2/party_info'
import * as clientbound_ping_v1 from './packets/clientbound/v1/ping'
import * as clientbound_player_info_v1 from './packets/clientbound/v1/player_info'
import { PacketReader, PacketWriter } from '@lilithmod/unborn-mcproto'
Expand Down Expand Up @@ -41,10 +42,12 @@ export * from './enums'
*/
export const serverboundPackets: Record<number, Record<string, PacketUtils<VersionedPacket>>> = {
1: {
location: serverbound_location_v1,
party_info: serverbound_party_info_v1,
register: serverbound_register_v1,
ping: serverbound_ping_v1,
player_info: serverbound_player_info_v1
},
2: {
party_info: serverbound_party_info_v2
}
}

Expand All @@ -55,9 +58,11 @@ export const serverboundPackets: Record<number, Record<string, PacketUtils<Versi
export const clientboundPackets: Record<number, Record<string, PacketUtils<VersionedPacket>>> = {
1: {
location: clientbound_location_v1,
party_info: clientbound_party_info_v1,
ping: clientbound_ping_v1,
player_info: clientbound_player_info_v1
},
2: {
party_info: clientbound_party_info_v2,
}
}

Expand Down
260 changes: 0 additions & 260 deletions package-lock.json

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"@lilithmod/unborn-mcproto": "^0.14.0"
"@lilithmod/unborn-mcproto": "^0.14.0",
"hypixel-plugin-message": "file:"
},
"devDependencies": {
"@types/node": "^20.12.7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VersionedPacket } from '../../../mod'
import { VersionedPacket } from '../../../../mod'
import { PacketReader, PacketWriter } from '@lilithmod/unborn-mcproto'
import { Environment, environmentToId, getEnvironmentFromId } from '../../../enums'
import { Environment, environmentToId, getEnvironmentFromId } from '../../../../enums'

const CURRENT_VERSION = 1

Expand All @@ -9,8 +9,6 @@ const CURRENT_VERSION = 1
* Similar to /locraw, and based on the same data.
*/
export interface ClientboundLocationPacketV1 extends VersionedPacket {
environment: Environment
proxyName: string
serverName: string
serverType?: string
lobbyName?: string
Expand All @@ -28,8 +26,6 @@ export function read(buffer: Buffer): ClientboundLocationPacketV1 {

const packet: ClientboundLocationPacketV1 = {
version: reader.id,
environment: getEnvironmentFromId(reader.readVarInt()),
proxyName: reader.readString(),
serverName: reader.readString(),
serverType: reader.readOptional(reader.readString.bind(reader)),
lobbyName: reader.readOptional(reader.readString.bind(reader)),
Expand All @@ -54,8 +50,6 @@ export function write(packet: ClientboundLocationPacketV1): Buffer {
const writer = new PacketWriter(CURRENT_VERSION)

writer
.writeVarInt(environmentToId(packet.environment))
.writeString(packet.proxyName)
.writeString(packet.serverName)
.writeOptional(packet.serverType, writer.writeString.bind(writer))
.writeOptional(packet.lobbyName, writer.writeString.bind(writer))
Expand Down
30 changes: 30 additions & 0 deletions packets/clientbound/v1/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PacketReader, PacketWriter } from '@lilithmod/unborn-mcproto'

export interface ClientboundHelloPacket {
environment: number
}

/**
* Reads a clientbound hello packet from a buffer.
* @param buffer A buffer containing the packet data.
* @returns The parsed ClientboundHelloPacket
*/
export function read(buffer: Buffer): ClientboundHelloPacket {
const reader = new PacketReader(buffer)
const environmentId = reader.readVarInt()

const packet: ClientboundHelloPacket = {
environment: environmentId
}

return packet
}

/**
* Writes a clientbound hello packet to a new buffer.
* @param packet The packet to write.
* @returns A buffer containing the packet data.
*/
export function write(packet: ClientboundHelloPacket): Buffer {
return new PacketWriter(packet.environment).buffer
}
Loading