From 23b42e66fb7f8d3eaee3690b6322be1bfb871cc6 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sun, 26 Jan 2025 20:13:02 +0800 Subject: [PATCH] going insane --- examplemods/cubeentity.js | 17 ++++++++++++----- injector.js | 2 +- postinit.js | 15 +++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/examplemods/cubeentity.js b/examplemods/cubeentity.js index 4c39650..f84e108 100644 --- a/examplemods/cubeentity.js +++ b/examplemods/cubeentity.js @@ -2,22 +2,28 @@ ModAPI.meta.title("Cube Entity"); ModAPI.meta.version("v0"); ModAPI.meta.description("testing custom entities"); - ModAPI.meta.credits("By ZXMushroom64"); + ModAPI.meta.credits("By ZXMushroom63"); function registerEntity() { // Utils const ResourceLocation = ModAPI.reflect.getClassByName("ResourceLocation").constructors.find(x => x.length === 1); const GlStateManager = Object.fromEntries(Object.values(ModAPI.reflect.getClassByName("GlStateManager").staticMethods).map(x => [x.methodNameShort, x.method])); + const IAnimals = ModAPI.reflect.getClassById("net.minecraft.entity.passive.IAnimals"); // START CUSTOM ENTITY var entityClass = ModAPI.reflect.getClassById("net.minecraft.entity.Entity"); var entitySuper = ModAPI.reflect.getSuper(entityClass, (x) => x.length === 2); var nme_EntityCube = function nme_EntityCube($worldIn) { entitySuper(this, $worldIn); - //this.$preventEntitySpawning = 1; + this.$preventEntitySpawning = 1; this.$setSize(1, 1); } ModAPI.reflect.prototypeStack(entityClass, nme_EntityCube); + + //Turns out that minecraft 1.8's networking code is really stupid. Notch hardcoded every entity except for ones that implement the IAnimals interface. + //I don't know why, and I don't really care either. As long as it works (been working on this for too long, losing sanity) + ModAPI.reflect.implements(nme_EntityCube, IAnimals); + nme_EntityCube.prototype.$canTriggerWalking = function () { return 0 }; nme_EntityCube.prototype.$canBePushed = function () { return 0 }; nme_EntityCube.prototype.$getCollisionBox = function () { return this.$getEntityBoundingBox() }; @@ -27,9 +33,10 @@ }; nme_EntityCube.prototype.$writeEntityToNBT = function (nbtTagCompount) { // Needed, is an abstract method in parent class nbtTagCompount = ModAPI.util.wrap(nbtTagCompount); - }; - nme_EntityCube.prototype.$getCollisionBoundingBox = function () { return this.$getEntityBoundingBox() }; // Needed, is an abstract method in parent class - nme_EntityCube.prototype.$entityInit = function () { console.log("Cube entity created!") }; // Needed, is an abstract method in parent class + }; + nme_EntityCube.prototype.$entityInit = function () { + console.log("Cube entity created!"); + }; // END CUSTOM ENTITY diff --git a/injector.js b/injector.js index 386e80b..30b93ce 100644 --- a/injector.js +++ b/injector.js @@ -1,4 +1,4 @@ -globalThis.ModAPIVersion = "v2.6"; +globalThis.ModAPIVersion = "v2.7"; globalThis.doEaglerforge = true; document.querySelector("title").innerText = `EaglerForge Injector ${ModAPIVersion}`; document.querySelector("h1").innerText = `EaglerForge Injector ${ModAPIVersion}`; diff --git a/postinit.js b/postinit.js index 5a6c38b..7e5fa42 100644 --- a/postinit.js +++ b/postinit.js @@ -452,13 +452,14 @@ globalThis.modapi_postinit = "(" + (() => { var reloadDeprecationWarnings = 0; const TeaVMArray_To_Recursive_BaseData_ProxyConf = { get(target, prop, receiver) { + var corrective = !!this._corrective; if (prop === "getRef") { return function () { return target; } } var outputValue = Reflect.get(target, prop, receiver); - var wrapped = ModAPI.util.wrap(outputValue, target, this._corrective, true); + var wrapped = ModAPI.util.wrap(outputValue, target, corrective, true); if (wrapped) { return wrapped; } @@ -480,6 +481,7 @@ globalThis.modapi_postinit = "(" + (() => { return ("$" + prop) in target; }, get(target, prop, receiver) { + var corrective = !!this._corrective; if (prop === "getCorrective") { return function () { return new Proxy(target, patchProxyConfToCorrective(TeaVM_to_Recursive_BaseData_ProxyConf)); @@ -487,7 +489,7 @@ globalThis.modapi_postinit = "(" + (() => { } if (prop === "isCorrective") { return function () { - return !!this._corrective; + return corrective; } } if (prop === "getRef") { @@ -504,15 +506,15 @@ globalThis.modapi_postinit = "(" + (() => { } } if (prop === "isModProxy") { - return true + return true; } var outProp = "$" + prop; - if (this._corrective) { + if (corrective) { outProp = ModAPI.util.getNearestProperty(target, outProp); } var outputValue = Reflect.get(target, outProp, receiver); - var wrapped = ModAPI.util.wrap(outputValue, target, this._corrective, false); + var wrapped = ModAPI.util.wrap(outputValue, target, corrective, false); if (wrapped) { return wrapped; } @@ -1076,7 +1078,8 @@ globalThis.modapi_postinit = "(" + (() => { return qhash(block, values); } ModAPI.keygen.entity = function (entity) { - var values = ModAPI.reflect.getClassById("net.minecraft.entity.EntityList").staticVariables.idToClassMapping.$elementData.data.filter(x=>x).map(x=>x.$key.$value); + var hashMap = ModAPI.util.wrap(ModAPI.reflect.getClassById("net.minecraft.entity.EntityList").staticVariables.idToClassMapping).getCorrective(); + var values = hashMap.keys.getRef().data.filter(x=>hashMap.get(x)); return qhash(entity, values); } }).toString() + ")();";