From 3979d7e0cee583d1a3d362e0bf7198ff3bfefbe1 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Fri, 30 May 2025 16:43:08 +0800 Subject: [PATCH] add enchantment keygen --- core/postinit.js | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/core/postinit.js b/core/postinit.js index e8049b1..2b03ce5 100644 --- a/core/postinit.js +++ b/core/postinit.js @@ -36,7 +36,7 @@ const modapi_postinit = "(" + (() => { } function getCreditsString() { return Object.entries(credits).map((entry) => { - return " "+entry[0] + LF + " " + (new Array(entry[0].length)).fill("~").join("") + entry[1].join("") + LF + LF + LF; + return " " + entry[0] + LF + " " + (new Array(entry[0].length)).fill("~").join("") + entry[1].join("") + LF + LF + LF; }).join(""); } ModAPI.array = {}; @@ -571,6 +571,24 @@ const modapi_postinit = "(" + (() => { return target; } } + if (prop === "getCorrective") { + return function () { + return new Proxy(target, patchProxyConfToCorrective(TeaVMArray_To_Recursive_BaseData_ProxyConf)); + } + } + if (prop === "isCorrective") { + return function () { + return corrective; + } + } + if (prop === "reload") { + return function () { + if (reloadDeprecationWarnings < 10) { + console.warn("ModAPI/PluginAPI reload() is obsolete, please stop using it in code.") + reloadDeprecationWarnings++; + } + } + } var outputValue = Reflect.get(target, prop, receiver); var wrapped = ModAPI.util.wrap(outputValue, target, corrective, true); if (wrapped) { @@ -1196,8 +1214,10 @@ const modapi_postinit = "(" + (() => { 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) { + + ModAPI.util.qhash = function qhash(txt, arr, interval) { + arr ||= []; + interval ||= 32767; // var interval = 4095; //used to be 4095 - arr.length, but that increases incompatibility based on load order and other circumstances if (arr.length >= interval) { console.error("[ModAPI.keygen] Ran out of IDs while generating for " + txt); @@ -1253,13 +1273,22 @@ const modapi_postinit = "(" + (() => { return -1; } const SoundEvent = ModAPI.reflect.getClassByName("SoundEvent") - const values = ModAPI.util.wrap(SoundEvent.staticVariables.REGISTRY).getCorrective().underlyingIntegerMap.identityMap.elementData.filter(x=>!!x).map(y=>y.value.value); + const values = ModAPI.util.wrap(SoundEvent.staticVariables.REGISTRY).getCorrective().underlyingIntegerMap.identityMap.elementData.filter(x => !!x).map(y => y.value.value); return qhash(soundId, values, 4095); } + ModAPI.keygen.enchantment = function (enchantment) { + const Enchantment = ModAPI.reflect.getClassByName("Enchantment"); + if (ModAPI.is_1_12) { + const values = ModAPI.util.wrap(Enchantment.staticVariables.REGISTRY).getCorrective().underlyingIntegerMap.identityMap.elementData.filter(x => !!x).map(y => y.value.value); + return qhash(enchantment, values, 4095); + } + const values = ModAPI.util.wrap(Enchantment.staticVariables.enchantmentsList).getCorrective().filter(x => !!x).map(y => y.effectId); + return qhash(enchantment, values, 4095); + } }).toString() + ")();"; if (globalThis.process) { module.exports = { modapi_postinit: modapi_postinit } - } \ No newline at end of file +} \ No newline at end of file