feat: modify GMLIB_BinaryStream API to return the BinaryStream object itself after each method call

This commit is contained in:
子沐呀
2024-10-10 18:45:02 +08:00
Unverified
parent fd672f675f
commit 01d9499970
3 changed files with 203 additions and 42 deletions
+110 -35
View File
@@ -1054,9 +1054,78 @@ declare class UserCache {
static getAllPlayerInfo(): { Xuid: String; Uuid: string; Name: string; }[] static getAllPlayerInfo(): { Xuid: String; Uuid: string; Name: string; }[]
} }
type PacketDataItem = (
{
id: number,
type: 0x0 | 0x1 | 0x2 | 0x3 | 0x7,
value: number
}
| {
id: number,
type: 0x4,
value: string
}
| {
id: number,
type: 0x5,
value: NbtCompound
}
| {
id: number,
type: 0x6 | 0x8,
value: IntPos | FloatPos
}
);
type PacketData = (
{ type: "Item", value: Item }
| { type: "CompoundTag", value: NbtCompound }
| {
type: "DataItem",
value: PacketDataItem[],
}
| {
type: "ActorLink",
value: {
mA: number,
mB: number,
mType: number,
mImmediate: boolean,
mPassengerInitiated: boolean,
},
}
| { type: "Vec3" | "BlockPos", value: FloatPos | IntPos }
| { type: "Vec2", value: DirectionAngle }
| { type: "String" | "Uuid", value: string }
| { type: "Bool", value: boolean }
| {
type:
"PacketHeader"
| "Byte"
| "Double"
| "Float"
| "SignedBigEndianInt"
| "SignedInt"
| "SignedInt64"
| "SignedShort"
| "UnsignedChar"
| "UnsignedInt"
| "UnsignedInt64"
| "UnsignedShort"
| "UnsignedVarInt"
| "UnsignedVarInt64"
| "VarInt"
| "VarInt64",
value: number,
}
);
/** 二进制流数据包类 */ /** 二进制流数据包类 */
declare class GMLIB_BinaryStream { declare class GMLIB_BinaryStream {
constructor(); constructor(
/** 数据包数据 */
data: PacketData[]?
);
/** 发送数据包 */ /** 发送数据包 */
sendTo( sendTo(
@@ -1064,7 +1133,7 @@ declare class GMLIB_BinaryStream {
player: Player, player: Player,
/** 数据包发送后是否销毁 */ /** 数据包发送后是否销毁 */
free: boolean = true free: boolean = true
): void; ): GMLIB_BinaryStream;
/** 发送数据包到玩家数组 */ /** 发送数据包到玩家数组 */
sendToPlayers( sendToPlayers(
@@ -1072,13 +1141,13 @@ declare class GMLIB_BinaryStream {
players: Player[], players: Player[],
/** 数据包发送后是否销毁 */ /** 数据包发送后是否销毁 */
free: boolean = true free: boolean = true
): void; ): GMLIB_BinaryStream;
/** 发送数据包到所有玩家 */ /** 发送数据包到所有玩家 */
sendToAll( sendToAll(
/** 数据包发送后是否销毁 */ /** 数据包发送后是否销毁 */
free: boolean = true free: boolean = true
): void; ): GMLIB_BinaryStream;
/** 发送数据包到维度 */ /** 发送数据包到维度 */
sendToDimension( sendToDimension(
@@ -1086,168 +1155,174 @@ declare class GMLIB_BinaryStream {
dimid: number, dimid: number,
/** 数据包发送后是否销毁 */ /** 数据包发送后是否销毁 */
free: boolean = true free: boolean = true
): void; ): GMLIB_BinaryStream;
/** 销毁数据包 */ /** 销毁数据包 */
destroy(): void; destroy(): GMLIB_BinaryStream;
/** 重置数据包 */ /** 重置数据包 */
reset(): void; reset(): GMLIB_BinaryStream;
/** 写入数据 */
write(
/** 数据 */
data: PacketData | PacketData[]?
): GMLIB_BinaryStream;
/** 写入数据包头部 */ /** 写入数据包头部 */
writePacketHeader( writePacketHeader(
/** 数据包ID */ /** 数据包ID */
id: number id: number
): void; ): GMLIB_BinaryStream;
/** 写入UUID */ /** 写入UUID */
writeUuid( writeUuid(
/** UUID */ /** UUID */
value: string value: string
): void; ): GMLIB_BinaryStream;
/** 写入物品 */ /** 写入物品 */
writeItem( writeItem(
/** 物品对象 */ /** 物品对象 */
value: Item value: Item
): void; ): GMLIB_BinaryStream;
/** 写入NBT */ /** 写入NBT */
writeCompoundTag( writeCompoundTag(
/** NBT */ /** NBT */
value: NbtCompound value: NbtCompound
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeDataItem( writeDataItem(
/** 数据项 */ /** 数据项 */
value: { "id": number, "type": number, "value": string | IntPos | FloatPos | number | NbtCompound }[] value: PacketDataItem[]
): void; ): GMLIB_BinaryStream;
writeActorLink( writeActorLink(
/** 数据项 */ /** 数据项 */
value: {"mA":number,"mB":number,"mType":number,"mImmediate":boolean,"mPassengerInitiated":boolean} value: { "mA": number, "mB": number, "mType": number, "mImmediate": boolean, "mPassengerInitiated": boolean }
): void; ): GMLIB_BinaryStream;
/** 写入浮点数坐标对象 */ /** 写入浮点数坐标对象 */
writeVec3( writeVec3(
/** 浮点数坐标对象 */ /** 浮点数坐标对象 */
value: FloatPos value: FloatPos
) : void; ): GMLIB_BinaryStream;
/** 写入整数坐标对象 */ /** 写入整数坐标对象 */
writeBlockPos( writeBlockPos(
/** 整数坐标对象 */ /** 整数坐标对象 */
value: IntPos value: IntPos
) : void; ): GMLIB_BinaryStream;
/** 写入方向角对象 */ /** 写入方向角对象 */
writeVec2( writeVec2(
/** 方向角对象 */ /** 方向角对象 */
value: DirectionAngle value: DirectionAngle
) : void; ): GMLIB_BinaryStream;
/** 写入字符串 */ /** 写入字符串 */
writeString( writeString(
/** 字符串 */ /** 字符串 */
value: string value: string
): void; ): GMLIB_BinaryStream;
/** 写入布尔值 */ /** 写入布尔值 */
writeBool( writeBool(
/** 布尔值 */ /** 布尔值 */
value: boolean value: boolean
): void; ): GMLIB_BinaryStream;
/** 写入字节 */ /** 写入字节 */
writeByte( writeByte(
/** 字节 */ /** 字节 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** 写入(双精度)浮点数 */ /** 写入(双精度)浮点数 */
writeDouble( writeDouble(
/** 浮点数 */ /** 浮点数 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** 写入(单精度)浮点数 */ /** 写入(单精度)浮点数 */
writeFloat( writeFloat(
/** 浮点数 */ /** 浮点数 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeSignedBigEndianInt( writeSignedBigEndianInt(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeSignedInt( writeSignedInt(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** 写入 */ /** 写入 */
writeSignedInt64( writeSignedInt64(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeSignedShort( writeSignedShort(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeUnsignedChar( writeUnsignedChar(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeUnsignedInt( writeUnsignedInt(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeUnsignedInt64( writeUnsignedInt64(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeUnsignedShort( writeUnsignedShort(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeUnsignedVarInt( writeUnsignedVarInt(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeUnsignedVarInt64( writeUnsignedVarInt64(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeVarInt( writeVarInt(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
/** */ /** */
writeVarInt64( writeVarInt64(
/** 数值 */ /** 数值 */
value: number value: number
): void; ): GMLIB_BinaryStream;
} }
interface Player { interface Player {
+88 -6
View File
@@ -380,7 +380,7 @@ const GMLIB_API = {
const GMLIB_BinaryStream_API = { const GMLIB_BinaryStream_API = {
/** 创建二进制流数据包 @type {function():number} */ /** 创建二进制流数据包 @type {function():number} */
create: ll.import("GMLIB_BinaryStream_API", "create"), create: ll.import("GMLIB_BinaryStream_API", "create"),
/** 发送二进制流数据包 @type {function(number,player, boolean):void} */ /** 发送二进制流数据包 @type {function(number,player):void} */
sendTo: ll.import("GMLIB_BinaryStream_API", "sendTo"), sendTo: ll.import("GMLIB_BinaryStream_API", "sendTo"),
/** 销毁二进制流数据包 @type {function(number):void} */ /** 销毁二进制流数据包 @type {function(number):void} */
destroy: ll.import("GMLIB_BinaryStream_API", "destroy"), destroy: ll.import("GMLIB_BinaryStream_API", "destroy"),
@@ -2114,107 +2114,146 @@ class GMLIB_BinaryStream {
/** 数据包是否被销毁 */ /** 数据包是否被销毁 */
#destroy = false; #destroy = false;
constructor() { /**
* 创建二进制流数据包
* @param {{"type":string,"value":any}[]?} value 写入数据
* @returns {GMLIB_BinaryStream}
*/
constructor(value) {
this.#id = GMLIB_BinaryStream_API.create(); this.#id = GMLIB_BinaryStream_API.create();
if (Array.isArray(value)) this.write(value);
} }
/** /**
* 发送数据包 * 发送数据包
* @param {Player} player 玩家 * @param {Player} player 玩家
* @param {boolean} [free=true] 发送后销毁数据包 * @param {boolean} [free=true] 发送后销毁数据包
* @returns {GMLIB_BinaryStream}
*/ */
sendTo(player, free = true) { sendTo(player, free = true) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.sendTo(this.#id, player, free); GMLIB_BinaryStream_API.sendTo(this.#id, player);
if (free) this.destroy(); if (free) this.destroy();
return this;
} }
/** /**
* 发送数据包到玩家 * 发送数据包到玩家
* @param {Player[]} players 玩家对象数组 * @param {Player[]} players 玩家对象数组
* @param {boolean} free 发送后销毁数据包 * @param {boolean} free 发送后销毁数据包
* @returns {GMLIB_BinaryStream}
*/ */
sendToPlayers(players, free = true) { sendToPlayers(players, free = true) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
players.forEach(player => this.sendTo(player, false)); players.forEach(player => this.sendTo(player, false));
if (free) this.destroy(); if (free) this.destroy();
return this;
} }
/** /**
* 发送数据包到所有玩家 * 发送数据包到所有玩家
* @param {boolean} [free=true] 发送后销毁数据包 * @param {boolean} [free=true] 发送后销毁数据包
* @returns {GMLIB_BinaryStream}
*/ */
sendToAll(free = true) { sendToAll(free = true) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
mc.getOnlinePlayers().forEach(player => this.sendTo(player, false)); mc.getOnlinePlayers().forEach(player => this.sendTo(player, false));
if (free) this.destroy(); if (free) this.destroy();
return this;
} }
/** /**
* 发送数据包到维度 * 发送数据包到维度
* @param {number} dimid 维度ID * @param {number} dimid 维度ID
* @param {boolean} [free=true] 发送后销毁数据包 * @param {boolean} [free=true] 发送后销毁数据包
* @returns {GMLIB_BinaryStream}
*/ */
sendToDimension(dimid, free = true) { sendToDimension(dimid, free = true) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
mc.getOnlinePlayers().filter(player => player.pos.dimid === dimid).forEach(player => this.sendTo(player, false)); mc.getOnlinePlayers().filter(player => player.pos.dimid === dimid).forEach(player => this.sendTo(player, false));
if (free) this.destroy(); if (free) this.destroy();
return this;
} }
/** /**
* 销毁数据包 * 销毁数据包
* @returns {GMLIB_BinaryStream}
*/ */
destroy() { destroy() {
GMLIB_BinaryStream_API.destroy(this.#id); GMLIB_BinaryStream_API.destroy(this.#id);
this.#destroy = true; this.#destroy = true;
return this;
} }
/** /**
* 重置数据包 * 重置数据包
* @returns {GMLIB_BinaryStream}
*/ */
reset() { reset() {
GMLIB_BinaryStream_API.reset(this.#id); GMLIB_BinaryStream_API.reset(this.#id);
this.#destroy = false; this.#destroy = false;
return this;
}
/**
* 写入数据
* @param {{"type":string,"value":any}[]|{"type":string,"value":any}} value 数据
* @returns {GMLIB_BinaryStream}
*/
write(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
if (Array.isArray(value)) value.forEach(v => this.write(v));
if (value?.type != null && value?.value != null) this[`write${value.type}`]?.(value.value);
return this;
} }
/** /**
* 写入数据包头部 * 写入数据包头部
* @param {number} id 数据包ID * @param {number} id 数据包ID
* @returns {GMLIB_BinaryStream}
*/ */
writePacketHeader(id) { writePacketHeader(id) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writePacketHeader(this.#id, id); GMLIB_BinaryStream_API.writePacketHeader(this.#id, id);
return this;
} }
/** /**
* 写入UUID * 写入UUID
* @param {string} value UUID * @param {string} value UUID
* @returns {GMLIB_BinaryStream}
*/ */
writeUuid(value) { writeUuid(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeUuid(this.#id, value); GMLIB_BinaryStream_API.writeUuid(this.#id, value);
return this;
} }
/** /**
* 写入物品 * 写入物品
* @param {Item} value 物品 * @param {Item} value 物品
* @returns {GMLIB_BinaryStream}
*/ */
writeItem(value){ writeItem(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeItem(this.#id, value); GMLIB_BinaryStream_API.writeItem(this.#id, value);
return this;
} }
/** /**
* 写入NBT * 写入NBT
* @param {NbtCompound} value NBT * @param {NbtCompound} value NBT
* @returns {GMLIB_BinaryStream}
*/ */
writeCompoundTag(value){ writeCompoundTag(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeCompoundTag(this.#id, value); GMLIB_BinaryStream_API.writeCompoundTag(this.#id, value);
return this;
} }
/** /**
* @param {{"id":number,"type":number,"value":string|IntPos|FloatPos|number|NbtCompound}[]} value 数据 * @param {{"id":number,"type":number,"value":string|IntPos|FloatPos|number|NbtCompound}[]} value 数据
* @returns {GMLIB_BinaryStream}
*/ */
writeDataItem(value) { writeDataItem(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
@@ -2235,10 +2274,12 @@ class GMLIB_BinaryStream {
default: throw new Error("Unknown data type"); default: throw new Error("Unknown data type");
} }
} }
return this;
} }
/** /**
* @param {{"mA":number,"mB":number,"mType":number,"mImmediate":boolean,"mPassengerInitiated":boolean}} value 数据 * @param {{"mA":number,"mB":number,"mType":number,"mImmediate":boolean,"mPassengerInitiated":boolean}} value 数据
* @returns {GMLIB_BinaryStream}
*/ */
writeActorLink(value) { writeActorLink(value) {
this.writeVarInt64(value.mA); this.writeVarInt64(value.mA);
@@ -2246,179 +2287,220 @@ class GMLIB_BinaryStream {
this.writeUnsignedChar(value.mType); this.writeUnsignedChar(value.mType);
this.writeBool(value.mImmediate); this.writeBool(value.mImmediate);
this.writeBool(value.mPassengerInitiated); this.writeBool(value.mPassengerInitiated);
return this;
} }
/** /**
* 写入字符串 * 写入字符串
* @param {string} value 字符串 * @param {string} value 字符串
* @returns {GMLIB_BinaryStream}
*/ */
writeString(value){ writeString(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeString(this.#id, value); GMLIB_BinaryStream_API.writeString(this.#id, value);
return this;
} }
/** /**
* 写入布尔值 * 写入布尔值
* @param {boolean} value 布尔值 * @param {boolean} value 布尔值
* @returns {GMLIB_BinaryStream}
*/ */
writeBool(value) { writeBool(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeBool(this.#id, value); GMLIB_BinaryStream_API.writeBool(this.#id, value);
return this;
} }
/** /**
* 写入字节 * 写入字节
* @param {number} value 字节 * @param {number} value 字节
* @returns {GMLIB_BinaryStream}
*/ */
writeByte(value) { writeByte(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeByte(this.#id, value); GMLIB_BinaryStream_API.writeByte(this.#id, value);
return this;
} }
/** /**
* 写入(双精度)浮点数 * 写入(双精度)浮点数
* @param {number} value 浮点数 * @param {number} value 浮点数
* @returns {GMLIB_BinaryStream}
*/ */
writeDouble(value) { writeDouble(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeDouble(this.#id, value); GMLIB_BinaryStream_API.writeDouble(this.#id, value);
return this;
} }
/** /**
* 写入(单精度)浮点数 * 写入(单精度)浮点数
* @param {number} value 浮点数 * @param {number} value 浮点数
* @returns {GMLIB_BinaryStream}
*/ */
writeFloat(value) { writeFloat(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeFloat(this.#id, value); GMLIB_BinaryStream_API.writeFloat(this.#id, value);
return this;
} }
/** /**
* 写入浮点数坐标对象 * 写入浮点数坐标对象
* @param {FloatPos} value 浮点数坐标对象 * @param {FloatPos} value 浮点数坐标对象
* @returns {GMLIB_BinaryStream}
*/ */
writeVec3({ x, y, z }) { writeVec3({ x, y, z }) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
this.writeFloat(x); this.writeFloat(x);
this.writeFloat(y); this.writeFloat(y);
this.writeFloat(z); this.writeFloat(z);
return this;
} }
/** /**
* 写入整数坐标对象 * 写入整数坐标对象
* @param {IntPos} value 整数坐标对象 * @param {IntPos} value 整数坐标对象
* @returns {GMLIB_BinaryStream}
*/ */
writeBlockPos({ x, y, z }) { writeBlockPos({ x, y, z }) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
this.writeVarInt(x); this.writeVarInt(x);
this.writeUnsignedVarInt(y); this.writeUnsignedVarInt(y);
this.writeVarInt(z); this.writeVarInt(z);
return this;
} }
/** /**
* 写入方向角对象 * 写入方向角对象
* @param {DirectionAngle} value 方向角对象 * @param {DirectionAngle} value 方向角对象
* @returns {GMLIB_BinaryStream}
*/ */
writeVec2({ pitch, yaw }) { writeVec2({ pitch, yaw }) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
this.writeFloat(pitch); this.writeFloat(pitch);
this.writeFloat(yaw); this.writeFloat(yaw);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeSignedBigEndianInt(value) { writeSignedBigEndianInt(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeSignedBigEndianInt(this.#id, value); GMLIB_BinaryStream_API.writeSignedBigEndianInt(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeSignedInt(value) { writeSignedInt(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeSignedInt(this.#id, value); GMLIB_BinaryStream_API.writeSignedInt(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeSignedInt64(value) { writeSignedInt64(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeSignedInt64(this.#id, value); GMLIB_BinaryStream_API.writeSignedInt64(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeSignedShort(value) { writeSignedShort(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeSignedShort(this.#id, value); GMLIB_BinaryStream_API.writeSignedShort(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeUnsignedChar(value) { writeUnsignedChar(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeUnsignedChar(this.#id, value); GMLIB_BinaryStream_API.writeUnsignedChar(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeUnsignedInt(value) { writeUnsignedInt(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeUnsignedInt(this.#id, value); GMLIB_BinaryStream_API.writeUnsignedInt(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeUnsignedInt64(value) { writeUnsignedInt64(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeUnsignedInt64(this.#id, value); GMLIB_BinaryStream_API.writeUnsignedInt64(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeUnsignedShort(value) { writeUnsignedShort(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeUnsignedShort(this.#id, value); GMLIB_BinaryStream_API.writeUnsignedShort(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeUnsignedVarInt(value) { writeUnsignedVarInt(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeUnsignedVarInt(this.#id, value); GMLIB_BinaryStream_API.writeUnsignedVarInt(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeUnsignedVarInt64(value) { writeUnsignedVarInt64(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeUnsignedVarInt64(this.#id, value); GMLIB_BinaryStream_API.writeUnsignedVarInt64(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeVarInt(value) { writeVarInt(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeVarInt(this.#id, value); GMLIB_BinaryStream_API.writeVarInt(this.#id, value);
return this;
} }
/** /**
* @param {number} value 数值 * @param {number} value 数值
* @returns {GMLIB_BinaryStream}
*/ */
writeVarInt64(value) { writeVarInt64(value) {
if (this.#destroy) throw new Error("The BinaryStream has been destroyed"); if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
GMLIB_BinaryStream_API.writeVarInt64(this.#id, value); GMLIB_BinaryStream_API.writeVarInt64(this.#id, value);
return this;
} }
} }
+5 -1
View File
@@ -63,7 +63,11 @@ void Export_BinaryStream_API() {
}); });
EXPORTAPI("writePacketHeader", int, binaryStream->writePacketHeader((MinecraftPacketIds)value)); EXPORTAPI("writePacketHeader", int, binaryStream->writePacketHeader((MinecraftPacketIds)value));
EXPORTAPI("writeUuid", std::string const&, binaryStream->writeUuid(mce::UUID::fromString(value))); EXPORTAPI("writeUuid", std::string const&, binaryStream->writeUuid(mce::UUID::fromString(value)));
EXPORTAPI("writeItem", ItemStack*, NetworkItemStackDescriptor(*value).write(*binaryStream)); EXPORTAPI(
"writeItem",
ItemStack*,
binaryStream->writeType<NetworkItemStackDescriptor>(NetworkItemStackDescriptor(*value))
);
EXPORTAPI("writeString", std::string const&, binaryStream->writeString(value)); EXPORTAPI("writeString", std::string const&, binaryStream->writeString(value));
EXPORTAPI("writeCompoundTag", CompoundTag*, binaryStream->writeCompoundTag(*value)); EXPORTAPI("writeCompoundTag", CompoundTag*, binaryStream->writeCompoundTag(*value));
EXPORTAPI2(writeBool); EXPORTAPI2(writeBool);