diff --git a/docs/apidoc/events.md b/docs/apidoc/events.md index a976db0..32bd6ee 100644 --- a/docs/apidoc/events.md +++ b/docs/apidoc/events.md @@ -39,7 +39,9 @@ Events broadcast data for use in mods. - String representing the type of event being fired. - `data: Object` - Object representing the original arguments to be passed to the callback. - +- `frame`: + - Called just when a frame is rendered on the client. + - Event object is blank. ### Server Side Events Can only be used in the context of the dedicated server. More: [DedicatedServerDocumentation](dedicatedserver.md) - `serverstart`: diff --git a/docs/apidoc/index.md b/docs/apidoc/index.md index b1d1166..b9d391e 100644 --- a/docs/apidoc/index.md +++ b/docs/apidoc/index.md @@ -59,6 +59,10 @@ The global object has the following properties: - `ModAPI.array` - This object is used to interact and create arrays easily. - More: [ArrayDocumentation](array.md) +- `ModAPI.resolution` + - This object is used to query information about GUI dimensions, to make drawing to the screen easier, generated when the `frame` event is fired. + - Deprecated alias (please do not use): `ModAPI.ScaledResolution` + - More: [ArrayDocumentation](array.md) - `ModAPI.version: String` - The version of ModAPI. - `ModAPI.flavour: String` diff --git a/examplemods/lib.customitems.js b/examplemods/lib.customitems.js index ea8bec1..40a0280 100644 --- a/examplemods/lib.customitems.js +++ b/examplemods/lib.customitems.js @@ -6,11 +6,12 @@ ModAPI.meta.description("Library to make adding basic custom items easier."); ModAPI.events.newEvent("lib:libcustomitems:loaded"); function libServerside() { - var packetblockchange = ModAPI.reflect.getClassByName("S23PacketBlockChange").constructors.find(x => {return x.length === 2}); + var packetblockchange = ModAPI.reflect.getClassByName("S23PacketBlockChange").constructors.find(x => { return x.length === 2 }); var sendPacket = ModAPI.reflect.getClassByName("NetHandlerPlayServer").methods.sendPacket.method; globalThis.LCI_REGISTRY ||= []; globalThis.LCI_RMBEVENTS ||= {}; globalThis.LCI_LMBEVENTS ||= {}; + globalThis.LCI_RECIPEEVENTS ||= {}; var useName = ModAPI.util.getMethodFromPackage("net.minecraft.network.NetHandlerPlayServer", "processPlayerBlockPlacement"); var oldUse = ModAPI.hooks.methods[useName]; ModAPI.hooks.methods[useName] = function ($this, packet) { @@ -61,15 +62,15 @@ var statusTag = Object.keys(packet.$status).find(x => { return x.startsWith("$name") }); var positionTag = Object.keys(packet).filter(x => { return x.startsWith("$position") })[0]; var stat = ModAPI.util.unstr(packet.$status[statusTag]); - if (stat === "START_DESTROY_BLOCK") { + if (stat === "START_DESTROY_BLOCK") { + sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag])); + } + if (stat !== "START_DESTROY_BLOCK") { + if (stat === "STOP_DESTROY_BLOCK") { sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag])); } - if (stat !== "START_DESTROY_BLOCK") { - if (stat === "STOP_DESTROY_BLOCK") { - sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag])); - } - return 0; - } + return 0; + } var r = globalThis.LCI_LMBEVENTS[cid].call(globalThis, new Proxy($this.$playerEntity, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf), @@ -91,6 +92,7 @@ globalThis.LCI_REGISTRY ||= []; globalThis.LCI_RMBEVENTS ||= {}; globalThis.LCI_LMBEVENTS ||= {}; + globalThis.LCI_RECIPEEVENTS ||= {}; globalThis.LCI_REGISTRY.push(data.tag); if (data.onRightClickGround) { globalThis.LCI_RMBEVENTS[data.tag] = new Function("user", "world", "itemstack", "blockpos", data.onRightClickGround); @@ -98,6 +100,9 @@ if (data.onLeftClickGround) { globalThis.LCI_LMBEVENTS[data.tag] = new Function("user", "world", "itemstack", "blockpos", data.onLeftClickGround); } + if (data.craftingExtra) { + globalThis.LCI_RECIPEEVENTS[data.tag] = new Function("itemstack", data.craftingExtra); + } var ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class; function ToChar(char) { return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0)); @@ -132,6 +137,9 @@ var lore = ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagList").constructors[0](); lore.$appendTag(ModAPI.reflect.getClassById("net.minecraft.nbt.NBTTagString").constructors.filter(x => { return x.length === 1 })[0](ModAPI.util.str(data.tag))); displayTag.$setTag(ModAPI.util.str("Lore"), lore); + if (globalThis.LCI_RECIPEEVENTS[data.tag]) { + globalThis.LCI_RECIPEEVENTS[data.tag](new Proxy(testItem, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf)); + } var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method(); ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, testItem, recipe); diff --git a/postinit.injector.js b/postinit.injector.js index 223c4af..87b606d 100644 --- a/postinit.injector.js +++ b/postinit.injector.js @@ -648,6 +648,18 @@ globalThis.modapi_postinit = `(() => { return sendChatMessage.apply(this, [$this, $message]); } + const ScaledResolutionConstructor = ModAPI.reflect.getClassByName("ScaledResolution").constructors[0]; + ModAPI.events.newEvent("frame", "client"); + const frameMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "runTick"); + const frameMethod = ModAPI.hooks.methods[frameMethodName]; + ModAPI.hooks.methods[frameMethodName] = function (...args) { + ModAPI.events.callEvent("frame", {}); + if (ModAPI.required.has("resolution") && ModAPI.mcinstance) { + ModAPI.ScaledResolution = ModAPI.resolution = new Proxy(ScaledResolutionConstructor(ModAPI.mcinstance), TeaVM_to_Recursive_BaseData_ProxyConf); + } + return frameMethod.apply(this, args); + } + ModAPI.events.newEvent("tick", "server"); const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick"); const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName]; diff --git a/postinit.js b/postinit.js index d4ec002..c1e2b2c 100644 --- a/postinit.js +++ b/postinit.js @@ -648,6 +648,18 @@ return sendChatMessage.apply(this, [$this, $message]); } + const ScaledResolutionConstructor = ModAPI.reflect.getClassByName("ScaledResolution").constructors[0]; + ModAPI.events.newEvent("frame", "client"); + const frameMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "runTick"); + const frameMethod = ModAPI.hooks.methods[frameMethodName]; + ModAPI.hooks.methods[frameMethodName] = function (...args) { + ModAPI.events.callEvent("frame", {}); + if (ModAPI.required.has("resolution") && ModAPI.mcinstance) { + ModAPI.ScaledResolution = ModAPI.resolution = new Proxy(ScaledResolutionConstructor(ModAPI.mcinstance), TeaVM_to_Recursive_BaseData_ProxyConf); + } + return frameMethod.apply(this, args); + } + ModAPI.events.newEvent("tick", "server"); const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick"); const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName];