Merge pull request #38 from zimuya4153/main
feat: add BinaryStream API and adapted to GMLIB version and remove shift
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
const getNextCallbackId = ll.import("GMLIB_FormAPI", "getNextFormCallbackId");
|
// const getNextCallbackId = ll.import("GMLIB_FormAPI", "getNextFormCallbackId");
|
||||||
|
|
||||||
class ServerSettingForm {
|
class ServerSettingForm {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
Vendored
+284
-1
@@ -1054,6 +1054,289 @@ 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: "", value: PacketData | 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 {
|
||||||
|
/** 数据包ID */
|
||||||
|
#id: number;
|
||||||
|
/** 数据包是否被销毁 */
|
||||||
|
#destroy: boolean;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
/** 数据包数据 */
|
||||||
|
data: PacketData[]?
|
||||||
|
);
|
||||||
|
|
||||||
|
/** 发送数据包 */
|
||||||
|
sendTo(
|
||||||
|
/** 要发送数据包的玩家对象 */
|
||||||
|
player: Player,
|
||||||
|
/** 数据包发送后是否销毁 */
|
||||||
|
free: boolean = true
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 发送数据包到玩家数组 */
|
||||||
|
sendToPlayers(
|
||||||
|
/** 要发送数据包的玩家对象数组 */
|
||||||
|
players: Player[],
|
||||||
|
/** 数据包发送后是否销毁 */
|
||||||
|
free: boolean = true
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 发送数据包到所有玩家 */
|
||||||
|
sendToAll(
|
||||||
|
/** 数据包发送后是否销毁 */
|
||||||
|
free: boolean = true
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 发送数据包到维度 */
|
||||||
|
sendToDimension(
|
||||||
|
/** 维度ID */
|
||||||
|
dimid: number,
|
||||||
|
/** 数据包发送后是否销毁 */
|
||||||
|
free: boolean = true
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 销毁数据包 */
|
||||||
|
destroy(): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 数据包是否已被销毁 */
|
||||||
|
isDestroy(): boolean;
|
||||||
|
|
||||||
|
/** 重置数据包 */
|
||||||
|
reset(): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 转换成字符串 */
|
||||||
|
toString(): string;
|
||||||
|
|
||||||
|
/** 写入数据 */
|
||||||
|
write(
|
||||||
|
/** 数据 */
|
||||||
|
data: PacketData | PacketData[]?
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入数据包头部 */
|
||||||
|
writePacketHeader(
|
||||||
|
/** 数据包ID */
|
||||||
|
id: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入UUID */
|
||||||
|
writeUuid(
|
||||||
|
/** UUID */
|
||||||
|
value: string
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入物品 */
|
||||||
|
writeItem(
|
||||||
|
/** 物品对象 */
|
||||||
|
value: Item
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入NBT */
|
||||||
|
writeCompoundTag(
|
||||||
|
/** NBT */
|
||||||
|
value: NbtCompound
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeDataItem(
|
||||||
|
/** 数据项 */
|
||||||
|
value: PacketDataItem[]
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
writeActorLink(
|
||||||
|
/** 数据项 */
|
||||||
|
value: { "mA": number, "mB": number, "mType": number, "mImmediate": boolean, "mPassengerInitiated": boolean }
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入浮点数坐标对象 */
|
||||||
|
writeVec3(
|
||||||
|
/** 浮点数坐标对象 */
|
||||||
|
value: FloatPos
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入整数坐标对象 */
|
||||||
|
writeBlockPos(
|
||||||
|
/** 整数坐标对象 */
|
||||||
|
value: IntPos
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeVec2(
|
||||||
|
/** 数据 */
|
||||||
|
value: { "x": number, "z": number }
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入字符串 */
|
||||||
|
writeString(
|
||||||
|
/** 字符串 */
|
||||||
|
value: string
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入布尔值 */
|
||||||
|
writeBool(
|
||||||
|
/** 布尔值 */
|
||||||
|
value: boolean
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入字节 */
|
||||||
|
writeByte(
|
||||||
|
/** 字节 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入(双精度)浮点数 */
|
||||||
|
writeDouble(
|
||||||
|
/** 浮点数 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入(单精度)浮点数 */
|
||||||
|
writeFloat(
|
||||||
|
/** 浮点数 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeSignedBigEndianInt(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeSignedInt(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** 写入 */
|
||||||
|
writeSignedInt64(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeSignedShort(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeUnsignedChar(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeUnsignedInt(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeUnsignedInt64(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeUnsignedShort(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeUnsignedVarInt(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeUnsignedVarInt64(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeVarInt(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
|
||||||
|
/** */
|
||||||
|
writeVarInt64(
|
||||||
|
/** 数值 */
|
||||||
|
value: number
|
||||||
|
): GMLIB_BinaryStream;
|
||||||
|
}
|
||||||
|
|
||||||
interface Player {
|
interface Player {
|
||||||
/** (GMLIB)转换成实体对象 */
|
/** (GMLIB)转换成实体对象 */
|
||||||
toEntity(): Entity;
|
toEntity(): Entity;
|
||||||
@@ -1081,7 +1364,7 @@ interface Player {
|
|||||||
/** (GMLIB)获取玩家的rumtimeId */
|
/** (GMLIB)获取玩家的rumtimeId */
|
||||||
getRuntimeId(): number;
|
getRuntimeId(): number;
|
||||||
|
|
||||||
/** (GMLIB)获取玩家饱食度 */
|
/** (GMLIB)获取玩家饥饿值 */
|
||||||
getHungry(): number;
|
getHungry(): number;
|
||||||
|
|
||||||
/** (GMLIB)获取玩家盔甲覆盖百分比 */
|
/** (GMLIB)获取玩家盔甲覆盖百分比 */
|
||||||
|
|||||||
+473
-4
@@ -316,7 +316,7 @@ const GMLIB_API = {
|
|||||||
getItemCanPlaceOn: ll.import("GMLIB_API", "getItemCanPlaceOn"),
|
getItemCanPlaceOn: ll.import("GMLIB_API", "getItemCanPlaceOn"),
|
||||||
/** 设置物品冒险模式下能放置在什么方块上 @type {function(Item,Array.<string>):void} */
|
/** 设置物品冒险模式下能放置在什么方块上 @type {function(Item,Array.<string>):void} */
|
||||||
setItemCanPlaceOn: ll.import("GMLIB_API", "setItemCanPlaceOn"),
|
setItemCanPlaceOn: ll.import("GMLIB_API", "setItemCanPlaceOn"),
|
||||||
/** 获取玩家饱食度 @type {function(Player):number} */
|
/** 获取玩家饥饿值 @type {function(Player):number} */
|
||||||
getPlayerHungry: ll.import("GMLIB_API", "getPlayerHungry"),
|
getPlayerHungry: ll.import("GMLIB_API", "getPlayerHungry"),
|
||||||
/** 获取玩家盔甲覆盖百分比 @type {function(Player):number} */
|
/** 获取玩家盔甲覆盖百分比 @type {function(Player):number} */
|
||||||
getPlayerArmorCoverPercentage: ll.import("GMLIB_API", "getPlayerArmorCoverPercentage"),
|
getPlayerArmorCoverPercentage: ll.import("GMLIB_API", "getPlayerArmorCoverPercentage"),
|
||||||
@@ -374,7 +374,61 @@ const GMLIB_API = {
|
|||||||
getDefaultGameMode: ll.import("GMLIB_API", "getDefaultGameMode"),
|
getDefaultGameMode: ll.import("GMLIB_API", "getDefaultGameMode"),
|
||||||
/** 设置默认游戏模式 @type {function(mode):void} */
|
/** 设置默认游戏模式 @type {function(mode):void} */
|
||||||
setDefaultGameMode: ll.import("GMLIB_API", "setDefaultGameMode"),
|
setDefaultGameMode: ll.import("GMLIB_API", "setDefaultGameMode"),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
/** LRCA的二进制流数据包导出接口 */
|
||||||
|
const GMLIB_BinaryStream_API = {
|
||||||
|
/** 创建二进制流数据包 @type {function():number} */
|
||||||
|
create: ll.import("GMLIB_BinaryStream_API", "create"),
|
||||||
|
/** 发送二进制流数据包 @type {function(number,player):void} */
|
||||||
|
sendTo: ll.import("GMLIB_BinaryStream_API", "sendTo"),
|
||||||
|
/** 销毁二进制流数据包 @type {function(number):void} */
|
||||||
|
destroy: ll.import("GMLIB_BinaryStream_API", "destroy"),
|
||||||
|
/** 重置二进制流数据包 @type {function(number):void} */
|
||||||
|
reset: ll.import("GMLIB_BinaryStream_API", "reset"),
|
||||||
|
/** 写入二进制流数据包头部 @type {function(number, number):void} */
|
||||||
|
writePacketHeader: ll.import("GMLIB_BinaryStream_API", "writePacketHeader"),
|
||||||
|
/** 写入UUID @type {function(number, string):void} */
|
||||||
|
writeUuid: ll.import("GMLIB_BinaryStream_API", "writeUuid"),
|
||||||
|
/** 写入物品 @type {function(number, Item):void} */
|
||||||
|
writeItem: ll.import("GMLIB_BinaryStream_API", "writeItem"),
|
||||||
|
/** 写入NBT @type {function(NbtCompound, Item):void} */
|
||||||
|
writeCompoundTag: ll.import("GMLIB_BinaryStream_API", "writeCompoundTag"),
|
||||||
|
/** 写入字符串 @type {function(number, string):void} */
|
||||||
|
writeString: ll.import("GMLIB_BinaryStream_API", "writeString"),
|
||||||
|
/** 写入布尔值 @type {function(number, boolean):void} */
|
||||||
|
writeBool: ll.import("GMLIB_BinaryStream_API", "writeBool"),
|
||||||
|
/** 写入字节 @type {function(number, number):void} */
|
||||||
|
writeByte: ll.import("GMLIB_BinaryStream_API", "writeByte"),
|
||||||
|
/** 写入双精度浮点数 @type {function(number, number):void} */
|
||||||
|
writeDouble: ll.import("GMLIB_BinaryStream_API", "writeDouble"),
|
||||||
|
/** 写入浮点数 @type {function(number, number):void} */
|
||||||
|
writeFloat: ll.import("GMLIB_BinaryStream_API", "writeFloat"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeSignedBigEndianInt: ll.import("GMLIB_BinaryStream_API", "writeSignedBigEndianInt"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeSignedInt: ll.import("GMLIB_BinaryStream_API", "writeSignedInt"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeSignedInt64: ll.import("GMLIB_BinaryStream_API", "writeSignedInt64"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeSignedShort: ll.import("GMLIB_BinaryStream_API", "writeSignedShort"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeUnsignedChar: ll.import("GMLIB_BinaryStream_API", "writeUnsignedChar"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeUnsignedInt: ll.import("GMLIB_BinaryStream_API", "writeUnsignedInt"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeUnsignedInt64: ll.import("GMLIB_BinaryStream_API", "writeUnsignedInt64"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeUnsignedShort: ll.import("GMLIB_BinaryStream_API", "writeUnsignedShort"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeUnsignedVarInt: ll.import("GMLIB_BinaryStream_API", "writeUnsignedVarInt"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeUnsignedVarInt64: ll.import("GMLIB_BinaryStream_API", "writeUnsignedVarInt64"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeVarInt: ll.import("GMLIB_BinaryStream_API", "writeVarInt"),
|
||||||
|
/** @type {function(number, number):void} */
|
||||||
|
writeVarInt64: ll.import("GMLIB_BinaryStream_API", "writeVarInt64"),
|
||||||
|
};
|
||||||
|
|
||||||
/** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */
|
/** 静态悬浮字类列表 @type {Map<number,StaticFloatingText>} */
|
||||||
const mStaticFloatingTextMap = new Map();
|
const mStaticFloatingTextMap = new Map();
|
||||||
@@ -2052,6 +2106,420 @@ class UserCache {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 二进制数据包API类 */
|
||||||
|
class GMLIB_BinaryStream {
|
||||||
|
|
||||||
|
/** 数据包ID @type {number} */
|
||||||
|
#id = null;
|
||||||
|
/** 数据包是否被销毁 @type {boolean} */
|
||||||
|
#destroy = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建二进制流数据包
|
||||||
|
* @param {{"type":string,"value":any}[]?} value 写入数据
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
constructor(value) {
|
||||||
|
this.#id = GMLIB_BinaryStream_API.create();
|
||||||
|
if (Array.isArray(value)) this.write(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送数据包
|
||||||
|
* @param {Player} player 玩家
|
||||||
|
* @param {boolean} [free=true] 发送后销毁数据包
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
sendTo(player, free = true) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.sendTo(this.#id, player);
|
||||||
|
if (free) this.destroy();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送数据包到玩家
|
||||||
|
* @param {Player[]} players 玩家对象数组
|
||||||
|
* @param {boolean} free 发送后销毁数据包
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
sendToPlayers(players, free = true) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
players.forEach(player => this.sendTo(player, false));
|
||||||
|
if (free) this.destroy();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送数据包到所有玩家
|
||||||
|
* @param {boolean} [free=true] 发送后销毁数据包
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
sendToAll(free = true) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
mc.getOnlinePlayers().forEach(player => this.sendTo(player, false));
|
||||||
|
if (free) this.destroy();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送数据包到维度
|
||||||
|
* @param {number} dimid 维度ID
|
||||||
|
* @param {boolean} [free=true] 发送后销毁数据包
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
sendToDimension(dimid, free = true) {
|
||||||
|
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));
|
||||||
|
if (free) this.destroy();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 销毁数据包
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
destroy() {
|
||||||
|
GMLIB_BinaryStream_API.destroy(this.#id);
|
||||||
|
this.#destroy = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据包是否已被销毁
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
isDestroy() {
|
||||||
|
return this.#destroy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置数据包
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
reset() {
|
||||||
|
GMLIB_BinaryStream_API.reset(this.#id);
|
||||||
|
this.#destroy = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换成字符串
|
||||||
|
* @returns {string} 字符串
|
||||||
|
*/
|
||||||
|
toString(){
|
||||||
|
return `<GMLIB_BinaryStream#${this.#id}>`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入数据
|
||||||
|
* @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
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writePacketHeader(id) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writePacketHeader(this.#id, id);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入UUID
|
||||||
|
* @param {string} value UUID
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeUuid(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeUuid(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入物品
|
||||||
|
* @param {Item} value 物品
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeItem(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeItem(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入NBT
|
||||||
|
* @param {NbtCompound} value NBT
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeCompoundTag(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeCompoundTag(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{"id":number,"type":number,"value":string|IntPos|FloatPos|number|NbtCompound}[]} value 数据
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeDataItem(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
this.writeUnsignedVarInt(value.length);
|
||||||
|
for (const data of value) {
|
||||||
|
this.writeUnsignedVarInt(data.id);
|
||||||
|
this.writeUnsignedVarInt(data.type);
|
||||||
|
switch (data.type) {
|
||||||
|
case 0: this.writeByte(data.value); break;
|
||||||
|
case 1: this.writeSignedShort(data.value); break;
|
||||||
|
case 2: this.writeSignedInt(data.value); break;
|
||||||
|
case 3: this.writeFloat(data.value); break;
|
||||||
|
case 4: this.writeString(data.value); break;
|
||||||
|
case 5: this.writeCompoundTag(data.value); break;
|
||||||
|
case 6: this.writeBlockPos(data.value); break;
|
||||||
|
case 7: this.writeSignedInt64(data.value); break;
|
||||||
|
case 8: this.writeVec3(data.value); break;
|
||||||
|
default: throw new Error("Unknown data type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{"mA":number,"mB":number,"mType":number,"mImmediate":boolean,"mPassengerInitiated":boolean}} value 数据
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeActorLink(value) {
|
||||||
|
this.writeVarInt64(value.mA);
|
||||||
|
this.writeVarInt64(value.mB);
|
||||||
|
this.writeUnsignedChar(value.mType);
|
||||||
|
this.writeBool(value.mImmediate);
|
||||||
|
this.writeBool(value.mPassengerInitiated);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入字符串
|
||||||
|
* @param {string} value 字符串
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeString(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeString(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入布尔值
|
||||||
|
* @param {boolean} value 布尔值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeBool(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeBool(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入字节
|
||||||
|
* @param {number} value 字节
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeByte(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeByte(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入(双精度)浮点数
|
||||||
|
* @param {number} value 浮点数
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeDouble(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeDouble(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入(单精度)浮点数
|
||||||
|
* @param {number} value 浮点数
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeFloat(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeFloat(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入浮点数坐标对象
|
||||||
|
* @param {FloatPos} value 浮点数坐标对象
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeVec3({ x, y, z }) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
this.writeFloat(x);
|
||||||
|
this.writeFloat(y);
|
||||||
|
this.writeFloat(z);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入整数坐标对象
|
||||||
|
* @param {IntPos} value 整数坐标对象
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeBlockPos({ x, y, z }) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
this.writeVarInt(x);
|
||||||
|
this.writeUnsignedVarInt(y);
|
||||||
|
this.writeVarInt(z);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {{"x":number,"z":number}} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeVec2({ x, z }) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
this.writeFloat(x);
|
||||||
|
this.writeFloat(z);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeSignedBigEndianInt(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeSignedBigEndianInt(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeSignedInt(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeSignedInt(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeSignedInt64(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeSignedInt64(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeSignedShort(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeSignedShort(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeUnsignedChar(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeUnsignedChar(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeUnsignedInt(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeUnsignedInt(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeUnsignedInt64(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeUnsignedInt64(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeUnsignedShort(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeUnsignedShort(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeUnsignedVarInt(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeUnsignedVarInt(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeUnsignedVarInt64(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeUnsignedVarInt64(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeVarInt(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeVarInt(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} value 数值
|
||||||
|
* @returns {GMLIB_BinaryStream}
|
||||||
|
*/
|
||||||
|
writeVarInt64(value) {
|
||||||
|
if (this.#destroy) throw new Error("The BinaryStream has been destroyed");
|
||||||
|
GMLIB_BinaryStream_API.writeVarInt64(this.#id, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LLSE_Player.prototype.toEntity =
|
LLSE_Player.prototype.toEntity =
|
||||||
/**
|
/**
|
||||||
* 获取实体对象
|
* 获取实体对象
|
||||||
@@ -2470,7 +2938,7 @@ LLSE_Item.prototype.setCanPlaceOn =
|
|||||||
|
|
||||||
LLSE_Player.prototype.getHungry =
|
LLSE_Player.prototype.getHungry =
|
||||||
/**
|
/**
|
||||||
* 获取玩家饱食度
|
* 获取玩家饥饿值
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function () {
|
function () {
|
||||||
@@ -2661,5 +3129,6 @@ module.exports = {
|
|||||||
JsonI18n,
|
JsonI18n,
|
||||||
Version,
|
Version,
|
||||||
I18nAPI,
|
I18nAPI,
|
||||||
UserCache
|
UserCache,
|
||||||
|
GMLIB_BinaryStream
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#include "Global.h"
|
||||||
|
using namespace ll::hash_utils;
|
||||||
|
|
||||||
|
class LegacyScriptBinaryStreamManager {
|
||||||
|
private:
|
||||||
|
int64 mNextBinaryStreamId = 0;
|
||||||
|
std::unordered_map<uint64, std::shared_ptr<gmlib::network::BinaryStream>> mBinaryStream;
|
||||||
|
|
||||||
|
public:
|
||||||
|
uint getNextId() { return mNextBinaryStreamId++; }
|
||||||
|
|
||||||
|
void cretateBinaryStream(uint id) { mBinaryStream[id] = std::make_shared<gmlib::network::BinaryStream>(); }
|
||||||
|
|
||||||
|
void removeBinaryStream(uint64 id) { mBinaryStream.erase(id); }
|
||||||
|
|
||||||
|
std::shared_ptr<gmlib::network::BinaryStream> getBinaryStream(uint64 id) {
|
||||||
|
return mBinaryStream.contains(id) ? mBinaryStream.at(id) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static LegacyScriptBinaryStreamManager& getInstance() {
|
||||||
|
static std::unique_ptr<LegacyScriptBinaryStreamManager> instance;
|
||||||
|
if (!instance) instance = std::make_unique<LegacyScriptBinaryStreamManager>();
|
||||||
|
return *instance;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define BinaryStreamManager LegacyScriptBinaryStreamManager::getInstance()
|
||||||
|
#define EXPORTAPI(funcName, type, fuc) \
|
||||||
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", funcName, [](uint64 id, type value) -> void { \
|
||||||
|
auto bs = BinaryStreamManager.getBinaryStream(id); \
|
||||||
|
if (bs != nullptr) fuc; \
|
||||||
|
})
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct Info;
|
||||||
|
template <typename T, typename R, typename A, typename... AS>
|
||||||
|
struct Info<R (T::*)(A, AS...)> {
|
||||||
|
using ArgT = A;
|
||||||
|
};
|
||||||
|
#define EXPORTAPI2(T) EXPORTAPI(#T, Info<decltype(&gmlib::network::BinaryStream::T)>::ArgT, bs->T(value))
|
||||||
|
|
||||||
|
void Export_BinaryStream_API() {
|
||||||
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "create", []() -> uint64 {
|
||||||
|
auto id = BinaryStreamManager.getNextId();
|
||||||
|
BinaryStreamManager.cretateBinaryStream(id);
|
||||||
|
return id;
|
||||||
|
});
|
||||||
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "reset", [](uint64 id) -> void {
|
||||||
|
if (BinaryStreamManager.getBinaryStream(id) == nullptr) BinaryStreamManager.cretateBinaryStream(id);
|
||||||
|
else BinaryStreamManager.getBinaryStream(id)->reset();
|
||||||
|
});
|
||||||
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "sendTo", [](uint64 id, Player* player) -> void {
|
||||||
|
if (auto bs = BinaryStreamManager.getBinaryStream(id); bs != nullptr) bs->sendTo(*player);
|
||||||
|
});
|
||||||
|
RemoteCall::exportAs("GMLIB_BinaryStream_API", "destroy", [](uint64 id) -> void {
|
||||||
|
BinaryStreamManager.removeBinaryStream(id);
|
||||||
|
});
|
||||||
|
EXPORTAPI("writePacketHeader", int, bs->writePacketHeader((MinecraftPacketIds)value));
|
||||||
|
EXPORTAPI("writeUuid", std::string const&, bs->writeUuid(mce::UUID::fromString(value)));
|
||||||
|
EXPORTAPI("writeItem", ItemStack*, bs->writeType(NetworkItemStackDescriptor(*value)));
|
||||||
|
EXPORTAPI("writeString", std::string const&, bs->writeString(value));
|
||||||
|
EXPORTAPI("writeCompoundTag", CompoundTag*, bs->writeCompoundTag(*value));
|
||||||
|
EXPORTAPI2(writeBool);
|
||||||
|
EXPORTAPI2(writeByte);
|
||||||
|
EXPORTAPI2(writeDouble);
|
||||||
|
EXPORTAPI2(writeFloat);
|
||||||
|
EXPORTAPI2(writeSignedBigEndianInt);
|
||||||
|
EXPORTAPI2(writeSignedInt);
|
||||||
|
EXPORTAPI2(writeSignedInt64);
|
||||||
|
EXPORTAPI2(writeSignedShort);
|
||||||
|
EXPORTAPI2(writeUnsignedChar);
|
||||||
|
EXPORTAPI2(writeUnsignedInt);
|
||||||
|
EXPORTAPI2(writeUnsignedInt64);
|
||||||
|
EXPORTAPI2(writeUnsignedShort);
|
||||||
|
EXPORTAPI2(writeUnsignedVarInt);
|
||||||
|
EXPORTAPI2(writeUnsignedVarInt64);
|
||||||
|
EXPORTAPI2(writeVarInt);
|
||||||
|
EXPORTAPI2(writeVarInt64);
|
||||||
|
}
|
||||||
+320
-446
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -16,11 +16,12 @@ bool LegacyRemoteCallApi::load() {
|
|||||||
Export_Compatibility_API();
|
Export_Compatibility_API();
|
||||||
ExportPAPI();
|
ExportPAPI();
|
||||||
Export_Event_API();
|
Export_Event_API();
|
||||||
|
Export_BinaryStream_API();
|
||||||
Export_Form_API();
|
Export_Form_API();
|
||||||
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
|
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
|
||||||
logger.info(
|
logger.info(
|
||||||
"Loaded Version: {} with {}",
|
"Loaded Version: {} with {}",
|
||||||
fmt::format(fg(fmt::color::pink), "GMLIB-" + Version::getLibVersionString()),
|
fmt::format(fg(fmt::color::pink), "GMLIB-" + gmlib::Version::getLibVersionString()),
|
||||||
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-" + LIB_VERSION.asString())
|
fmt::format(fg(fmt::color::light_green), "GMLIB-LegacyRemoteCallApi-" + LIB_VERSION.asString())
|
||||||
);
|
);
|
||||||
logger.info("Author: GroupMountain");
|
logger.info("Author: GroupMountain");
|
||||||
@@ -34,4 +35,4 @@ bool LegacyRemoteCallApi::disable() { return true; }
|
|||||||
|
|
||||||
} // namespace gmlib
|
} // namespace gmlib
|
||||||
|
|
||||||
LL_REGISTER_MOD(LegacyRemoteCallApi, LegacyRemoteCallApi::getInstance());
|
LL_REGISTER_MOD(GMLIB::LegacyRemoteCallApi, GMLIB::LegacyRemoteCallApi::getInstance());
|
||||||
|
|||||||
+57
-52
@@ -1,6 +1,4 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "ll/api/event/EventBus.h"
|
|
||||||
#include "mc/world/inventory/network/ItemStackRequestActionTransferBase.h"
|
|
||||||
using namespace ll::hash_utils;
|
using namespace ll::hash_utils;
|
||||||
|
|
||||||
class LegacyScriptEventManager {
|
class LegacyScriptEventManager {
|
||||||
@@ -15,7 +13,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void emplaceListener(std::string const& scriptEventId, ll::event::ListenerPtr listenerPtr) {
|
void emplaceListener(std::string const& scriptEventId, ll::event::ListenerPtr listenerPtr) {
|
||||||
mEventListeners[doHash(scriptEventId)] = listenerPtr;
|
mEventListeners[doHash(scriptEventId)] = std::move(listenerPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeListener(std::string const& scriptEventId) {
|
void removeListener(std::string const& scriptEventId) {
|
||||||
@@ -72,7 +70,7 @@ void Export_Event_API() {
|
|||||||
std::string const& clientXuid),
|
std::string const& clientXuid),
|
||||||
(ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
|
(ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
|
||||||
logger.error("Event \"onClientLogin\" cannot be intercepted"),
|
logger.error("Event \"onClientLogin\" cannot be intercepted"),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onWeatherChange"): {
|
case doHash("onWeatherChange"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
@@ -80,91 +78,91 @@ void Export_Event_API() {
|
|||||||
(int lightningLevel, int rainLevel, int lightningLast, int rainLast),
|
(int lightningLevel, int rainLevel, int lightningLast, int rainLast),
|
||||||
(ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
|
(ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onMobPick"): {
|
case doHash("onMobPick"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::MobPickupItemBeforeEvent,
|
gmlib::event::entity::MobPickupItemBeforeEvent,
|
||||||
(::Actor * mob, ::Actor * item),
|
(Actor * mob, Actor * item),
|
||||||
(&ev.self(), (::Actor*)&ev.getItemActor()),
|
(&ev.self(), (Actor*)&ev.getItemActor()),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onItemTrySpawn"): {
|
case doHash("onItemTrySpawn"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ItemActorSpawnBeforeEvent,
|
gmlib::event::entity::ItemActorSpawnBeforeEvent,
|
||||||
(const ::ItemStack* item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
(const ItemStack* item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||||
(&ev.getItem(),
|
(&ev.getItem(),
|
||||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onItemSpawned"): {
|
case doHash("onItemSpawned"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ItemActorSpawnAfterEvent,
|
gmlib::event::entity::ItemActorSpawnAfterEvent,
|
||||||
(const ::ItemStack* item, ::Actor* itemActor, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||||
(&ev.getItem(),
|
(&ev.getItem(),
|
||||||
(::Actor*)&ev.getItemActor(),
|
(Actor*)&ev.getItemActor(),
|
||||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||||
logger.error("Event \"onItemSpawned\" cannot be intercepted"),
|
logger.error("Event \"onItemSpawned\" cannot be intercepted"),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onEntityTryChangeDim"): {
|
case doHash("onEntityTryChangeDim"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ActorChangeDimensionBeforeEvent,
|
gmlib::event::entity::ActorChangeDimensionBeforeEvent,
|
||||||
(::Actor * entity, int toDimId),
|
(Actor * entity, int toDimId),
|
||||||
(&ev.self(), ev.getToDimensionId()),
|
(&ev.self(), ev.getToDimensionId()),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onLeaveBed"): {
|
case doHash("onLeaveBed"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::player::PlayerStopSleepBeforeEvent,
|
gmlib::event::player::PlayerStopSleepBeforeEvent,
|
||||||
(::Player * pl),
|
(Player * pl),
|
||||||
(&ev.self()),
|
(&ev.self()),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onDeathMessage"): {
|
case doHash("onDeathMessage"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::DeathMessageAfterEvent,
|
gmlib::event::entity::DeathMessageAfterEvent,
|
||||||
(std::string const& message, std::vector<std::string>, ::Actor* dead),
|
(std::string const& message, std::vector<std::string>, Actor* dead),
|
||||||
(ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()),
|
(ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()),
|
||||||
logger.error("Event \"onDeathMessage\" cannot be intercepted"),
|
logger.error("Event \"onDeathMessage\" cannot be intercepted"),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onMobHurted"): {
|
case doHash("onMobHurted"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::MobHurtAfterEvent,
|
gmlib::event::entity::MobHurtAfterEvent,
|
||||||
(::Actor * mob, ::Actor * source, float damage, int cause),
|
(Actor * mob, Actor * source, float damage, int cause),
|
||||||
(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()),
|
(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()),
|
||||||
logger.error("Event \"onMobHurted\" cannot be intercepted"),
|
logger.error("Event \"onMobHurted\" cannot be intercepted"),
|
||||||
auto& damageSource = ev.getSource();
|
auto& damageSource = ev.getSource();
|
||||||
::Actor* source = nullptr;
|
Actor* source = nullptr;
|
||||||
if (damageSource.isEntitySource()) {
|
if (damageSource.isEntitySource()) {
|
||||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
||||||
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
||||||
if (source->getOwner()) source = source->getOwner();
|
if (source->getOwner()) source = source->getOwner();
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onEndermanTake"): {
|
case doHash("onEndermanTake"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::EndermanTakeBlockBeforeEvent,
|
gmlib::event::entity::EndermanTakeBlockBeforeEvent,
|
||||||
(::Actor * mob),
|
(Actor * mob),
|
||||||
(&ev.self()),
|
(&ev.self()),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onEntityChangeDim"): {
|
case doHash("onEntityChangeDim"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ActorChangeDimensionAfterEvent,
|
gmlib::event::entity::ActorChangeDimensionAfterEvent,
|
||||||
(::Actor * mob, int fromDimId),
|
(Actor * mob, int fromDimId),
|
||||||
(&ev.self(), ev.getFromDimensionId()),
|
(&ev.self(), ev.getFromDimensionId()),
|
||||||
logger.error("Event \"onEntityChangeDim\" cannot be intercepted"),
|
logger.error("Event \"onEntityChangeDim\" cannot be intercepted"),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onDragonRespawn"): {
|
case doHash("onDragonRespawn"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
@@ -177,18 +175,18 @@ void Export_Event_API() {
|
|||||||
case doHash("onProjectileTryCreate"): {
|
case doHash("onProjectileTryCreate"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ProjectileCreateBeforeEvent,
|
gmlib::event::entity::ProjectileCreateBeforeEvent,
|
||||||
(::Actor * mob, int64 uniqueId),
|
(Actor * mob, int64 uniqueId),
|
||||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onProjectileCreate"): {
|
case doHash("onProjectileCreate"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
gmlib::event::entity::ProjectileCreateAfterEvent,
|
gmlib::event::entity::ProjectileCreateAfterEvent,
|
||||||
(::Actor * mob, int64 uniqueId),
|
(Actor * mob, int64 uniqueId),
|
||||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||||
logger.error("Event \"onProjectileCreate\" cannot be intercepted"),
|
logger.error("Event \"onProjectileCreate\" cannot be intercepted"),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onSpawnWanderingTrader"): {
|
case doHash("onSpawnWanderingTrader"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
@@ -196,32 +194,39 @@ void Export_Event_API() {
|
|||||||
(std::pair<BlockPos, int> pos),
|
(std::pair<BlockPos, int> pos),
|
||||||
({ev.getPos(), ev.getRegion().getDimensionId()}),
|
({ev.getPos(), ev.getRegion().getDimensionId()}),
|
||||||
ev.cancel(),
|
ev.cancel(),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
case doHash("onHandleRequestAction"): {
|
case doHash("onHandleRequestAction"): {
|
||||||
REGISTER_EVENT_LISTEN(gmlib::event::player::HandleRequestActionBeforeEvent,
|
// clang-format off
|
||||||
(::Player * player,
|
REGISTER_EVENT_LISTEN(
|
||||||
std::string const& actionType,
|
gmlib::event::player::HandleRequestActionBeforeEvent,
|
||||||
int count,
|
(
|
||||||
std::string const& sourceContainerNetId,
|
Player * player,
|
||||||
int sourceSlot,
|
std::string const& actionType,
|
||||||
std::string const& destinationContainerNetId,
|
int count,
|
||||||
int destinationSlot),
|
std::string const& sourceContainerNetId,
|
||||||
((::Player*)&ev.self(),
|
int sourceSlot,
|
||||||
magic_enum::enum_name(requestAction->mActionType).data(),
|
std::string const& destinationContainerNetId,
|
||||||
(int)requestAction->mAmount,
|
int destinationSlot
|
||||||
magic_enum::enum_name(requestAction->mSrc.mOpenContainerNetId).data(),
|
),
|
||||||
(int)requestAction->mSrc.mSlot,
|
(
|
||||||
magic_enum::enum_name(requestAction->mDst.mOpenContainerNetId).data(),
|
(Player*)&ev.self(),
|
||||||
(int)requestAction->mDst.mSlot),
|
magic_enum::enum_name(requestAction.mActionType).data(),
|
||||||
ev.cancel(),
|
(int)requestAction.mAmount,
|
||||||
auto requestAction = (ItemStackRequestActionTransferBase*)&ev.getRequestAction();
|
magic_enum::enum_name(requestAction.mSrc.mOpenContainerNetId).data(),
|
||||||
);
|
(int)requestAction.mSrc.mSlot,
|
||||||
|
magic_enum::enum_name(requestAction.mDst.mOpenContainerNetId).data(),
|
||||||
|
(int)requestAction.mDst.mSlot
|
||||||
|
),
|
||||||
|
ev.cancel(),
|
||||||
|
auto& requestAction = (ItemStackRequestActionTransferBase&)ev.getRequestAction();
|
||||||
|
)
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
case doHash("onSendContainerClosePacket"): {
|
case doHash("onSendContainerClosePacket"): {
|
||||||
REGISTER_EVENT_LISTEN(
|
REGISTER_EVENT_LISTEN(
|
||||||
event::packet::ContainerClosePacketSendAfterEvent,
|
gmlib::event::packet::ContainerClosePacketSendAfterEvent,
|
||||||
(::Player * player, int ContainerNetId),
|
(Player * player, int ContainerNetId),
|
||||||
(ev.getServerNetworkHandler()
|
(ev.getServerNetworkHandler()
|
||||||
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
|
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
|
||||||
(int)ev.getPacket().mContainerId),
|
(int)ev.getPacket().mContainerId),
|
||||||
@@ -234,7 +239,7 @@ void Export_Event_API() {
|
|||||||
(),
|
(),
|
||||||
(),
|
(),
|
||||||
logger.error("Event \"onServerStopping\" cannot be intercepted"),
|
logger.error("Event \"onServerStopping\" cannot be intercepted"),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+46
-93
@@ -1,21 +1,18 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "gmlib/world/Player.h"
|
|
||||||
|
|
||||||
using namespace gmlib::form;
|
|
||||||
using namespace ll::hash_utils;
|
using namespace ll::hash_utils;
|
||||||
|
|
||||||
class LegacyScriptFormManager {
|
class LegacyScriptFormManager {
|
||||||
private:
|
private:
|
||||||
int64 mNextFormCallbackId = 0;
|
int64 mNextFormCallbackId = 0;
|
||||||
int64 mNextFormId = 0;
|
int64 mNextFormId = 0;
|
||||||
std::unordered_map<int64, std::unique_ptr<NpcDialogueForm>> mNpcDialogueForms;
|
std::unordered_map<int64, std::unique_ptr<gmlib::form::NpcDialogueForm>> mNpcDialogueForms;
|
||||||
// std::unordered_map<int64, std::unique_ptr<ChestForm>> mChestForms;
|
// std::unordered_map<int64, std::unique_ptr<ChestForm>> mChestForms;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string getNextFormCallbackId() {
|
// std::string getNextFormCallbackId() {
|
||||||
mNextFormCallbackId++;
|
// return "GMLIB_FormApi_" + std::to_string(mNextFormCallbackId++);
|
||||||
return "GMLIB_EVENT_" + std::to_string(mNextFormCallbackId);
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
int64 getNextFormId() {
|
int64 getNextFormId() {
|
||||||
mNextFormId++;
|
mNextFormId++;
|
||||||
@@ -24,7 +21,7 @@ public:
|
|||||||
|
|
||||||
int64 createNpcDialogueForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
int64 createNpcDialogueForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
||||||
auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
||||||
auto formPtr = std::make_unique<NpcDialogueForm>(npcName, sceneName, dialogue);
|
auto formPtr = std::make_unique<gmlib::form::NpcDialogueForm>(npcName, sceneName, dialogue);
|
||||||
mNpcDialogueForms[formId] = std::move(formPtr);
|
mNpcDialogueForms[formId] = std::move(formPtr);
|
||||||
return formId;
|
return formId;
|
||||||
}
|
}
|
||||||
@@ -37,7 +34,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional_ref<NpcDialogueForm> getNpcDialogueForm(int64 formId) {
|
optional_ref<gmlib::form::NpcDialogueForm> getNpcDialogueForm(int64 formId) {
|
||||||
if (mNpcDialogueForms.contains(formId)) {
|
if (mNpcDialogueForms.contains(formId)) {
|
||||||
return mNpcDialogueForms[formId].get();
|
return mNpcDialogueForms[formId].get();
|
||||||
}
|
}
|
||||||
@@ -85,60 +82,20 @@ public:
|
|||||||
auto const& detector = RemoteCall::importAs<bool(::Player*)>("GMLIB_FORM_CALLBACK", detectorId); \
|
auto const& detector = RemoteCall::importAs<bool(::Player*)>("GMLIB_FORM_CALLBACK", detectorId); \
|
||||||
return detector(&pl); \
|
return detector(&pl); \
|
||||||
} else { \
|
} else { \
|
||||||
ServerSettingForm::removeElement(result); \
|
gmlib::form::ServerSettingForm::removeElement(result); \
|
||||||
} \
|
} \
|
||||||
} catch (...) {} \
|
} catch (...) {} \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CALLBACK_TYPE_STRING \
|
#define CALLBACK_TYPE(type) \
|
||||||
[callbackId, result](::Player& pl, std::string const& data) { \
|
[callbackId, result](Player& pl, type data) { \
|
||||||
try { \
|
try { \
|
||||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||||
auto const& callback = \
|
auto const& callback = RemoteCall::importAs<void(Player*, type)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||||
RemoteCall::importAs<void(::Player*, std::string const&)>("GMLIB_FORM_CALLBACK", callbackId); \
|
|
||||||
callback(&pl, data); \
|
callback(&pl, data); \
|
||||||
} else { \
|
} else { \
|
||||||
ServerSettingForm::removeElement(result); \
|
gmlib::form::ServerSettingForm::removeElement(result); \
|
||||||
} \
|
|
||||||
} catch (...) {} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CALLBACK_TYPE_BOOL \
|
|
||||||
[callbackId, result](::Player& pl, bool data) { \
|
|
||||||
try { \
|
|
||||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
|
||||||
auto const& callback = RemoteCall::importAs<void(::Player*, bool)>("GMLIB_FORM_CALLBACK", callbackId); \
|
|
||||||
callback(&pl, data); \
|
|
||||||
} else { \
|
|
||||||
ServerSettingForm::removeElement(result); \
|
|
||||||
} \
|
|
||||||
} catch (...) {} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CALLBACK_TYPE_DOUBLE \
|
|
||||||
[callbackId, result](::Player& pl, double data) { \
|
|
||||||
try { \
|
|
||||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
|
||||||
auto const& callback = \
|
|
||||||
RemoteCall::importAs<void(::Player*, double)>("GMLIB_FORM_CALLBACK", callbackId); \
|
|
||||||
callback(&pl, data); \
|
|
||||||
} else { \
|
|
||||||
ServerSettingForm::removeElement(result); \
|
|
||||||
} \
|
|
||||||
} catch (...) {} \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define CALLBACK_TYPE_LONG \
|
|
||||||
[callbackId, result](::Player& pl, int64 data) { \
|
|
||||||
try { \
|
|
||||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
|
||||||
auto const& callback = \
|
|
||||||
RemoteCall::importAs<void(::Player*, int64)>("GMLIB_FORM_CALLBACK", callbackId); \
|
|
||||||
callback(&pl, data); \
|
|
||||||
} else { \
|
|
||||||
ServerSettingForm::removeElement(result); \
|
|
||||||
} \
|
} \
|
||||||
} catch (...) {} \
|
} catch (...) {} \
|
||||||
}
|
}
|
||||||
@@ -156,50 +113,46 @@ public:
|
|||||||
|
|
||||||
void Export_Form_API() {
|
void Export_Form_API() {
|
||||||
//////////////////////////////// Form Manager /////////////////////////////////
|
//////////////////////////////// Form Manager /////////////////////////////////
|
||||||
RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
// RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
||||||
return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
// return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
||||||
});
|
// });
|
||||||
////////////////////////////// ServerSettingForm //////////////////////////////
|
////////////////////////////// ServerSettingForm //////////////////////////////
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int {
|
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int {
|
||||||
return ServerSettingForm::getDefaultPriority();
|
return gmlib::form::ServerSettingForm::getDefaultPriority();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return ServerSettingForm::hasTitle(); });
|
RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return gmlib::form::ServerSettingForm::hasTitle(); });
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string {
|
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string {
|
||||||
return ServerSettingForm::getTitle();
|
return gmlib::form::ServerSettingForm::getTitle();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
||||||
return ServerSettingForm::setTitle(title, forceModify);
|
return gmlib::form::ServerSettingForm::setTitle(title, forceModify);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasIcon", []() -> bool { return ServerSettingForm::hasIcon(); });
|
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "hasIcon", []() -> bool { return gmlib::form::ServerSettingForm::hasIcon(); });
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getIconData", []() -> std::string {
|
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconData", []() -> std::string {
|
||||||
if (auto data = ServerSettingForm::getIconData()) {
|
return gmlib::form::ServerSettingForm::getIconData().value_or("");
|
||||||
return data.value();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getIconType", []() -> int {
|
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconType", []() -> int {
|
||||||
if (auto type = ServerSettingForm::getIconType()) {
|
return gmlib::form::ServerSettingForm::getIconType()
|
||||||
return (int)type.value();
|
.transform([](gmlib::form::IconType&& type) -> int { return (int)type; })
|
||||||
}
|
.value_or(-1);
|
||||||
return -1;
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_ServerSettingForm",
|
"GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"setIcon",
|
"setIcon",
|
||||||
[](std::string const& title, uchar type, bool forceModify) -> bool {
|
[](std::string const& title, uchar type, bool forceModify) -> bool {
|
||||||
return ServerSettingForm::setIcon(title, IconType(type), forceModify);
|
return gmlib::form::ServerSettingForm::setIcon(title, gmlib::form::IconType(type), forceModify);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_ServerSettingForm",
|
"GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addLabel",
|
"addLabel",
|
||||||
[](std::string const& text, std::string const& detectorId, int priority) -> uint {
|
[](std::string const& text, std::string const& detectorId, int priority) -> uint {
|
||||||
uint result = ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
uint result = gmlib::form::ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_ServerSettingForm",
|
"GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addInput",
|
"addInput",
|
||||||
[](std::string const& text,
|
[](std::string const& text,
|
||||||
std::string const& placeholder,
|
std::string const& placeholder,
|
||||||
@@ -207,11 +160,11 @@ void Export_Form_API() {
|
|||||||
std::string const& callbackId,
|
std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
std::string const& detectorId,
|
||||||
int priority) -> uint {
|
int priority) -> uint {
|
||||||
uint result = ServerSettingForm::addInput(
|
uint result = gmlib::form::ServerSettingForm::addInput(
|
||||||
text,
|
text,
|
||||||
placeholder,
|
placeholder,
|
||||||
defaultVal,
|
defaultVal,
|
||||||
CALLBACK_TYPE_STRING,
|
CALLBACK_TYPE(std::string const&),
|
||||||
PLAYER_DETECROR,
|
PLAYER_DETECROR,
|
||||||
priority
|
priority
|
||||||
);
|
);
|
||||||
@@ -219,19 +172,19 @@ void Export_Form_API() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_ServerSettingForm",
|
"GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addToggle",
|
"addToggle",
|
||||||
[](std::string const& text,
|
[](std::string const& text,
|
||||||
bool defaultVal,
|
bool defaultVal,
|
||||||
std::string const& callbackId,
|
std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
std::string const& detectorId,
|
||||||
int priority) -> uint {
|
int priority) -> uint {
|
||||||
uint result = ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE_BOOL, PLAYER_DETECROR, priority);
|
uint result = gmlib::form::ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE(bool), PLAYER_DETECROR, priority);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_ServerSettingForm",
|
"GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addDropdown",
|
"addDropdown",
|
||||||
[](std::string const& text,
|
[](std::string const& text,
|
||||||
std::vector<std::string> options,
|
std::vector<std::string> options,
|
||||||
@@ -239,11 +192,11 @@ void Export_Form_API() {
|
|||||||
std::string const& callbackId,
|
std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
std::string const& detectorId,
|
||||||
int priority) -> uint {
|
int priority) -> uint {
|
||||||
uint result = ServerSettingForm::addDropdown(
|
uint result = gmlib::form::ServerSettingForm::addDropdown(
|
||||||
text,
|
text,
|
||||||
options,
|
options,
|
||||||
defaultVal,
|
defaultVal,
|
||||||
CALLBACK_TYPE_LONG,
|
CALLBACK_TYPE(int64),
|
||||||
PLAYER_DETECROR,
|
PLAYER_DETECROR,
|
||||||
priority
|
priority
|
||||||
);
|
);
|
||||||
@@ -251,7 +204,7 @@ void Export_Form_API() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_ServerSettingForm",
|
"GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addSlider",
|
"addSlider",
|
||||||
[](std::string const& text,
|
[](std::string const& text,
|
||||||
double min,
|
double min,
|
||||||
@@ -261,13 +214,13 @@ void Export_Form_API() {
|
|||||||
std::string const& callbackId,
|
std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
std::string const& detectorId,
|
||||||
int priority) -> uint {
|
int priority) -> uint {
|
||||||
uint result = ServerSettingForm::addSlider(
|
uint result = gmlib::form::ServerSettingForm::addSlider(
|
||||||
text,
|
text,
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
step,
|
step,
|
||||||
defaultVal,
|
defaultVal,
|
||||||
CALLBACK_TYPE_DOUBLE,
|
CALLBACK_TYPE(double),
|
||||||
PLAYER_DETECROR,
|
PLAYER_DETECROR,
|
||||||
priority
|
priority
|
||||||
);
|
);
|
||||||
@@ -275,7 +228,7 @@ void Export_Form_API() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLIB_ServerSettingForm",
|
"GMLIB_gmlib::form::ServerSettingForm",
|
||||||
"addStepSlider",
|
"addStepSlider",
|
||||||
[](std::string const& text,
|
[](std::string const& text,
|
||||||
std::vector<std::string> steps,
|
std::vector<std::string> steps,
|
||||||
@@ -283,19 +236,19 @@ void Export_Form_API() {
|
|||||||
std::string const& callbackId,
|
std::string const& callbackId,
|
||||||
std::string const& detectorId,
|
std::string const& detectorId,
|
||||||
int priority) -> uint {
|
int priority) -> uint {
|
||||||
uint result = ServerSettingForm::addStepSlider(
|
uint result = gmlib::form::ServerSettingForm::addStepSlider(
|
||||||
text,
|
text,
|
||||||
steps,
|
steps,
|
||||||
defaultVal,
|
defaultVal,
|
||||||
CALLBACK_TYPE_LONG,
|
CALLBACK_TYPE(int64),
|
||||||
PLAYER_DETECROR,
|
PLAYER_DETECROR,
|
||||||
priority
|
priority
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "removeElement", [](uint id) -> bool {
|
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "removeElement", [](uint id) -> bool {
|
||||||
return ServerSettingForm::removeElement(id);
|
return gmlib::form::ServerSettingForm::removeElement(id);
|
||||||
});
|
});
|
||||||
////////////////////////////// NpcDialogueForm //////////////////////////////
|
////////////////////////////// NpcDialogueForm //////////////////////////////
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
|
|||||||
+5
-8
@@ -1,19 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <RemoteCallAPI.h>
|
|
||||||
#include <headers/include_all.h>
|
#include <headers/include_all.h>
|
||||||
|
|
||||||
using namespace gmlib;
|
#include <RemoteCallAPI.h>
|
||||||
using namespace world;
|
|
||||||
using namespace mod;
|
|
||||||
using namespace tools;
|
|
||||||
|
|
||||||
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
|
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
|
||||||
|
|
||||||
#define LIB_VERSION_MAJOR 0
|
#define LIB_VERSION_MAJOR 0
|
||||||
#define LIB_VERSION_MINOR 13
|
#define LIB_VERSION_MINOR 13
|
||||||
#define LIB_VERSION_PATCH 4
|
#define LIB_VERSION_PATCH 3
|
||||||
|
|
||||||
#define LIB_VERSION Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
|
#define LIB_VERSION gmlib::Version(LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH)
|
||||||
|
|
||||||
extern ll::Logger logger;
|
extern ll::Logger logger;
|
||||||
|
|
||||||
@@ -22,4 +18,5 @@ extern void Export_Legacy_GMLib_ServerAPI();
|
|||||||
extern void Export_Compatibility_API();
|
extern void Export_Compatibility_API();
|
||||||
extern void ExportPAPI();
|
extern void ExportPAPI();
|
||||||
extern void Export_Event_API();
|
extern void Export_Event_API();
|
||||||
extern void Export_Form_API();
|
extern void Export_BinaryStream_API();
|
||||||
|
extern void Export_Form_API();
|
||||||
|
|||||||
+74
-76
@@ -3,13 +3,8 @@
|
|||||||
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
|
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
|
||||||
|
|
||||||
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string const& key) {
|
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string const& key) {
|
||||||
if (HardCodedKeys.count(key)) {
|
if (HardCodedKeys.count(key)) return key;
|
||||||
return key;
|
return std::vector<RecipeIngredient>({RecipeIngredient(key, 0, 1)});
|
||||||
}
|
|
||||||
std::vector<RecipeIngredient> result;
|
|
||||||
auto item = RecipeIngredient(key, 0, 1);
|
|
||||||
result.emplace_back(item);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Export_Legacy_GMLib_ModAPI() {
|
void Export_Legacy_GMLib_ModAPI() {
|
||||||
@@ -22,18 +17,17 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& result,
|
std::string const& result,
|
||||||
int count,
|
int count,
|
||||||
std::string const& unlock) -> void {
|
std::string const& unlock) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::vector<RecipeIngredient> types;
|
std::vector<RecipeIngredient> types;
|
||||||
for (auto ing : ingredients) {
|
for (auto ing : ingredients) {
|
||||||
auto key = RecipeIngredient(ing, 0, 1);
|
types.emplace_back(ing, 0, 1);
|
||||||
types.push_back(key);
|
|
||||||
}
|
}
|
||||||
auto res = RecipeIngredient(result, 0, count);
|
gmlib::mod::recipe::JsonRecipeRegistry::registerShapelessCraftingTableRecipe(
|
||||||
auto unl = makeRecipeUnlockingKey(unlock);
|
recipe_id,
|
||||||
recipe::JsonRecipeRegistry::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
|
types,
|
||||||
|
RecipeIngredient(result, 0, count),
|
||||||
|
makeRecipeUnlockingKey(unlock)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -45,18 +39,18 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& result,
|
std::string const& result,
|
||||||
int count,
|
int count,
|
||||||
std::string const& unlock) -> void {
|
std::string const& unlock) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::vector<RecipeIngredient> types;
|
std::vector<RecipeIngredient> types;
|
||||||
for (auto ing : ingredients) {
|
for (auto ing : ingredients) {
|
||||||
auto key = RecipeIngredient(ing, 0, 1);
|
types.push_back(RecipeIngredient(ing, 0, 1));
|
||||||
types.push_back(key);
|
|
||||||
}
|
}
|
||||||
auto res = RecipeIngredient(result, 0, count);
|
gmlib::mod::recipe::JsonRecipeRegistry::registerShapedCraftingTableRecipe(
|
||||||
auto unl = makeRecipeUnlockingKey(unlock);
|
recipe_id,
|
||||||
recipe::JsonRecipeRegistry::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
|
shape,
|
||||||
|
types,
|
||||||
|
RecipeIngredient(result, 0, count),
|
||||||
|
makeRecipeUnlockingKey(unlock)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -66,13 +60,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& input,
|
std::string const& input,
|
||||||
std::string const& output,
|
std::string const& output,
|
||||||
std::vector<std::string> tags) -> void {
|
std::vector<std::string> tags) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
gmlib::mod::recipe::JsonRecipeRegistry::registerFurnaceRecipe(
|
||||||
return;
|
recipe_id,
|
||||||
}
|
RecipeIngredient(input, 0, 1),
|
||||||
auto inp = RecipeIngredient(input, 0, 1);
|
RecipeIngredient(output, 0, 1),
|
||||||
auto outp = RecipeIngredient(output, 0, 1);
|
tags
|
||||||
recipe::JsonRecipeRegistry::registerFurnaceRecipe(recipe_id, inp, outp, tags);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -80,12 +74,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
"registerBrewingMixRecipe",
|
"registerBrewingMixRecipe",
|
||||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||||
) -> void {
|
) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingMixRecipe(
|
||||||
return;
|
recipe_id,
|
||||||
}
|
input,
|
||||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
output,
|
||||||
recipe::JsonRecipeRegistry::registerBrewingMixRecipe(recipe_id, input, output, rea);
|
RecipeIngredient(reagent, 0, 1)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -93,14 +88,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
"registerBrewingContainerRecipe",
|
"registerBrewingContainerRecipe",
|
||||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||||
) -> void {
|
) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingContainerRecipe(
|
||||||
return;
|
recipe_id,
|
||||||
}
|
RecipeIngredient(input, 0, 1),
|
||||||
auto inp = RecipeIngredient(input, 0, 1);
|
RecipeIngredient(output, 0, 1),
|
||||||
auto outp = RecipeIngredient(output, 0, 1);
|
RecipeIngredient(reagent, 0, 1)
|
||||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
);
|
||||||
recipe::JsonRecipeRegistry::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -111,11 +105,14 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& base,
|
std::string const& base,
|
||||||
std::string const& addition,
|
std::string const& addition,
|
||||||
std::string const& result) -> void {
|
std::string const& result) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTransformRecipe(
|
||||||
return;
|
recipe_id,
|
||||||
}
|
smithing_template,
|
||||||
recipe::JsonRecipeRegistry::registerSmithingTransformRecipe(recipe_id, smithing_template, base, addition, result);
|
base,
|
||||||
|
addition,
|
||||||
|
result
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -125,11 +122,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& smithing_template,
|
std::string const& smithing_template,
|
||||||
std::string const& base,
|
std::string const& base,
|
||||||
std::string const& addition) -> void {
|
std::string const& addition) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTrimRecipe(
|
||||||
return;
|
recipe_id,
|
||||||
}
|
smithing_template,
|
||||||
recipe::JsonRecipeRegistry::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
|
base,
|
||||||
|
addition
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
@@ -141,50 +140,49 @@ void Export_Legacy_GMLib_ModAPI() {
|
|||||||
std::string const& output,
|
std::string const& output,
|
||||||
int output_data,
|
int output_data,
|
||||||
int output_count) -> void {
|
int output_count) -> void {
|
||||||
auto level = world::Level::getInstance();
|
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||||
if (!level) {
|
gmlib::mod::recipe::JsonRecipeRegistry::registerStoneCutterRecipe(
|
||||||
return;
|
recipe_id,
|
||||||
}
|
RecipeIngredient(input, 0, 1),
|
||||||
auto inp = RecipeIngredient(input, 0, 1);
|
RecipeIngredient(output, 0, 1)
|
||||||
auto outp = RecipeIngredient(output, 0, 1);
|
);
|
||||||
recipe::JsonRecipeRegistry::registerStoneCutterRecipe(recipe_id, inp, outp);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// 错误方块清理
|
// 错误方块清理
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
|
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
|
||||||
VanillaFix::setAutoCleanUnknownBlockEnabled();
|
gmlib::tools::VanillaFix::setAutoCleanUnknownBlockEnabled();
|
||||||
});
|
});
|
||||||
// 实验性
|
// 实验性
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
|
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
|
||||||
auto list = world::Level::getAllExperiments();
|
auto list = gmlib::world::Level::getAllExperiments();
|
||||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||||
if (set.contains((AllExperiments)experiment_id)) {
|
if (set.contains((AllExperiments)experiment_id)) {
|
||||||
world::Level::addExperimentsRequire((AllExperiments)experiment_id);
|
gmlib::world::Level::addExperimentsRequire((AllExperiments)experiment_id);
|
||||||
} else {
|
} else {
|
||||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
||||||
if (world::Level::getInstance()) {
|
if (gmlib::world::Level::getInstance()) {
|
||||||
auto list = world::Level::getAllExperiments();
|
auto list = gmlib::world::Level::getAllExperiments();
|
||||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||||
if (set.contains((AllExperiments)experiment_id)) {
|
if (set.contains((AllExperiments)experiment_id)) {
|
||||||
world::Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
gmlib::world::Level::getInstance()->setExperimentEnabled(((AllExperiments)experiment_id), value);
|
||||||
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
||||||
if (world::Level::getInstance()) {
|
if (gmlib::world::Level::getInstance()) {
|
||||||
auto list = world::Level::getAllExperiments();
|
auto list = gmlib::world::Level::getAllExperiments();
|
||||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||||
if (set.contains((AllExperiments)experiment_id)) {
|
if (set.contains((AllExperiments)experiment_id)) {
|
||||||
return world::Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
return gmlib::world::Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||||
} else {
|
|
||||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void { VanillaFix::setFixI18nEnabled(); });
|
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
|
||||||
|
gmlib::tools::VanillaFix::setFixI18nEnabled();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
+28
-31
@@ -2,81 +2,78 @@
|
|||||||
|
|
||||||
void Export_Legacy_GMLib_ServerAPI() {
|
void Export_Legacy_GMLib_ServerAPI() {
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
||||||
world::Level::tryEnableEducationEdition();
|
gmlib::world::Level::tryEnableEducationEdition();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
||||||
world::Level::tryRegisterAbilityCommand();
|
gmlib::world::Level::tryRegisterAbilityCommand();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
||||||
world::Level::setForceAchievementsEnabled();
|
gmlib::world::Level::setForceAchievementsEnabled();
|
||||||
|
});
|
||||||
|
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void {
|
||||||
|
gmlib::world::Level::trustAllSkins();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { world::Level::trustAllSkins(); });
|
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
|
||||||
world::Level::requireServerResourcePackAndAllowClientResourcePack();
|
gmlib::world::Level::requireServerResourcePackAndAllowClientResourcePack();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||||
if (auto level = world::Level::getInstance()) {
|
return gmlib::world::Level::getInstance()
|
||||||
return level->getLevelName();
|
.transform([](gmlib::world::Level& level) -> std::string { return level.getLevelName(); })
|
||||||
}
|
.value_or("");
|
||||||
return {};
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void {
|
||||||
if (auto level = world::Level::getInstance()) {
|
if (auto level = gmlib::world::Level::getInstance()) {
|
||||||
level->setLevelName(name);
|
level->setLevelName(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string {
|
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string {
|
||||||
if (auto level = world::Level::getInstance()) {
|
return gmlib::world::Level::getInstance()
|
||||||
return std::to_string(level->getSeed());
|
.transform([](gmlib::world::Level& level) -> std::string { return std::to_string(level.getSeed()); })
|
||||||
}
|
.value_or("");
|
||||||
return {};
|
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
||||||
return world::Level::setFakeSeed(seed);
|
return gmlib::world::Level::setFakeSeed(seed);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"spawnEntity",
|
"spawnEntity",
|
||||||
[](std::pair<Vec3, int> pos, std::string const& name) -> ::Actor* {
|
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* {
|
||||||
return world::Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
return gmlib::world::Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"shootProjectile",
|
"shootProjectile",
|
||||||
[](::Actor* owner, std::string const& name, float speed, float offset) -> ::Actor* {
|
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
|
||||||
auto ac = (world::Actor*)owner;
|
auto ac = (gmlib::world::Actor*)owner;
|
||||||
return ac->shootProjectile(name, speed, offset).as_ptr();
|
return ac->shootProjectile(name, speed, offset).as_ptr();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"throwEntity",
|
"throwEntity",
|
||||||
[](::Actor* owner, ::Actor* actor, float speed, float offset) -> bool {
|
[](Actor* owner, Actor* actor, float speed, float offset) -> bool {
|
||||||
auto ac = (world::Actor*)owner;
|
auto ac = (gmlib::world::Actor*)owner;
|
||||||
return ac->throwEntity(*actor, speed, offset);
|
return ac->throwEntity(*actor, speed, offset);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](::Player* player) -> ::Actor* {
|
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { return (Actor*)player; });
|
||||||
return (::Actor*)player;
|
|
||||||
});
|
|
||||||
RemoteCall::exportAs(
|
RemoteCall::exportAs(
|
||||||
"GMLib_ServerAPI",
|
"GMLib_ServerAPI",
|
||||||
"addFakeList",
|
"addFakeList",
|
||||||
[](const std::string& name, const std::string& xuid) -> bool {
|
[](const std::string& name, const std::string& xuid) -> bool {
|
||||||
return FakeList::addFakeList(name, xuid, ActorUniqueID(-1));
|
return gmlib::tools::FakeList::addFakeList(name, xuid, ActorUniqueID(-1));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool {
|
RemoteCall::exportAs("GMLib_ServerAPI", "removeFakeList", [](const std::string& nameOrXuid) -> bool {
|
||||||
return FakeList::removeFakeList(nameOrXuid);
|
return gmlib::tools::FakeList::removeFakeList(nameOrXuid);
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
|
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
|
||||||
return FakeList::removeAllFakeLists();
|
return gmlib::tools::FakeList::removeAllFakeLists();
|
||||||
});
|
});
|
||||||
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
|
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
|
||||||
if (auto level = world::Level::getInstance()) {
|
return gmlib::world::Level::getInstance()
|
||||||
return level->getMaxPlayerCount();
|
.transform([](gmlib::world::Level& level) -> int { return level.getMaxPlayerCount(); })
|
||||||
}
|
.value_or(0);
|
||||||
return {};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-19
@@ -13,9 +13,11 @@ bool isParameters(std::string const& str) {
|
|||||||
return std::regex_search(removeBrackets(str), reg);
|
return std::regex_search(removeBrackets(str), reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetValue(std::string const& from) { return PlaceholderAPI::getValue(from); }
|
std::string GetValue(std::string const& from) { return gmlib::tools::PlaceholderAPI::getValue(from); }
|
||||||
|
|
||||||
std::string GetValueWithPlayer(std::string const& key, ::Player* player) { return PlaceholderAPI::getValue(key, player); }
|
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
||||||
|
return gmlib::tools::PlaceholderAPI::getValue(key, player);
|
||||||
|
}
|
||||||
|
|
||||||
bool registerPlayerPlaceholder(
|
bool registerPlayerPlaceholder(
|
||||||
std::string const& PluginName,
|
std::string const& PluginName,
|
||||||
@@ -23,20 +25,24 @@ bool registerPlayerPlaceholder(
|
|||||||
std::string const& PAPIName
|
std::string const& PAPIName
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
if (isParameters(PAPIName)) {
|
if (isParameters(PAPIName)) {
|
||||||
auto Call = RemoteCall::importAs<std::string(::Player * pl, std::unordered_map<std::string, std::string>)>(
|
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
||||||
PluginName,
|
PluginName,
|
||||||
FuncName
|
FuncName
|
||||||
);
|
);
|
||||||
PlaceholderAPI::registerPlayerPlaceholder(
|
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
||||||
PAPIName,
|
PAPIName,
|
||||||
[Call](::Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
|
[Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
|
||||||
PluginName
|
PluginName
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
auto Call = RemoteCall::importAs<std::string(::Player * pl)>(PluginName, FuncName);
|
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
|
||||||
PlaceholderAPI::registerPlayerPlaceholder(PAPIName, [Call](::Player* sp) { return Call(sp); }, PluginName);
|
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
||||||
|
PAPIName,
|
||||||
|
[Call](Player* sp) { return Call(sp); },
|
||||||
|
PluginName
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -49,18 +55,18 @@ bool registerServerPlaceholder(
|
|||||||
std::string const& PAPIName
|
std::string const& PAPIName
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
if (isParameters(PAPIName)) {
|
if (isParameters(PAPIName)) {
|
||||||
auto Call =
|
auto Call =
|
||||||
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
||||||
PlaceholderAPI::registerServerPlaceholder(
|
gmlib::tools::PlaceholderAPI::registerServerPlaceholder(
|
||||||
PAPIName,
|
PAPIName,
|
||||||
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
|
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
|
||||||
PluginName
|
PluginName
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||||
PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
|
gmlib::tools::PlaceholderAPI::registerServerPlaceholder(PAPIName, [Call]() { return Call(); }, PluginName);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -74,13 +80,22 @@ bool registerStaticPlaceholder(
|
|||||||
int num
|
int num
|
||||||
) {
|
) {
|
||||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||||
if (isParameters(PAPIName)) {
|
if (isParameters(PAPIName)) {
|
||||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||||
if (num == -1) {
|
if (num == -1) {
|
||||||
PlaceholderAPI::registerStaticPlaceholder(PAPIName, [Call] { return Call(); }, PluginName);
|
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
||||||
|
PAPIName,
|
||||||
|
[Call] { return Call(); },
|
||||||
|
PluginName
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
PlaceholderAPI::registerStaticPlaceholder(PAPIName, num, [Call] { return Call(); }, PluginName);
|
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
||||||
|
PAPIName,
|
||||||
|
num,
|
||||||
|
[Call] { return Call(); },
|
||||||
|
PluginName
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -88,15 +103,15 @@ bool registerStaticPlaceholder(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string translateStringWithPlayer(std::string const& str, ::Player* pl) {
|
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
|
||||||
return PlaceholderAPI::translateString(str, pl);
|
return gmlib::tools::PlaceholderAPI::translateString(str, pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string translateString(std::string const& str) { return PlaceholderAPI::translateString(str); }
|
std::string translateString(std::string const& str) { return gmlib::tools::PlaceholderAPI::translateString(str); }
|
||||||
|
|
||||||
bool unRegisterPlaceholder(std::string const& str) { return PlaceholderAPI::unregisterPlaceholder(str); }
|
bool unRegisterPlaceholder(std::string const& str) { return gmlib::tools::PlaceholderAPI::unregisterPlaceholder(str); }
|
||||||
|
|
||||||
std::vector<std::string> getAllPAPI() { return PlaceholderAPI::getAllPAPI(); }
|
std::vector<std::string> getAllPAPI() { return gmlib::tools::PlaceholderAPI::getAllPAPI(); }
|
||||||
|
|
||||||
} // namespace PAPIRemoteCall
|
} // namespace PAPIRemoteCall
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user