From 5c4d4a3803a3fde1917c4630cd3d515f67d56b5b Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Tue, 6 May 2025 19:03:25 +0800 Subject: [PATCH] v2.7.9 --- core/core.js | 3 ++- core/postinit.js | 21 ++++++++++++++++++++- examplemods/veinminer.js | 22 +++++++++++++--------- package.json | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/core/core.js b/core/core.js index dd95f40..6529acf 100644 --- a/core/core.js +++ b/core/core.js @@ -14,7 +14,7 @@ var modapi_preinit = `globalThis.ModAPI ||= {}; `; var freezeCallstack = `if(ModAPI.hooks.freezeCallstack){return false};`; const EFIConfig = { - ModAPIVersion: "v2.7.8", //also change in package.json + ModAPIVersion: "v2.7.9", //also change in package.json doEaglerforge: true, verbose: false, doServerExtras: false, @@ -128,6 +128,7 @@ async function processClasses(string, parser) { assets.modapi_modloader = modapi_modloader; assets.modapi_guikit = modapi_guikit; } + _status("Running EaglerForgeInjector " + EFIConfig.ModAPIVersion); if (string.includes("__eaglerforgeinjector_installation_flag__")) { backgroundLog("Detected input containing EFI installation flag.", true); return alert("this file already has EaglerForge injected in it, you nonce.\nif you're trying to update, you need a vanilla file.") diff --git a/core/postinit.js b/core/postinit.js index 04a9ddc..bee8371 100644 --- a/core/postinit.js +++ b/core/postinit.js @@ -246,7 +246,6 @@ const modapi_postinit = "(" + (() => { } ModAPI.util.asClass = ModAPI.hooks._teavm.$rt_cls; - ModAPI.util.wrap = function (outputValue, target, corrective, disableFunctions) { target ||= {}; corrective ||= false; @@ -259,6 +258,16 @@ const modapi_postinit = "(" + (() => { } return new Proxy(outputValue.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf); } + if (ModAPI.is_1_12 && outputValue && typeof outputValue === "object" && outputValue.constructor === NonNullList) { //1.12 NonNullList support + const targetProperty = Object.values(outputValue)?.find(x => x && typeof x === "object" && x.constructor === ArrayAsList); + if (targetProperty) { + const arrayProp = Object.values(targetProperty).find(x => x && typeof x === "object" && Array.isArray(x.data) && typeof x.type === "function"); + if (corrective) { + return new Proxy(arrayProp.data, CorrectiveArray); + } + return new Proxy(arrayProp.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf); + } + } if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) { if (corrective) { return new Proxy(outputValue, CorrectiveRecursive); @@ -643,6 +652,7 @@ const modapi_postinit = "(" + (() => { get(target, prop, receiver) { var outProp = prop; var outputValue = Reflect.get(target, outProp, receiver); + outputValue ||= Reflect.get(target, outProp.toUpperCase(), receiver); //1.12 made a lot of variables uppercase (idk why) if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") { return new Proxy(outputValue.data, TeaVMArray_To_Recursive_BaseData_ProxyConf); } @@ -799,6 +809,9 @@ const modapi_postinit = "(" + (() => { //Function used for running @Async / @Async-dependent TeaVM methods. ModAPI.promisify = function promisify(fn) { + if (typeof fn !== "function") { + console.error("[ModAPI.promisify] Input was not a function: ", fn); + } return function promisifiedJavaMethod(...inArguments) { return new Promise((res, rej) => { Promise.resolve().then( //queue microtask @@ -1173,6 +1186,12 @@ const modapi_postinit = "(" + (() => { ModAPI.util.getBlockById = easyStaticMethod("net.minecraft.block.Block", "getBlockById", false); ModAPI.util.getBlockFromItem = easyStaticMethod("net.minecraft.block.Block", "getBlockFromItem", true); ModAPI.util.getIdFromBlock = easyStaticMethod("net.minecraft.block.Block", "getIdFromBlock", true); + + // 1.12 utility junk + if (ModAPI.is_1_12) { + var NonNullList = ModAPI.reflect.getClassById("net.minecraft.util.NonNullList").class; + var ArrayAsList = ModAPI.reflect.getClassById("java.util.Arrays$ArrayAsList").class; + } function qhash(txt, arr, interval) { // var interval = 4095; //used to be 4095 - arr.length, but that increases incompatibility based on load order and other circumstances diff --git a/examplemods/veinminer.js b/examplemods/veinminer.js index 408f953..5512e91 100644 --- a/examplemods/veinminer.js +++ b/examplemods/veinminer.js @@ -14,7 +14,7 @@ } catch (error) { //swallow } - ModAPI.meta.config(()=>{ + ModAPI.meta.config(() => { var conf = document.createElement("div"); conf.innerHTML = `

Vein Miner Settings [X]

@@ -25,7 +25,7 @@
`; conf.style = "position: fixed; background-color: white; color: black; width: 100vw; height: 100vh; z-index: 256;top:0;left:0;"; - conf.__save = ()=>localStorage.setItem("trc_mod::conf", JSON.stringify(VEINMINERCONF)); + conf.__save = () => localStorage.setItem("trc_mod::conf", JSON.stringify(VEINMINERCONF)); document.body.appendChild(conf); }); @@ -33,6 +33,8 @@ ModAPI.dedicatedServer.appendCode(function () { ModAPI.addEventListener("bootstrap", () => { + const axes = [ModAPI.items.iron_axe, ModAPI.items.stone_axe, ModAPI.items.golden_axe, ModAPI.items.wooden_axe, ModAPI.items.diamond_axe].map(x => x.getRef()); + const logs = ["log", "log2"].map(x => ModAPI.blocks[x].getRef()); const targettedBlockIds = []; if (VEINMINERCONF.doLogs) { targettedBlockIds.push("log", "log2"); @@ -110,21 +112,23 @@ valid_log_blocks.forEach(b => { const originalHarvest = b.$harvestBlock; - b.$harvestBlock = function ($theWorld, $player, $blockpos, $blockstate, $tileentity) { - if ($player.$isSneaking() && !ModAPI.util.isCritical()) { + b.$harvestBlock = function ($theWorld, $player, $blockpos, $blockstate, $tileentity, ...args) { + const blockState = ModAPI.util.wrap($blockstate); + const player = ModAPI.util.wrap($player); + console.log(blockState, player); + if (player.isSneaking() && !ModAPI.util.isCritical() && !(logs.includes(blockState.block.getRef()) && !axes.includes(player.inventory.mainInventory[player.inventory.currentItem]?.getCorrective()?.item?.getRef()))) { ModAPI.promisify(async () => { - var player = ModAPI.util.wrap($player); var world = ModAPI.util.wrap($theWorld); - var harvestCall = ModAPI.promisify(player.theItemInWorldManager.tryHarvestBlock); - - const blocks = await getBlockGraph(ModAPI.util.wrap($blockpos), ModAPI.promisify(world.getBlockState), b); + var harvestCall = ModAPI.promisify(ModAPI.is_1_12 ? player.interactionManager.tryHarvestBlock : player.theItemInWorldManager.tryHarvestBlock); + const blocks = await getBlockGraph(ModAPI.util.wrap($blockpos), ModAPI.promisify(world.getBlockState), b); + console.log(blocks); for (let i = 0; i < blocks.length; i++) { await harvestCall(blocks[i].getRef()); } })(); } - originalHarvest.apply(this, [$theWorld, $player, $blockpos, $blockstate, $tileentity]); + originalHarvest.apply(this, [$theWorld, $player, $blockpos, $blockstate, $tileentity, ...args]); } }); }); diff --git a/package.json b/package.json index eba4922..e4d09c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eaglerforgeinjector", - "version": "2.7.8", + "version": "2.7.9", "description": "Advanced modding API injector for unminified, unobfuscated, unsigned eaglercraft builds.", "main": "node.js", "directories": {