From b683b5d40ca1135842efff90ec296f9ead54a131 Mon Sep 17 00:00:00 2001 From: radmanplays <95340057+radmanplays@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:54:26 +0330 Subject: [PATCH 1/7] Update npcspawner.js --- examplemods/npcspawner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examplemods/npcspawner.js b/examplemods/npcspawner.js index e2f1718..f72b41a 100644 --- a/examplemods/npcspawner.js +++ b/examplemods/npcspawner.js @@ -9,7 +9,7 @@ // Create a fake player GameProfile const GameProfileClass = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.v1_8.mojang.authlib.GameProfile"); - const fakeProfile = GameProfileClass.constructors[2](null, ModAPI.util.str("Steve")); + const fakeProfile = GameProfileClass.constructors[1](null, ModAPI.util.str("Steve")); // Get the EntityPlayerMP class to spawn the fake player const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP"); From 2adc025d3a725c26445535116648fa668ff84993 Mon Sep 17 00:00:00 2001 From: radmanplays <95340057+radmanplays@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:14:47 +0330 Subject: [PATCH 2/7] Update npcspawner.js --- examplemods/npcspawner.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examplemods/npcspawner.js b/examplemods/npcspawner.js index f72b41a..7256c5a 100644 --- a/examplemods/npcspawner.js +++ b/examplemods/npcspawner.js @@ -11,10 +11,14 @@ const GameProfileClass = ModAPI.reflect.getClassById("net.lax1dude.eaglercraft.v1_8.mojang.authlib.GameProfile"); const fakeProfile = GameProfileClass.constructors[1](null, ModAPI.util.str("Steve")); + // Get the PlayerInteractionManager class + const PlayerInteractionManagerClass = ModAPI.reflect.getClassById("net.minecraft.server.management.PlayerInteractionManager"); + const playerInteractionManager = PlayerInteractionManagerClass.constructors[1](world.getRef()); + // Get the EntityPlayerMP class to spawn the fake player const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP"); const fakePlayer = EntityPlayerMPClass.constructors[1]( - world.getMinecraftServer(), world.getRef(), fakeProfile, world.getPlayerInteractionManager() + world.getMinecraftServer(), world.getRef(), fakeProfile, playerInteractionManager ); // Set the fake player position to be near the command sender From 7c1747369b050c30a9f07b48ff7a5621c6f3afd7 Mon Sep 17 00:00:00 2001 From: radmanplays <95340057+radmanplays@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:23:04 +0330 Subject: [PATCH 3/7] Update npcspawner.js --- examplemods/npcspawner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examplemods/npcspawner.js b/examplemods/npcspawner.js index 7256c5a..2b67b65 100644 --- a/examplemods/npcspawner.js +++ b/examplemods/npcspawner.js @@ -13,11 +13,11 @@ // Get the PlayerInteractionManager class const PlayerInteractionManagerClass = ModAPI.reflect.getClassById("net.minecraft.server.management.PlayerInteractionManager"); - const playerInteractionManager = PlayerInteractionManagerClass.constructors[1](world.getRef()); + const playerInteractionManager = PlayerInteractionManagerClass.constructors[0](world.getRef()); // Get the EntityPlayerMP class to spawn the fake player const EntityPlayerMPClass = ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP"); - const fakePlayer = EntityPlayerMPClass.constructors[1]( + const fakePlayer = EntityPlayerMPClass.constructors[0]( world.getMinecraftServer(), world.getRef(), fakeProfile, playerInteractionManager ); From 6dd4f62bc9913a7b4a37d3c86e5eeedd0bf61e88 Mon Sep 17 00:00:00 2001 From: radmanplays <95340057+radmanplays@users.noreply.github.com> Date: Thu, 19 Sep 2024 23:36:21 +0330 Subject: [PATCH 4/7] Update npcspawner.js --- examplemods/npcspawner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examplemods/npcspawner.js b/examplemods/npcspawner.js index 2b67b65..d0afafc 100644 --- a/examplemods/npcspawner.js +++ b/examplemods/npcspawner.js @@ -12,7 +12,7 @@ const fakeProfile = GameProfileClass.constructors[1](null, ModAPI.util.str("Steve")); // Get the PlayerInteractionManager class - const PlayerInteractionManagerClass = ModAPI.reflect.getClassById("net.minecraft.server.management.PlayerInteractionManager"); + const PlayerInteractionManagerClass = ModAPI.reflect.getClassById("net.minecraft.server.management.ItemInWorldManager"); const playerInteractionManager = PlayerInteractionManagerClass.constructors[0](world.getRef()); // Get the EntityPlayerMP class to spawn the fake player From 3cb01c5a5e4d8c5af677ce083091c70f9478c5a7 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Fri, 20 Sep 2024 19:00:35 +0800 Subject: [PATCH 5/7] Cool fixes --- modgui.injector.js | 3 +++ modgui.js | 4 ++++ postinit.injector.js | 28 ++++++++++++++++++++++++++++ postinit.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/modgui.injector.js b/modgui.injector.js index 2c5a49a..dd2af4f 100644 --- a/modgui.injector.js +++ b/modgui.injector.js @@ -173,8 +173,11 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays return; } if (document.querySelector("#modapi_gui_container")) { + cb ||= document.querySelector("#modapi_gui_container")._cb; document.querySelector("#modapi_gui_container").remove(); } + + document.querySelector("#modapi_gui_container")._cb = cb; var element = document.createElement("div"); element.innerHTML = gui.replace("{splash_msg}", splashes[Math.floor(Math.random() * splashes.length)]); diff --git a/modgui.js b/modgui.js index 2b4ef23..0d4c5c0 100644 --- a/modgui.js +++ b/modgui.js @@ -173,8 +173,12 @@ return; } if (document.querySelector("#modapi_gui_container")) { + cb ||= document.querySelector("#modapi_gui_container")._cb; document.querySelector("#modapi_gui_container").remove(); } + + document.querySelector("#modapi_gui_container")._cb = cb; + var element = document.createElement("div"); element.innerHTML = gui.replace("{splash_msg}", splashes[Math.floor(Math.random() * splashes.length)]); diff --git a/postinit.injector.js b/postinit.injector.js index b4e8278..3813b68 100644 --- a/postinit.injector.js +++ b/postinit.injector.js @@ -741,6 +741,34 @@ globalThis.modapi_postinit = `(() => { ModAPI.materials = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.block.material.Material")].staticVariables, StaticProps_ProxyConf); ModAPI.enchantments = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.enchantment.Enchantment")].staticVariables, StaticProps_ProxyConf); + const originalOptionsInit = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")] = function (...args) { + var x = originalOptionsInit.apply(this, args); + + //NOT A BUG DO NOT FIX + var msg = Math.random() < 0.025 ? "Plugins" : "Mods"; + + // Find the right constructor. (int id, int x, int y, int width, int height, String buttonText); + var btnConstructor = ModAPI.hooks._classMap['nmcg_GuiButton'].constructors.filter(c => { return c.length === 6 })[0]; + var btn = btnConstructor(9635329, 0, args[0].$height8 - 21, 100, 20, ModAPI.util.str(msg)); + args[0].$buttonList.$add(btn); + + return x; + } + + const originalOptionsAction = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")] = function (...args) { + if (args[1] && args[1].$id12 === 9635329) { + if (typeof window.modapi_displayModGui === "function") { + window.modapi_displayModGui(); + } else { + alert("[ModAPI] Mod Manager GUI does not exist!") + } + } + var x = originalOptionsAction.apply(this, args); + return x; + } + const originalCrashMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")]; ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")] = function (...args) { if (window.confirm("Your game has crashed, do you want to open the mod manager gui?")) { diff --git a/postinit.js b/postinit.js index c4f04d1..ab6190a 100644 --- a/postinit.js +++ b/postinit.js @@ -741,6 +741,34 @@ ModAPI.materials = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.block.material.Material")].staticVariables, StaticProps_ProxyConf); ModAPI.enchantments = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.enchantment.Enchantment")].staticVariables, StaticProps_ProxyConf); + const originalOptionsInit = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")] = function (...args) { + var x = originalOptionsInit.apply(this, args); + + //NOT A BUG DO NOT FIX + var msg = Math.random() < 0.025 ? "Plugins" : "Mods"; + + // Find the right constructor. (int id, int x, int y, int width, int height, String buttonText); + var btnConstructor = ModAPI.hooks._classMap['nmcg_GuiButton'].constructors.filter(c => { return c.length === 6 })[0]; + var btn = btnConstructor(9635329, 0, args[0].$height8 - 21, 100, 20, ModAPI.util.str(msg)); + args[0].$buttonList.$add(btn); + + return x; + } + + const originalOptionsAction = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")] = function (...args) { + if (args[1] && args[1].$id12 === 9635329) { + if (typeof window.modapi_displayModGui === "function") { + window.modapi_displayModGui(); + } else { + alert("[ModAPI] Mod Manager GUI does not exist!") + } + } + var x = originalOptionsAction.apply(this, args); + return x; + } + const originalCrashMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")]; ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")] = function (...args) { if (window.confirm("Your game has crashed, do you want to open the mod manager gui?")) { From 841e056606e57c4fa90a1c0cab9ba7a6c9d19617 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sat, 21 Sep 2024 11:40:06 +0800 Subject: [PATCH 6/7] Documentation Notice --- docs/apidoc/index.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/apidoc/index.md b/docs/apidoc/index.md index b9d391e..5336311 100644 --- a/docs/apidoc/index.md +++ b/docs/apidoc/index.md @@ -1,6 +1,17 @@ # EaglerForge ModAPI Documentation The EaglerForge ModAPI is housed in a global JavaScript object stored on `globalThis`, called `ModAPI` or `PluginAPI`. (both are identical) +### Important Notice! +From people used to the doc prior to EaglerForgeInjector, now, when you see something like `ModAPI.world`'s type is `World`, that literally means it is identical to an instance of `net.minecraft.world.World` from java. For easier modding, here are some online javadocs, that explain properties from each individual method and proerty of every 1.8 class: + +https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/overview-summary.html - Javadoc for vanilla 1.8 +https://eaglerreborn.github.io/javadoc/ - EaglerReborn (EF precursor) javadoc, for EaglercraftX u17 (missing serverside classes, this version didn't have singleplayer) +An up-to-date javadoc for EaglercraftX is coming soon, in the meanwhile, I recommend modding with a local EaglercraftX workspace, so you can inspect the contents of each class. + +Additionally, when you se that something like `ModAPI.mcinstance` is `Raw` this means that it has a lot of TeaVM nonsense like '$' prefixes before everything, as well has making it difficult to call the objects methods. + +### Global ModAPI Object: + The global object has the following properties: - `ModAPI.player: EntityPlayerSP` - Only accessible after `ModAPI.require("player")` is called, this is the local player entity. It is regenerated every time the `update` event is called. From 45283aa7690aea691b56afc4d6f928cbdbf30743 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sat, 21 Sep 2024 11:42:09 +0800 Subject: [PATCH 7/7] Patchfix --- modgui.injector.js | 3 ++- modgui.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modgui.injector.js b/modgui.injector.js index dd2af4f..4e466e8 100644 --- a/modgui.injector.js +++ b/modgui.injector.js @@ -177,13 +177,14 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays document.querySelector("#modapi_gui_container").remove(); } - document.querySelector("#modapi_gui_container")._cb = cb; var element = document.createElement("div"); element.innerHTML = gui.replace("{splash_msg}", splashes[Math.floor(Math.random() * splashes.length)]); document.body.appendChild(element); + document.querySelector("#modapi_gui_container")._cb = cb; + var modsList = await getMods(); var tbody = document.querySelector("#modapi_gui_container .modTable tbody"); tbody.innerHTML = ""; diff --git a/modgui.js b/modgui.js index 0d4c5c0..c6fb267 100644 --- a/modgui.js +++ b/modgui.js @@ -176,8 +176,6 @@ cb ||= document.querySelector("#modapi_gui_container")._cb; document.querySelector("#modapi_gui_container").remove(); } - - document.querySelector("#modapi_gui_container")._cb = cb; var element = document.createElement("div"); @@ -185,6 +183,8 @@ document.body.appendChild(element); + document.querySelector("#modapi_gui_container")._cb = cb; + var modsList = await getMods(); var tbody = document.querySelector("#modapi_gui_container .modTable tbody"); tbody.innerHTML = "";