This commit is contained in:
ZXMushroom63 2025-05-06 19:03:25 +08:00
parent 92ccade9fe
commit 5c4d4a3803
4 changed files with 36 additions and 12 deletions

View File

@ -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.")

View File

@ -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
@ -1174,6 +1187,12 @@ const modapi_postinit = "(" + (() => {
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
if (arr.length >= interval) {

View File

@ -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);
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]);
}
});
});

View File

@ -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": {