Compare commits
33 Commits
Vendored
+6
-6
@@ -55,8 +55,8 @@ declare class Event {
|
||||
item: Item,
|
||||
/** 尝试生成的坐标对象 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体对象 */
|
||||
spawnerEntity: Entity
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => boolean | void
|
||||
): boolean;
|
||||
|
||||
@@ -72,15 +72,15 @@ declare class Event {
|
||||
entity: Entity,
|
||||
/** 实体生成的坐标 */
|
||||
pos: FloatPos,
|
||||
/** 创建掉落物的实体对象 */
|
||||
spawnerEntity: Entity
|
||||
/** 创建掉落物的实体uniqueId */
|
||||
spawnerUniqueId: number
|
||||
) => void
|
||||
): boolean;
|
||||
|
||||
/** 实体切换维度 */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityChangeDim",
|
||||
event: "onEntityTryChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
@@ -93,7 +93,7 @@ declare class Event {
|
||||
/** 实体切换维度后(不可拦截) */
|
||||
static listen(
|
||||
/** 事件名 */
|
||||
event: "onEntityChangeDimAfter",
|
||||
event: "onEntityChangeDim",
|
||||
/** 回调函数 */
|
||||
listener: (
|
||||
/** 切换维度的实体对象 */
|
||||
|
||||
+7
-21
@@ -1,23 +1,11 @@
|
||||
/** 事件创建函数 @type {function(string,string):boolean} */
|
||||
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
|
||||
|
||||
/** 事件ID @type {number} */
|
||||
let NextEventId = 0;
|
||||
|
||||
/**
|
||||
* 获取事件ID标识名
|
||||
* @returns {string} 事件ID标识名
|
||||
*/
|
||||
function getNextEventId() {
|
||||
NextEventId++;
|
||||
return "GMLIB_Event_" + NextEventId;
|
||||
}
|
||||
const CallEvent = ll.import("GMLIB_Event_API", "callCustomEvent");
|
||||
/** 获取事件ID函数 @type {function():string} */
|
||||
const getNextEventId = ll.import("GMLIB_Event_API", "getNextScriptEventId");
|
||||
|
||||
/** 事件类 */
|
||||
class Event {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
constructor() { throw new Error("Static class cannot be instantiated"); }
|
||||
|
||||
/**
|
||||
* 监听事件
|
||||
@@ -30,13 +18,11 @@ class Event {
|
||||
ll.export(callback, event, eventId);
|
||||
let result = CallEvent(event, eventId);
|
||||
if (!result) {
|
||||
logger.error(`Cannot listen event "${event}"!`);
|
||||
logger.error(`Event "${event}" No Found!`);
|
||||
logger.error(`Cannot listen event "${event}" !`);
|
||||
logger.error(`GMLIB Script Event "${event}" does not exist !`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Event
|
||||
};
|
||||
module.exports = { Event };
|
||||
@@ -0,0 +1,182 @@
|
||||
// const getNextCallbackId = ll.import("GMLIB_FormAPI", "getNextFormCallbackId");
|
||||
|
||||
class ServerSettingForm {
|
||||
constructor() {
|
||||
throw new Error("Static class cannot be instantiated");
|
||||
}
|
||||
|
||||
static getDefaultPriority() {
|
||||
return ll.import("GMLIB_ServerSettingForm", "getDefaultPriority")();
|
||||
}
|
||||
|
||||
static hasTitle() {
|
||||
return ll.import("GMLIB_ServerSettingForm", "hasTitle")();
|
||||
}
|
||||
|
||||
static getTitle() {
|
||||
return ll.import("GMLIB_ServerSettingForm", "getTitle")();
|
||||
}
|
||||
|
||||
static setTitle(title, forceModify = false) {
|
||||
return ll.import("GMLIB_ServerSettingForm", "setTitle")(title, forceModify);
|
||||
}
|
||||
|
||||
static hasIcon() {
|
||||
return ll.import("GMLIB_ServerSettingForm", "hasIcon")();
|
||||
}
|
||||
|
||||
static getIconData() {
|
||||
return hasIcon() ? ll.import("GMLIB_ServerSettingForm", "getIconData")() : null;
|
||||
}
|
||||
|
||||
static getIconType() {
|
||||
return ll.import("GMLIB_ServerSettingForm", "getIconType")();
|
||||
}
|
||||
|
||||
static setIcon(data, type = 0, forceModify = false) {
|
||||
return ll.import("GMLIB_ServerSettingForm", "setIcon")(data, type, forceModify);
|
||||
}
|
||||
|
||||
static addLabel(
|
||||
text,
|
||||
playerDetector = (pl) => { return true; },
|
||||
priority = this.getDefaultPriority()
|
||||
) {
|
||||
let detectorId = getNextCallbackId();
|
||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
return ll.import("GMLIB_ServerSettingForm", "addLabel")(text, detectorId, priority);
|
||||
}
|
||||
|
||||
|
||||
static addInput(
|
||||
text,
|
||||
placeholder,
|
||||
defaultVal,
|
||||
callback = (pl, input) => { },
|
||||
playerDetector = (pl) => { return true; },
|
||||
priority = this.getDefaultPriority()
|
||||
) {
|
||||
let callbackId = getNextCallbackId();
|
||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
let detectorId = getNextCallbackId();
|
||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
return ll.import("GMLIB_ServerSettingForm", "addInput")(text, placeholder, defaultVal, callbackId, detectorId, priority);
|
||||
}
|
||||
|
||||
static addToggle(
|
||||
text,
|
||||
defaultVal = false,
|
||||
callback = (pl, input) => { },
|
||||
playerDetector = (pl) => { return true; },
|
||||
priority = this.getDefaultPriority()
|
||||
) {
|
||||
let callbackId = getNextCallbackId();
|
||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
let detectorId = getNextCallbackId();
|
||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
return ll.import("GMLIB_ServerSettingForm", "addToggle")(text, defaultVal, callbackId, detectorId, priority);
|
||||
}
|
||||
|
||||
static addDropdown(
|
||||
text,
|
||||
options,
|
||||
defaultVal = 0,
|
||||
callback = (pl, input) => { },
|
||||
playerDetector = (pl) => { return true; },
|
||||
priority = this.getDefaultPriority()
|
||||
) {
|
||||
let callbackId = getNextCallbackId();
|
||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
let detectorId = getNextCallbackId();
|
||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
return ll.import("GMLIB_ServerSettingForm", "addDropdown")(text, options, defaultVal, callbackId, detectorId, priority);
|
||||
}
|
||||
|
||||
static addSlider(
|
||||
text,
|
||||
min,
|
||||
max,
|
||||
step = 0.0,
|
||||
defaultVal = 0.0,
|
||||
callback = (pl, input) => { },
|
||||
playerDetector = (pl) => { return true; },
|
||||
priority = this.getDefaultPriority()
|
||||
) {
|
||||
let callbackId = getNextCallbackId();
|
||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
let detectorId = getNextCallbackId();
|
||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
return ll.import("GMLIB_ServerSettingForm", "addSlider")(text, min, max, step, defaultVal, callbackId, detectorId, priority);
|
||||
}
|
||||
|
||||
static addStepSlider(
|
||||
text,
|
||||
steps,
|
||||
defaultVal = 0,
|
||||
callback = (pl, input) => { },
|
||||
playerDetector = (pl) => { return true; },
|
||||
priority = this.getDefaultPriority()
|
||||
) {
|
||||
let callbackId = getNextCallbackId();
|
||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
let detectorId = getNextCallbackId();
|
||||
ll.export(playerDetector, "GMLIB_FORM_CALLBACK", detectorId);
|
||||
return ll.import("GMLIB_ServerSettingForm", "addStepSlider")(text, steps, defaultVal, callbackId, detectorId, priority);
|
||||
}
|
||||
|
||||
static removeElement(id) {
|
||||
return ll.import("GMLIB_ServerSettingForm", "removeElement")(id);
|
||||
}
|
||||
}
|
||||
|
||||
class NpcDialogueForm {
|
||||
constructor(npcName, sceneName, dialogue) {
|
||||
this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
||||
}
|
||||
|
||||
addButton(button) {
|
||||
return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
||||
}
|
||||
|
||||
sendTo(pl, callback = (pl, index, type) => { }, free = true) {
|
||||
let callbackId = getNextCallbackId();
|
||||
ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
||||
if (free) {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
||||
}
|
||||
}
|
||||
|
||||
class ChestForm {
|
||||
constructor(npcName, sceneName, dialogue) {
|
||||
this.mFormId = ll.import("GMLIB_NpcDialogueForm", "createForm")(npcName, sceneName, dialogue);
|
||||
}
|
||||
|
||||
addButton(button) {
|
||||
return ll.import("GMLIB_NpcDialogueForm", "addButton")(this.mFormId, button);
|
||||
}
|
||||
|
||||
sendTo(pl, free = true) {
|
||||
//let callbackId = getNextCallbackId();
|
||||
//ll.export(callback, "GMLIB_FORM_CALLBACK", callbackId);
|
||||
//ll.import("GMLIB_NpcDialogueForm", "sendTo")(this.mFormId, pl, callbackId);
|
||||
//if (free) {
|
||||
// this.destroy();
|
||||
//}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
//ll.import("GMLIB_NpcDialogueForm", "destroyForm")(this.mFormId);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ServerSettingForm,
|
||||
NpcDialogueForm,
|
||||
ChestForm
|
||||
};
|
||||
Vendored
+306
-1
@@ -509,6 +509,28 @@ declare class Recipes {
|
||||
/** 解锁条件(也可以填物品命名空间ID) */
|
||||
unlock: "AlwaysUnlocked" | "PlayerHasManyItems" | "PlayerInWater" | "None" | undefined
|
||||
): boolean;
|
||||
|
||||
/** 注册自定义有序合成表 */
|
||||
static registerCustomShapedRecipe(
|
||||
/** 合成表唯一标识符 */
|
||||
recipeId: string,
|
||||
/** 合成表摆放方式,数组元素为字符串 */
|
||||
shape: [string, string, string],
|
||||
/** 材料数组 */
|
||||
ingredients: string[],
|
||||
/** 合成结果 */
|
||||
result: Item
|
||||
): boolean;
|
||||
|
||||
/** 注册自定义无序合成表 */
|
||||
static registerCustomShapelessRecipe(
|
||||
/** 合成表唯一标识符 */
|
||||
recipeId: string,
|
||||
/** 合成材料 */
|
||||
ingredients: string[],
|
||||
/** 合成结果 */
|
||||
result: Item
|
||||
): boolean;
|
||||
}
|
||||
|
||||
/** 实验性功能类 */
|
||||
@@ -1032,6 +1054,289 @@ declare class UserCache {
|
||||
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 {
|
||||
/** (GMLIB)转换成实体对象 */
|
||||
toEntity(): Entity;
|
||||
@@ -1059,7 +1364,7 @@ interface Player {
|
||||
/** (GMLIB)获取玩家的rumtimeId */
|
||||
getRuntimeId(): number;
|
||||
|
||||
/** (GMLIB)获取玩家饱食度 */
|
||||
/** (GMLIB)获取玩家饥饿值 */
|
||||
getHungry(): number;
|
||||
|
||||
/** (GMLIB)获取玩家盔甲覆盖百分比 */
|
||||
|
||||
+502
-8
@@ -96,6 +96,10 @@ const GMLIB_API = {
|
||||
registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"),
|
||||
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||
registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"),
|
||||
/** 注册有序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||
registerCustomShapedRecipe: ll.import("GMLIB_API", "registerCustomShapedRecipe"),
|
||||
/** 注册无序合成表 @type {function(string,Array.<string>,Array.<string>,string,number,string)} */
|
||||
registerCustomShapelessRecipe: ll.import("GMLIB_API", "registerCustomShapelessRecipe"),
|
||||
/** 检测LRCA版本是否大于或等于此版本 @type {function(number,number,number):boolean} */
|
||||
isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"),
|
||||
/** 获取LRCA版本 @type {function():string} */
|
||||
@@ -312,7 +316,7 @@ const GMLIB_API = {
|
||||
getItemCanPlaceOn: ll.import("GMLIB_API", "getItemCanPlaceOn"),
|
||||
/** 设置物品冒险模式下能放置在什么方块上 @type {function(Item,Array.<string>):void} */
|
||||
setItemCanPlaceOn: ll.import("GMLIB_API", "setItemCanPlaceOn"),
|
||||
/** 获取玩家饱食度 @type {function(Player):number} */
|
||||
/** 获取玩家饥饿值 @type {function(Player):number} */
|
||||
getPlayerHungry: ll.import("GMLIB_API", "getPlayerHungry"),
|
||||
/** 获取玩家盔甲覆盖百分比 @type {function(Player):number} */
|
||||
getPlayerArmorCoverPercentage: ll.import("GMLIB_API", "getPlayerArmorCoverPercentage"),
|
||||
@@ -370,7 +374,61 @@ const GMLIB_API = {
|
||||
getDefaultGameMode: ll.import("GMLIB_API", "getDefaultGameMode"),
|
||||
/** 设置默认游戏模式 @type {function(mode):void} */
|
||||
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>} */
|
||||
const mStaticFloatingTextMap = new Map();
|
||||
@@ -539,9 +597,7 @@ class DynamicFloatingText extends StaticFloatingText {
|
||||
* @param {boolean} [papi=true] 是否使用PAPI变量
|
||||
*/
|
||||
constructor(pos, text, updateRate = 1, papi = true) {
|
||||
this.mPosition = pos;
|
||||
this.mText = text;
|
||||
this.mPlaceholderAPI = papi;
|
||||
super(pos, text, papi);
|
||||
this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText, this.mPlaceholderAPI);
|
||||
this.mUpdateRate = updateRate;
|
||||
this.mTaskId = null;
|
||||
@@ -1196,6 +1252,18 @@ class Recipes {
|
||||
return GMLIB_API.registerShapedRecipe(recipeId, shape, ingredients, result, count, unlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义有序合成表
|
||||
* @param {string} recipeId 合成表唯一标识
|
||||
* @param {[string,string,string]} shape 合成表摆放方式,数组元素为字符串
|
||||
* @param {Array.<string>} ingredients 材料数组
|
||||
* @param {Item} result 合成结果
|
||||
* @returns {boolean} 是否注册成功
|
||||
*/
|
||||
static registerCustomShapedRecipe(recipeId, shape, ingredients, result) {
|
||||
return GMLIB_API.registerCustomShapedRecipe(recipeId, shape, ingredients, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册无序合成表
|
||||
* @param {string} recipeId 合成表唯一标识
|
||||
@@ -1208,6 +1276,17 @@ class Recipes {
|
||||
static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") {
|
||||
return GMLIB_API.registerShapelessRecipe(recipeId, ingredients, result, count, unlock);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册自定义无序合成表
|
||||
* @param {string} recipeId 合成表唯一标识
|
||||
* @param {Array.<string>} ingredients 合成材料
|
||||
* @param {Item} result 合成结果
|
||||
* @returns {boolean} 是否注册成功
|
||||
*/
|
||||
static registerCustomShapelessRecipe(recipeId, ingredients, result) {
|
||||
return GMLIB_API.registerCustomShapelessRecipe(recipeId, ingredients, result);
|
||||
}
|
||||
}
|
||||
|
||||
/** 实验性功能类 */
|
||||
@@ -2027,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 =
|
||||
/**
|
||||
* 获取实体对象
|
||||
@@ -2445,7 +2938,7 @@ LLSE_Item.prototype.setCanPlaceOn =
|
||||
|
||||
LLSE_Player.prototype.getHungry =
|
||||
/**
|
||||
* 获取玩家饱食度
|
||||
* 获取玩家饥饿值
|
||||
* @returns {number}
|
||||
*/
|
||||
function () {
|
||||
@@ -2470,7 +2963,7 @@ LLSE_Player.prototype.getArmorValue =
|
||||
return GMLIB_API.getPlayerArmorValue(this);
|
||||
}
|
||||
|
||||
LLSE_Player.prototype.getEntityOwner =
|
||||
LLSE_Entity.prototype.getEntityOwner =
|
||||
/**
|
||||
* 获取实体的主人
|
||||
* @returns {Entity|null}
|
||||
@@ -2636,5 +3129,6 @@ module.exports = {
|
||||
JsonI18n,
|
||||
Version,
|
||||
I18nAPI,
|
||||
UserCache
|
||||
UserCache,
|
||||
GMLIB_BinaryStream
|
||||
};
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "${pluginName}",
|
||||
"entry": "${pluginFile}",
|
||||
"version": "0.13.2",
|
||||
"version": "0.13.3",
|
||||
"author": "GroupMountain",
|
||||
"type": "native",
|
||||
"passive": true,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
+264
-336
File diff suppressed because it is too large
Load Diff
+6
-4
@@ -3,7 +3,7 @@
|
||||
|
||||
ll::Logger logger(PLUGIN_NAME);
|
||||
|
||||
namespace GMLIB {
|
||||
namespace gmlib {
|
||||
|
||||
std::unique_ptr<LegacyRemoteCallApi>& LegacyRemoteCallApi::getInstance() {
|
||||
static std::unique_ptr<LegacyRemoteCallApi> instance;
|
||||
@@ -16,10 +16,12 @@ bool LegacyRemoteCallApi::load() {
|
||||
Export_Compatibility_API();
|
||||
ExportPAPI();
|
||||
Export_Event_API();
|
||||
Export_BinaryStream_API();
|
||||
Export_Form_API();
|
||||
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
|
||||
logger.info(
|
||||
"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())
|
||||
);
|
||||
logger.info("Author: GroupMountain");
|
||||
@@ -31,6 +33,6 @@ bool LegacyRemoteCallApi::enable() { return true; }
|
||||
|
||||
bool LegacyRemoteCallApi::disable() { return true; }
|
||||
|
||||
} // namespace GMLIB
|
||||
} // namespace gmlib
|
||||
|
||||
LL_REGISTER_MOD(LegacyRemoteCallApi, LegacyRemoteCallApi::getInstance());
|
||||
LL_REGISTER_MOD(gmlib::LegacyRemoteCallApi, gmlib::LegacyRemoteCallApi::getInstance());
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
#include <ll/api/mod/NativeMod.h>
|
||||
#include <ll/api/mod/RegisterHelper.h>
|
||||
|
||||
namespace GMLIB {
|
||||
namespace gmlib {
|
||||
|
||||
class LegacyRemoteCallApi {
|
||||
|
||||
@@ -30,4 +30,4 @@ private:
|
||||
ll::mod::NativeMod& mSelf;
|
||||
};
|
||||
|
||||
} // namespace GMLIB
|
||||
} // namespace gmlib
|
||||
|
||||
+185
-269
@@ -1,271 +1,206 @@
|
||||
#include "Global.h"
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class LegacyScriptEventManager {
|
||||
private:
|
||||
int64 mNextEventId = 0;
|
||||
std::unordered_map<uint64, ll::event::ListenerPtr> mEventListeners;
|
||||
|
||||
public:
|
||||
std::string getNextEventId() {
|
||||
mNextEventId++;
|
||||
return "GMLIB_EVENT_" + std::to_string(mNextEventId);
|
||||
}
|
||||
|
||||
void emplaceListener(std::string const& scriptEventId, ll::event::ListenerPtr listenerPtr) {
|
||||
mEventListeners[doHash(scriptEventId)] = std::move(listenerPtr);
|
||||
}
|
||||
|
||||
void removeListener(std::string const& scriptEventId) {
|
||||
ll::event::EventBus::getInstance().removeListener(mEventListeners[doHash(scriptEventId)]);
|
||||
mEventListeners.erase(doHash(scriptEventId));
|
||||
}
|
||||
|
||||
public:
|
||||
static LegacyScriptEventManager& getInstance() {
|
||||
static std::unique_ptr<LegacyScriptEventManager> instance;
|
||||
if (!instance) {
|
||||
instance = std::make_unique<LegacyScriptEventManager>();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_EVENT_LISTEN(eventType, callFunction, eventParams, cancelFunction, otherFunction) \
|
||||
eventManager.emplaceListener( \
|
||||
eventId, \
|
||||
eventBus.emplaceListener<eventType>([eventName, eventId, &eventBus, &eventManager](eventType& ev) -> void { \
|
||||
if (!RemoteCall::hasFunc(eventName, eventId)) { \
|
||||
eventManager.removeListener(eventId); \
|
||||
return; \
|
||||
} \
|
||||
bool result = true; \
|
||||
try { \
|
||||
otherFunction; \
|
||||
result = RemoteCall::importAs<bool callFunction>(eventName, eventId) eventParams; \
|
||||
} catch (...) {} \
|
||||
if (!result) cancelFunction; \
|
||||
}) \
|
||||
); \
|
||||
return true;
|
||||
|
||||
void Export_Event_API() {
|
||||
auto eventBus = &ll::event::EventBus::getInstance();
|
||||
RemoteCall::exportAs("GMLIB_Event_API", "getNextScriptEventId", []() -> std::string {
|
||||
return LegacyScriptEventManager::getInstance().getNextEventId();
|
||||
});
|
||||
auto& eventBus = ll::event::EventBus::getInstance();
|
||||
auto& eventManager = LegacyScriptEventManager::getInstance();
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_API",
|
||||
"GMLIB_Event_API",
|
||||
"callCustomEvent",
|
||||
[eventBus](std::string const& eventName, std::string const& eventId) -> bool {
|
||||
[&eventBus, &eventManager](std::string const& eventName, std::string const& eventId) -> bool {
|
||||
if (!RemoteCall::hasFunc(eventName, eventId)) return false;
|
||||
switch (doHash(eventName)) {
|
||||
case doHash("onClientLogin"): {
|
||||
auto Call = RemoteCall::importAs<bool(
|
||||
std::string const& realName,
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::packet::ClientLoginAfterEvent,
|
||||
(std::string const& realName,
|
||||
std::string const& uuid,
|
||||
std::string const& serverXuid,
|
||||
std::string const& clientXuid
|
||||
)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PacketEvent::ClientLoginAfterEvent>(
|
||||
[Call](Event::PacketEvent::ClientLoginAfterEvent& ev) {
|
||||
try {
|
||||
Call(
|
||||
ev.getRealName(),
|
||||
ev.getUuid().asString(),
|
||||
ev.getServerAuthXuid(),
|
||||
ev.getClientAuthXuid()
|
||||
);
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
std::string const& clientXuid),
|
||||
(ev.getRealName(), ev.getUuid().asString(), ev.getServerAuthXuid(), ev.getClientAuthXuid()),
|
||||
logger.error("Event \"onClientLogin\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onWeatherChange"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::LevelEvent::WeatherUpdateBeforeEvent>(
|
||||
[Call](Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(
|
||||
ev.getLightningLevel(),
|
||||
ev.getRainLevel(),
|
||||
ev.getLightningLastTick(),
|
||||
ev.getRainingLastTick()
|
||||
);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::level::WeatherUpdateBeforeEvent,
|
||||
(int lightningLevel, int rainLevel, int lightningLast, int rainLast),
|
||||
(ev.getLightningLevel(), ev.getRainLevel(), ev.getLightningLastTick(), ev.getRainingLastTick()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onMobPick"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::MobPickupItemBeforeEvent>(
|
||||
[Call](Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), (Actor*)&ev.getItemActor());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::MobPickupItemBeforeEvent,
|
||||
(Actor * mob, Actor * item),
|
||||
(&ev.self(), (Actor*)&ev.getItemActor()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onItemTrySpawn"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnBeforeEvent>(
|
||||
[Call](Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.getItem(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ItemActorSpawnBeforeEvent,
|
||||
(const ItemStack* item, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||
(&ev.getItem(),
|
||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onItemSpawned"): {
|
||||
auto Call = RemoteCall::importAs<
|
||||
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ItemActorSpawnAfterEvent>(
|
||||
[Call](Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
|
||||
auto pos = ev.getPosition();
|
||||
auto dimid = ev.getBlockSource().getDimensionId().id;
|
||||
std::pair<Vec3, int> lsePos = {pos, dimid};
|
||||
try {
|
||||
Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner());
|
||||
} catch (...) {}
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ItemActorSpawnAfterEvent,
|
||||
(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, int64 spawnerUniqueId),
|
||||
(&ev.getItem(),
|
||||
(Actor*)&ev.getItemActor(),
|
||||
{ev.getPosition(), ev.getBlockSource().getDimensionId().id},
|
||||
ev.getSpawner().has_value() ? ev.getSpawner()->getOrCreateUniqueID().id : -1),
|
||||
logger.error("Event \"onItemSpawned\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEntityChangeDim"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * entity, int toDimId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ActorChangeDimensionBeforeEvent>(
|
||||
[Call](Event::EntityEvent::ActorChangeDimensionBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), ev.getToDimensionId());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
case doHash("onEntityTryChangeDim"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ActorChangeDimensionBeforeEvent,
|
||||
(Actor * entity, int toDimId),
|
||||
(&ev.self(), ev.getToDimensionId()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onLeaveBed"): {
|
||||
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
|
||||
[Call](Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::player::PlayerStopSleepBeforeEvent,
|
||||
(Player * pl),
|
||||
(&ev.self()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onDeathMessage"): {
|
||||
auto Call =
|
||||
RemoteCall::importAs<bool(std::string const& message, std::vector<std::string>, Actor* dead)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::DeathMessageAfterEvent>(
|
||||
[Call](Event::EntityEvent::DeathMessageAfterEvent& ev) {
|
||||
auto msg = ev.getDeathMessage();
|
||||
auto source = ev.getDamageSource();
|
||||
try {
|
||||
Call(msg.first, msg.second, &ev.self());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::DeathMessageAfterEvent,
|
||||
(std::string const& message, std::vector<std::string>, Actor* dead),
|
||||
(ev.getDeathMessage().first, ev.getDeathMessage().second, &ev.self()),
|
||||
logger.error("Event \"onDeathMessage\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onMobHurted"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * source, float damage, int cause)>(
|
||||
eventName,
|
||||
eventId
|
||||
);
|
||||
eventBus->emplaceListener<Event::EntityEvent::MobHurtAfterEvent>(
|
||||
[Call](Event::EntityEvent::MobHurtAfterEvent& ev) {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::MobHurtAfterEvent,
|
||||
(Actor * mob, Actor * source, float damage, int cause),
|
||||
(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause()),
|
||||
logger.error("Event \"onMobHurted\" cannot be intercepted"),
|
||||
auto& damageSource = ev.getSource();
|
||||
Actor* source = nullptr;
|
||||
if (damageSource.isEntitySource()) {
|
||||
auto uniqueId = damageSource.getDamagingEntityUniqueID();
|
||||
source = ll::service::getLevel()->fetchEntity(uniqueId);
|
||||
if (source->getOwner()) {
|
||||
source = source->getOwner();
|
||||
if (source->getOwner()) source = source->getOwner();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Call(&ev.self(), source, ev.getDamage(), (int)damageSource.getCause());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
)
|
||||
}
|
||||
case doHash("onEndermanTake"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::EndermanTakeBlockBeforeEvent>(
|
||||
[Call](Event::EntityEvent::EndermanTakeBlockBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self());
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::EndermanTakeBlockBeforeEvent,
|
||||
(Actor * mob),
|
||||
(&ev.self()),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
case doHash("onEntityChangeDimAfter"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, int fromDimId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ActorChangeDimensionAfterEvent>(
|
||||
[Call](Event::EntityEvent::ActorChangeDimensionAfterEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(&ev.self(), ev.getFromDimensionId());
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
case doHash("onEntityChangeDim"): {
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ActorChangeDimensionAfterEvent,
|
||||
(Actor * mob, int fromDimId),
|
||||
(&ev.self(), ev.getFromDimensionId()),
|
||||
logger.error("Event \"onEntityChangeDim\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onDragonRespawn"): {
|
||||
auto Call = RemoteCall::importAs<bool(int64 enderDragonUniqueID)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::DragonRespawnBeforeEvent>(
|
||||
[Call](Event::EntityEvent::DragonRespawnBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call(ev.getEnderDragon().id);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::DragonRespawnBeforeEvent,
|
||||
(int64 enderDragonUniqueID),
|
||||
(ev.getEnderDragon().id),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onProjectileTryCreate"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateBeforeEvent>(
|
||||
[Call](Event::EntityEvent::ProjectileCreateBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||
result = Call(&ev.self(), uid);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ProjectileCreateBeforeEvent,
|
||||
(Actor * mob, int64 uniqueId),
|
||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onProjectileCreate"): {
|
||||
auto Call = RemoteCall::importAs<bool(Actor * mob, int64 uniqueId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::ProjectileCreateAfterEvent>(
|
||||
[Call](Event::EntityEvent::ProjectileCreateAfterEvent& ev) {
|
||||
try {
|
||||
auto uid = ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1;
|
||||
Call(&ev.self(), uid);
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::ProjectileCreateAfterEvent,
|
||||
(Actor * mob, int64 uniqueId),
|
||||
(&ev.self(), ev.getShooter() ? ev.getShooter()->getOrCreateUniqueID().id : -1),
|
||||
logger.error("Event \"onProjectileCreate\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onSpawnWanderingTrader"): {
|
||||
auto Call = RemoteCall::importAs<bool(std::pair<BlockPos, int> pos)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::EntityEvent::SpawnWanderingTraderBeforeEvent>(
|
||||
[Call](Event::EntityEvent::SpawnWanderingTraderBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
result = Call({ev.getPos(), ev.getRegion().getDimensionId()});
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::entity::SpawnWanderingTraderBeforeEvent,
|
||||
(std::pair<BlockPos, int> pos),
|
||||
({ev.getPos(), ev.getRegion().getDimensionId()}),
|
||||
ev.cancel(),
|
||||
)
|
||||
}
|
||||
case doHash("onHandleRequestAction"): {
|
||||
auto Call = RemoteCall::importAs<bool(
|
||||
// clang-format off
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::player::HandleRequestActionBeforeEvent,
|
||||
(
|
||||
Player * player,
|
||||
std::string const& actionType,
|
||||
int count,
|
||||
@@ -273,57 +208,38 @@ void Export_Event_API() {
|
||||
int sourceSlot,
|
||||
std::string const& destinationContainerNetId,
|
||||
int destinationSlot
|
||||
)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PlayerEvent::HandleRequestActionBeforeEvent>(
|
||||
[Call](Event::PlayerEvent::HandleRequestActionBeforeEvent& ev) {
|
||||
bool result = true;
|
||||
try {
|
||||
auto requestAction = (ItemStackRequestActionTransferBase*)&ev.getRequestAction();
|
||||
auto source = requestAction->getSrc();
|
||||
// TODO: The next version of LeviLamina changes to a member function
|
||||
auto destination = ll::memory::dAccess<ItemStackRequestSlotInfo>(requestAction, 56);
|
||||
result = Call(
|
||||
&ev.self(),
|
||||
magic_enum::enum_name(requestAction->mActionType).data(),
|
||||
ll::memory::dAccess<uchar>(requestAction, 18),
|
||||
magic_enum::enum_name(source.mOpenContainerNetId).data(),
|
||||
source.mSlot,
|
||||
magic_enum::enum_name(destination.mOpenContainerNetId).data(),
|
||||
destination.mSlot
|
||||
);
|
||||
} catch (...) {}
|
||||
if (!result) {
|
||||
ev.cancel();
|
||||
}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
),
|
||||
(
|
||||
(Player*)&ev.self(),
|
||||
magic_enum::enum_name(requestAction.mActionType).data(),
|
||||
(int)requestAction.mAmount,
|
||||
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"): {
|
||||
auto Call = RemoteCall::importAs<bool(Player * player, int ContainerNetId)>(eventName, eventId);
|
||||
eventBus->emplaceListener<Event::PacketEvent::ContainerClosePacketSendAfterEvent>(
|
||||
[Call](Event::PacketEvent::ContainerClosePacketSendAfterEvent& ev) {
|
||||
try {
|
||||
Call(
|
||||
ev.getServerNetworkHandler()
|
||||
REGISTER_EVENT_LISTEN(
|
||||
gmlib::event::packet::ContainerClosePacketSendAfterEvent,
|
||||
(Player * player, int ContainerNetId),
|
||||
(ev.getServerNetworkHandler()
|
||||
.getServerPlayer(ev.getNetworkIdentifier(), ev.getPacket().mClientSubId),
|
||||
(int)ev.getPacket().mContainerId
|
||||
);
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
(int)ev.getPacket().mContainerId),
|
||||
logger.error("Event \"onSendContainerClosePacket\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
case doHash("onServerStopping"): {
|
||||
auto Call = RemoteCall::importAs<bool()>(eventName, eventId);
|
||||
eventBus->emplaceListener<ll::event::server::ServerStoppingEvent>(
|
||||
[Call](ll::event::server::ServerStoppingEvent& ev) {
|
||||
try {
|
||||
Call();
|
||||
} catch (...) {}
|
||||
}
|
||||
);
|
||||
return true;
|
||||
REGISTER_EVENT_LISTEN(
|
||||
ll::event::server::ServerStoppingEvent,
|
||||
(),
|
||||
(),
|
||||
logger.error("Event \"onServerStopping\" cannot be intercepted"),
|
||||
)
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
#include "Global.h"
|
||||
|
||||
using namespace ll::hash_utils;
|
||||
|
||||
class LegacyScriptFormManager {
|
||||
private:
|
||||
int64 mNextFormCallbackId = 0;
|
||||
int64 mNextFormId = 0;
|
||||
std::unordered_map<int64, std::unique_ptr<gmlib::form::NpcDialogueForm>> mNpcDialogueForms;
|
||||
// std::unordered_map<int64, std::unique_ptr<ChestForm>> mChestForms;
|
||||
|
||||
public:
|
||||
// std::string getNextFormCallbackId() {
|
||||
// return "GMLIB_FormApi_" + std::to_string(mNextFormCallbackId++);
|
||||
// }
|
||||
|
||||
int64 getNextFormId() {
|
||||
mNextFormId++;
|
||||
return mNextFormId;
|
||||
}
|
||||
|
||||
int64 createNpcDialogueForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
||||
auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
||||
auto formPtr = std::make_unique<gmlib::form::NpcDialogueForm>(npcName, sceneName, dialogue);
|
||||
mNpcDialogueForms[formId] = std::move(formPtr);
|
||||
return formId;
|
||||
}
|
||||
|
||||
bool destroyNpcDialogueForm(int64 formId) {
|
||||
if (mNpcDialogueForms.contains(formId)) {
|
||||
mNpcDialogueForms.erase(formId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
optional_ref<gmlib::form::NpcDialogueForm> getNpcDialogueForm(int64 formId) {
|
||||
if (mNpcDialogueForms.contains(formId)) {
|
||||
return mNpcDialogueForms[formId].get();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/*
|
||||
int64 createChestForm(std::string const& npcName, std::string const& sceneName, std::string const& dialogue) {
|
||||
auto formId = LegacyScriptFormManager::getInstance().getNextFormId();
|
||||
auto formPtr = std::make_unique<ChestForm>(npcName, sceneName, dialogue);
|
||||
mChestForms[formId] = std::move(formPtr);
|
||||
return formId;
|
||||
}
|
||||
|
||||
bool destroyChestForm(int64 formId) {
|
||||
if (mChestForms.contains(formId)) {
|
||||
mChestForms.erase(formId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
optional_ref<ChestForm> getChestForm(int64 formId) {
|
||||
if (mChestForms.contains(formId)) {
|
||||
return mChestForms[formId].get();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
*/
|
||||
public:
|
||||
static LegacyScriptFormManager& getInstance() {
|
||||
static std::unique_ptr<LegacyScriptFormManager> instance;
|
||||
if (!instance) {
|
||||
instance = std::make_unique<LegacyScriptFormManager>();
|
||||
}
|
||||
return *instance;
|
||||
}
|
||||
};
|
||||
|
||||
#define PLAYER_DETECROR \
|
||||
[detectorId, result](::Player& pl) -> bool { \
|
||||
try { \
|
||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", detectorId)) { \
|
||||
auto const& detector = RemoteCall::importAs<bool(::Player*)>("GMLIB_FORM_CALLBACK", detectorId); \
|
||||
return detector(&pl); \
|
||||
} else { \
|
||||
gmlib::form::ServerSettingForm::removeElement(result); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define CALLBACK_TYPE(type) \
|
||||
[callbackId, result](Player& pl, type data) { \
|
||||
try { \
|
||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
auto const& callback = RemoteCall::importAs<void(Player*, type)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
callback(&pl, data); \
|
||||
} else { \
|
||||
gmlib::form::ServerSettingForm::removeElement(result); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
}
|
||||
|
||||
#define CALLBACK_TYPE_NORMAL \
|
||||
[callbackId](::Player& pl) { \
|
||||
try { \
|
||||
if (RemoteCall::hasFunc("GMLIB_FORM_CALLBACK", callbackId)) { \
|
||||
auto const& callback = RemoteCall::importAs<void(::Player*)>("GMLIB_FORM_CALLBACK", callbackId); \
|
||||
callback(&pl); \
|
||||
} \
|
||||
} catch (...) {} \
|
||||
}
|
||||
|
||||
|
||||
void Export_Form_API() {
|
||||
//////////////////////////////// Form Manager /////////////////////////////////
|
||||
// RemoteCall::exportAs("GMLIB_FormAPI", "getNextFormCallbackId", []() -> std::string {
|
||||
// return LegacyScriptFormManager::getInstance().getNextFormCallbackId();
|
||||
// });
|
||||
////////////////////////////// ServerSettingForm //////////////////////////////
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getDefaultPriority", []() -> int {
|
||||
return gmlib::form::ServerSettingForm::getDefaultPriority();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "hasTitle", []() -> bool { return gmlib::form::ServerSettingForm::hasTitle(); });
|
||||
RemoteCall::exportAs("GMLIB_ServerSettingForm", "getTitle", []() -> std::string {
|
||||
return gmlib::form::ServerSettingForm::getTitle();
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "setTitle", [](std::string const& title, bool forceModify) -> bool {
|
||||
return gmlib::form::ServerSettingForm::setTitle(title, forceModify);
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "hasIcon", []() -> bool { return gmlib::form::ServerSettingForm::hasIcon(); });
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconData", []() -> std::string {
|
||||
return gmlib::form::ServerSettingForm::getIconData().value_or("");
|
||||
});
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "getIconType", []() -> int {
|
||||
return gmlib::form::ServerSettingForm::getIconType()
|
||||
.transform([](gmlib::form::IconType&& type) -> int { return (int)type; })
|
||||
.value_or(-1);
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"setIcon",
|
||||
[](std::string const& title, uchar type, bool forceModify) -> bool {
|
||||
return gmlib::form::ServerSettingForm::setIcon(title, gmlib::form::IconType(type), forceModify);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addLabel",
|
||||
[](std::string const& text, std::string const& detectorId, int priority) -> uint {
|
||||
uint result = gmlib::form::ServerSettingForm::addLabel(text, PLAYER_DETECROR, priority);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addInput",
|
||||
[](std::string const& text,
|
||||
std::string const& placeholder,
|
||||
std::string const& defaultVal,
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = gmlib::form::ServerSettingForm::addInput(
|
||||
text,
|
||||
placeholder,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE(std::string const&),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addToggle",
|
||||
[](std::string const& text,
|
||||
bool defaultVal,
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = gmlib::form::ServerSettingForm::addToggle(text, defaultVal, CALLBACK_TYPE(bool), PLAYER_DETECROR, priority);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addDropdown",
|
||||
[](std::string const& text,
|
||||
std::vector<std::string> options,
|
||||
int64 defaultVal,
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = gmlib::form::ServerSettingForm::addDropdown(
|
||||
text,
|
||||
options,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE(int64),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addSlider",
|
||||
[](std::string const& text,
|
||||
double min,
|
||||
double max,
|
||||
double step,
|
||||
double defaultVal,
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = gmlib::form::ServerSettingForm::addSlider(
|
||||
text,
|
||||
min,
|
||||
max,
|
||||
step,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE(double),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_gmlib::form::ServerSettingForm",
|
||||
"addStepSlider",
|
||||
[](std::string const& text,
|
||||
std::vector<std::string> steps,
|
||||
int64 defaultVal,
|
||||
std::string const& callbackId,
|
||||
std::string const& detectorId,
|
||||
int priority) -> uint {
|
||||
uint result = gmlib::form::ServerSettingForm::addStepSlider(
|
||||
text,
|
||||
steps,
|
||||
defaultVal,
|
||||
CALLBACK_TYPE(int64),
|
||||
PLAYER_DETECROR,
|
||||
priority
|
||||
);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_gmlib::form::ServerSettingForm", "removeElement", [](uint id) -> bool {
|
||||
return gmlib::form::ServerSettingForm::removeElement(id);
|
||||
});
|
||||
////////////////////////////// NpcDialogueForm //////////////////////////////
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_NpcDialogueForm",
|
||||
"createForm",
|
||||
[](std::string const& npcName, std::string const& sceneName, std::string const& dialogue) -> int64 {
|
||||
return LegacyScriptFormManager::getInstance().createNpcDialogueForm(npcName, sceneName, dialogue);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_NpcDialogueForm", "destroyForm", [](int64 formId) -> bool {
|
||||
return LegacyScriptFormManager::getInstance().destroyNpcDialogueForm(formId);
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_NpcDialogueForm",
|
||||
"addButton",
|
||||
[](int64 formId, std::string const& button, std::string const& callbackId) -> void {
|
||||
if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||
formPtr->addButton(button, CALLBACK_TYPE_NORMAL);
|
||||
}
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLIB_NpcDialogueForm",
|
||||
"onPlayerClose",
|
||||
[](int64 formId, std::string const& callbackId) -> void {
|
||||
if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||
formPtr->onPlayerClose(CALLBACK_TYPE_NORMAL);
|
||||
}
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs("GMLIB_NpcDialogueForm", "sendTo", [](int64 formId, ::Player* pl) -> void {
|
||||
if (auto formPtr = LegacyScriptFormManager::getInstance().getNpcDialogueForm(formId)) {
|
||||
formPtr->sendTo(*pl);
|
||||
}
|
||||
});
|
||||
////////////////////////////// ChestForm //////////////////////////////
|
||||
}
|
||||
+5
-7
@@ -1,19 +1,15 @@
|
||||
#pragma once
|
||||
#include <include_all.h>
|
||||
#include <headers/include_all.h>
|
||||
|
||||
#include <RemoteCallAPI.h>
|
||||
|
||||
using namespace GMLIB;
|
||||
using namespace Server;
|
||||
using namespace Mod;
|
||||
|
||||
#define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA")
|
||||
|
||||
#define LIB_VERSION_MAJOR 0
|
||||
#define LIB_VERSION_MINOR 13
|
||||
#define LIB_VERSION_PATCH 2
|
||||
#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;
|
||||
|
||||
@@ -22,3 +18,5 @@ extern void Export_Legacy_GMLib_ServerAPI();
|
||||
extern void Export_Compatibility_API();
|
||||
extern void ExportPAPI();
|
||||
extern void Export_Event_API();
|
||||
extern void Export_BinaryStream_API();
|
||||
extern void Export_Form_API();
|
||||
|
||||
+66
-76
@@ -3,13 +3,8 @@
|
||||
std::unordered_set<std::string> HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"};
|
||||
|
||||
std::variant<std::string, std::vector<RecipeIngredient>> makeRecipeUnlockingKey(std::string const& key) {
|
||||
if (HardCodedKeys.count(key)) {
|
||||
return key;
|
||||
}
|
||||
std::vector<RecipeIngredient> result;
|
||||
auto item = RecipeIngredient(key, 0, 1);
|
||||
result.emplace_back(item);
|
||||
return result;
|
||||
if (HardCodedKeys.count(key)) return key;
|
||||
return std::vector<RecipeIngredient>({RecipeIngredient(key, 0, 1)});
|
||||
}
|
||||
|
||||
void Export_Legacy_GMLib_ModAPI() {
|
||||
@@ -22,18 +17,17 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& result,
|
||||
int count,
|
||||
std::string const& unlock) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
std::vector<RecipeIngredient> types;
|
||||
for (auto ing : ingredients) {
|
||||
auto key = RecipeIngredient(ing, 0, 1);
|
||||
types.push_back(key);
|
||||
types.emplace_back(ing, 0, 1);
|
||||
}
|
||||
auto res = RecipeIngredient(result, 0, count);
|
||||
auto unl = makeRecipeUnlockingKey(unlock);
|
||||
JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerShapelessCraftingTableRecipe(
|
||||
recipe_id,
|
||||
types,
|
||||
RecipeIngredient(result, 0, count),
|
||||
makeRecipeUnlockingKey(unlock)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -45,18 +39,18 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& result,
|
||||
int count,
|
||||
std::string const& unlock) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
std::vector<RecipeIngredient> types;
|
||||
for (auto ing : ingredients) {
|
||||
auto key = RecipeIngredient(ing, 0, 1);
|
||||
types.push_back(key);
|
||||
types.push_back(RecipeIngredient(ing, 0, 1));
|
||||
}
|
||||
auto res = RecipeIngredient(result, 0, count);
|
||||
auto unl = makeRecipeUnlockingKey(unlock);
|
||||
JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerShapedCraftingTableRecipe(
|
||||
recipe_id,
|
||||
shape,
|
||||
types,
|
||||
RecipeIngredient(result, 0, count),
|
||||
makeRecipeUnlockingKey(unlock)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -66,13 +60,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& input,
|
||||
std::string const& output,
|
||||
std::vector<std::string> tags) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerFurnaceRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1),
|
||||
tags
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -80,12 +74,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"registerBrewingMixRecipe",
|
||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||
) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingMixRecipe(
|
||||
recipe_id,
|
||||
input,
|
||||
output,
|
||||
RecipeIngredient(reagent, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -93,14 +88,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
"registerBrewingContainerRecipe",
|
||||
[](std::string const& recipe_id, std::string const& input, std::string const& output, std::string const& reagent
|
||||
) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
auto rea = RecipeIngredient(reagent, 0, 1);
|
||||
JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerBrewingContainerRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1),
|
||||
RecipeIngredient(reagent, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -111,11 +105,8 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& base,
|
||||
std::string const& addition,
|
||||
std::string const& result) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
JsonRecipe::registerSmithingTransformRecipe(
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTransformRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
base,
|
||||
@@ -131,11 +122,13 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& smithing_template,
|
||||
std::string const& base,
|
||||
std::string const& addition) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerSmithingTrimRecipe(
|
||||
recipe_id,
|
||||
smithing_template,
|
||||
base,
|
||||
addition
|
||||
);
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
@@ -147,52 +140,49 @@ void Export_Legacy_GMLib_ModAPI() {
|
||||
std::string const& output,
|
||||
int output_data,
|
||||
int output_count) -> void {
|
||||
auto level = GMLIB_Level::getInstance();
|
||||
if (!level) {
|
||||
return;
|
||||
}
|
||||
auto inp = RecipeIngredient(input, 0, 1);
|
||||
auto outp = RecipeIngredient(output, 0, 1);
|
||||
JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
|
||||
if (!gmlib::world::Level::getInstance().has_value()) return;
|
||||
gmlib::mod::recipe::JsonRecipeRegistry::registerStoneCutterRecipe(
|
||||
recipe_id,
|
||||
RecipeIngredient(input, 0, 1),
|
||||
RecipeIngredient(output, 0, 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
// 错误方块清理
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setUnknownBlockCleaner", []() -> void {
|
||||
VanillaFix::setAutoCleanUnknownBlockEnabled();
|
||||
gmlib::tools::VanillaFix::setAutoCleanUnknownBlockEnabled();
|
||||
});
|
||||
// 实验性
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "registerExperimentsRequire", [](int experiment_id) -> void {
|
||||
auto list = GMLIB_Level::getAllExperiments();
|
||||
auto list = gmlib::world::Level::getAllExperiments();
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
GMLIB_Level::addExperimentsRequire((AllExperiments)experiment_id);
|
||||
gmlib::world::Level::addExperimentsRequire((AllExperiments)experiment_id);
|
||||
} else {
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
|
||||
if (GMLIB_Level::getInstance()) {
|
||||
auto list = GMLIB_Level::getAllExperiments();
|
||||
if (gmlib::world::Level::getInstance()) {
|
||||
auto list = gmlib::world::Level::getAllExperiments();
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
GMLIB_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);
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
|
||||
if (GMLIB_Level::getInstance()) {
|
||||
auto list = GMLIB_Level::getAllExperiments();
|
||||
if (gmlib::world::Level::getInstance()) {
|
||||
auto list = gmlib::world::Level::getAllExperiments();
|
||||
std::unordered_set<AllExperiments> set(list.begin(), list.end());
|
||||
if (set.contains((AllExperiments)experiment_id)) {
|
||||
return GMLIB_Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
} else {
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
return false;
|
||||
return gmlib::world::Level::getInstance()->getExperimentEnabled(((AllExperiments)experiment_id));
|
||||
}
|
||||
ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ModAPI", "setFixI18nEnabled", []() -> void {
|
||||
VanillaFix::setFixI18nEnabled();
|
||||
gmlib::tools::VanillaFix::setFixI18nEnabled();
|
||||
});
|
||||
}
|
||||
+24
-25
@@ -2,50 +2,50 @@
|
||||
|
||||
void Export_Legacy_GMLib_ServerAPI() {
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
|
||||
GMLIB_Level::tryEnableEducationEdition();
|
||||
gmlib::world::Level::tryEnableEducationEdition();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
|
||||
GMLIB_Level::tryRegisterAbilityCommand();
|
||||
gmlib::world::Level::tryRegisterAbilityCommand();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
|
||||
GMLIB_Level::setForceAchievementsEnabled();
|
||||
gmlib::world::Level::setForceAchievementsEnabled();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void {
|
||||
gmlib::world::Level::trustAllSkins();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::trustAllSkins(); });
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void {
|
||||
GMLIB_Level::requireServerResourcePackAndAllowClientResourcePack();
|
||||
gmlib::world::Level::requireServerResourcePackAndAllowClientResourcePack();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string {
|
||||
if (auto level = GMLIB_Level::getInstance()) {
|
||||
return level->getLevelName();
|
||||
}
|
||||
return {};
|
||||
return gmlib::world::Level::getInstance()
|
||||
.transform([](gmlib::world::Level& level) -> std::string { return level.getLevelName(); })
|
||||
.value_or("");
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string const& name) -> void {
|
||||
if (auto level = GMLIB_Level::getInstance()) {
|
||||
if (auto level = gmlib::world::Level::getInstance()) {
|
||||
level->setLevelName(name);
|
||||
}
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelSeed", []() -> std::string {
|
||||
if (auto level = GMLIB_Level::getInstance()) {
|
||||
return std::to_string(level->getSeed());
|
||||
}
|
||||
return {};
|
||||
return gmlib::world::Level::getInstance()
|
||||
.transform([](gmlib::world::Level& level) -> std::string { return std::to_string(level.getSeed()); })
|
||||
.value_or("");
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
|
||||
return GMLIB_Level::setFakeSeed(seed);
|
||||
return gmlib::world::Level::setFakeSeed(seed);
|
||||
});
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"spawnEntity",
|
||||
[](std::pair<Vec3, int> pos, std::string const& name) -> Actor* {
|
||||
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
||||
return gmlib::world::Spawner::spawnEntity(pos.first, pos.second, name).as_ptr();
|
||||
}
|
||||
);
|
||||
RemoteCall::exportAs(
|
||||
"GMLib_ServerAPI",
|
||||
"shootProjectile",
|
||||
[](Actor* owner, std::string const& name, float speed, float offset) -> Actor* {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
auto ac = (gmlib::world::Actor*)owner;
|
||||
return ac->shootProjectile(name, speed, offset).as_ptr();
|
||||
}
|
||||
);
|
||||
@@ -53,7 +53,7 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
"GMLib_ServerAPI",
|
||||
"throwEntity",
|
||||
[](Actor* owner, Actor* actor, float speed, float offset) -> bool {
|
||||
auto ac = (GMLIB_Actor*)owner;
|
||||
auto ac = (gmlib::world::Actor*)owner;
|
||||
return ac->throwEntity(*actor, speed, offset);
|
||||
}
|
||||
);
|
||||
@@ -62,19 +62,18 @@ void Export_Legacy_GMLib_ServerAPI() {
|
||||
"GMLib_ServerAPI",
|
||||
"addFakeList",
|
||||
[](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 {
|
||||
return FakeList::removeFakeList(nameOrXuid);
|
||||
return gmlib::tools::FakeList::removeFakeList(nameOrXuid);
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "removeAllFakeList", []() -> void {
|
||||
return FakeList::removeAllFakeLists();
|
||||
return gmlib::tools::FakeList::removeAllFakeLists();
|
||||
});
|
||||
RemoteCall::exportAs("GMLib_ServerAPI", "getMaxPlayers", []() -> int {
|
||||
if (auto level = GMLIB_Level::getInstance()) {
|
||||
return level->getMaxPlayerCount();
|
||||
}
|
||||
return {};
|
||||
return gmlib::world::Level::getInstance()
|
||||
.transform([](gmlib::world::Level& level) -> int { return level.getMaxPlayerCount(); })
|
||||
.value_or(0);
|
||||
});
|
||||
}
|
||||
|
||||
+16
-16
@@ -13,10 +13,10 @@ bool isParameters(std::string const& str) {
|
||||
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& a1, std::string const& a2) {
|
||||
return PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
|
||||
std::string GetValueWithPlayer(std::string const& key, Player* player) {
|
||||
return gmlib::tools::PlaceholderAPI::getValue(key, player);
|
||||
}
|
||||
|
||||
bool registerPlayerPlaceholder(
|
||||
@@ -25,20 +25,20 @@ bool registerPlayerPlaceholder(
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl, std::unordered_map<std::string, std::string>)>(
|
||||
PluginName,
|
||||
FuncName
|
||||
);
|
||||
PlaceholderAPI::registerPlayerPlaceholder(
|
||||
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp, std::unordered_map<std::string, std::string> map) { return Call(sp, map); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
|
||||
PlaceholderAPI::registerPlayerPlaceholder(
|
||||
gmlib::tools::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp) { return Call(sp); },
|
||||
PluginName
|
||||
@@ -55,18 +55,18 @@ bool registerServerPlaceholder(
|
||||
std::string const& PAPIName
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call =
|
||||
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
||||
PlaceholderAPI::registerServerPlaceholder(
|
||||
gmlib::tools::PlaceholderAPI::registerServerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
@@ -80,17 +80,17 @@ bool registerStaticPlaceholder(
|
||||
int num
|
||||
) {
|
||||
if (RemoteCall::hasFunc(PluginName, FuncName)) {
|
||||
PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
gmlib::tools::PlaceholderAPI::unregisterPlaceholder(PAPIName);
|
||||
if (isParameters(PAPIName)) {
|
||||
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
|
||||
if (num == -1) {
|
||||
PlaceholderAPI::registerStaticPlaceholder(
|
||||
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
[Call] { return Call(); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
PlaceholderAPI::registerStaticPlaceholder(
|
||||
gmlib::tools::PlaceholderAPI::registerStaticPlaceholder(
|
||||
PAPIName,
|
||||
num,
|
||||
[Call] { return Call(); },
|
||||
@@ -104,14 +104,14 @@ bool registerStaticPlaceholder(
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"format_version": 2,
|
||||
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
|
||||
"version": "0.13.2",
|
||||
"version": "0.13.3",
|
||||
"info": {
|
||||
"name": "GMLIB-LegacyRemoteCallApi",
|
||||
"description": "Legacy RemoteCall API for GMLIB",
|
||||
@@ -14,7 +14,7 @@
|
||||
"library"
|
||||
]
|
||||
},
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.13.2/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.13.3/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
|
||||
"dependencies": {
|
||||
"github.com/GroupMountain/GMLIB": ">=0.13.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user