Merge pull request #101 from eaglerforge/main

v2.7.91
This commit is contained in:
ZXMushroom63 2025-05-06 19:13:24 +08:00 committed by GitHub
commit 74b4130d4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 16 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.91", //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
@ -1091,10 +1104,14 @@ const modapi_postinit = "(" + (() => {
}
ModAPI.util.bootstrap = function () {
ModAPI.items = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.init.Items")].staticVariables, StaticProps_ProxyConf);
ModAPI.blocks = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.init.Blocks")].staticVariables, StaticProps_ProxyConf);
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);
ModAPI.items = new Proxy(ModAPI.reflect.getClassById("net.minecraft.init.Items").staticVariables, StaticProps_ProxyConf);
ModAPI.blocks = new Proxy(ModAPI.reflect.getClassById("net.minecraft.init.Blocks").staticVariables, StaticProps_ProxyConf);
ModAPI.materials = new Proxy(ModAPI.reflect.getClassById("net.minecraft.block.material.Material").staticVariables, StaticProps_ProxyConf);
if (ModAPI.is_1_12) {
ModAPI.enchantments = new Proxy(ModAPI.reflect.getClassById("net.minecraft.init.Enchantments").staticVariables, StaticProps_ProxyConf);
} else {
ModAPI.enchantments = new Proxy(ModAPI.reflect.getClassById("net.minecraft.enchantment.Enchantment").staticVariables, StaticProps_ProxyConf);
}
}
ModAPI.events.newEvent("bootstrap", "server");
@ -1173,6 +1190,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

View File

@ -79,6 +79,8 @@ The global object has the following properties:
- More: [ArrayDocumentation](array.md)
- `ModAPI.version: String`
- The version of ModAPI.
- `ModAPI.is_1_12: Boolean`
- Property defining wether or not ModAPI thinks the current version is 1.12-based.
- `ModAPI.flavour: String`
- The flavour of ModAPI. Hardcoded to be `"injector"`.

View File

@ -14,7 +14,7 @@
} catch (error) {
//swallow
}
ModAPI.meta.config(()=>{
ModAPI.meta.config(() => {
var conf = document.createElement("div");
conf.innerHTML = `
<h1>Vein Miner Settings&nbsp;<a href="javascript:void(0)" onclick="this.parentElement.parentElement.remove()" style="color:red">[X]</a></h1>
@ -25,7 +25,7 @@
<label>Veinmine Clay: </label><input type=checkbox ${VEINMINERCONF.doClay ? "checked" : ""} oninput="VEINMINERCONF.doClay = this.checked; this.parentElement.__save();"></input><br>
`;
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,20 @@
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);
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);
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.91",
"description": "Advanced modding API injector for unminified, unobfuscated, unsigned eaglercraft builds.",
"main": "node.js",
"directories": {