mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 06:01:38 -09:00
duck mod now somewhat works
This commit is contained in:
parent
6b2d19c705
commit
393f6fd2e7
@ -6,6 +6,7 @@ Properties:
|
||||
|
||||
- `classes: ReflectClass[]`
|
||||
- `ModAPI.reflect.classes` is an array of ReflectClasses, representing (almost) every java class.
|
||||
- `classMap: Map<String, ReflectClass>` is a map of every class.
|
||||
|
||||
Methods:
|
||||
|
||||
@ -54,11 +55,8 @@ Each `ReflectClass` has the following properties:
|
||||
- List of all the static variable names for the class.
|
||||
- `staticVariables: Map<String, *>`
|
||||
- key-value dictionary of all the static variables in a class.
|
||||
- `superclass: Class?`
|
||||
- The raw teavm class of the superclass.
|
||||
- `superclassName: String?`
|
||||
- The class id of the class's superclass. Eg: `net.minecraft.client.entity.AbstractClientPlayer`
|
||||
- Will be `null` if `hasMeta` is equal to `false`
|
||||
- `superclass: ReflectClass?`
|
||||
- The superclass.
|
||||
|
||||
Each `ReflectClass` has the following methods:
|
||||
|
||||
|
@ -317,8 +317,25 @@ ModAPI.meta.credits("By ZXMushroom63");
|
||||
// category: AsyncSink.Audio.Category.*
|
||||
// SoundEntry = {path: String, pitch: 1, volume: 1, streaming: false}
|
||||
const SoundPoolEntry = ModAPI.reflect.getClassByName("SoundPoolEntry").constructors.find(x => x.length === 4);
|
||||
const SoundEventAccessor = ModAPI.reflect.getClassByName("SoundEventAccessor").constructors.find(x => x.length === 2);
|
||||
const SoundEventAccessorComposite = ModAPI.reflect.getClassByName("SoundEventAccessorComposite").constructors.find(x => x.length === 4);
|
||||
const SoundEventAccessorClass = ModAPI.reflect.getClassByName("SoundEventAccessor").class;
|
||||
function makeSoundEventAccessor(soundpoolentry, weight) {
|
||||
var object = new SoundEventAccessorClass;
|
||||
var wrapped = ModAPI.util.wrap(object).getCorrective();
|
||||
wrapped.entry = soundpoolentry;
|
||||
wrapped.weight = weight;
|
||||
return object;
|
||||
}
|
||||
const SoundEventAccessorCompositeClass = ModAPI.reflect.getClassByName("SoundEventAccessorComposite").class;
|
||||
function makeSoundEventAccessorComposite(rKey, pitch, volume, category) {
|
||||
var object = new SoundEventAccessorCompositeClass;
|
||||
var wrapped = ModAPI.util.wrap(object).getCorrective();
|
||||
wrapped.soundLocation = rKey;
|
||||
wrapped.eventPitch = pitch;
|
||||
wrapped.eventVolume = volume;
|
||||
wrapped.category = category;
|
||||
wrapped.soundPool = ModAPI.hooks.methods.cgcc_Lists_newArrayList1();
|
||||
return object;
|
||||
}
|
||||
AsyncSink.Audio.register = function addSfx(key, category, values) {
|
||||
var snd = ModAPI.mc.mcSoundHandler;
|
||||
var registry = snd.sndRegistry.soundRegistry;
|
||||
@ -327,14 +344,14 @@ ModAPI.meta.credits("By ZXMushroom63");
|
||||
var path = ResourceLocation(ModAPI.util.str(se.path));
|
||||
return SoundPoolEntry(path, se.pitch, se.volume, 1 * se.streaming);
|
||||
}).map(spe => {
|
||||
return SoundEventAccessor(spe, 1); // 1 = weight
|
||||
return makeSoundEventAccessor(spe, 1); // 1 = weight
|
||||
});
|
||||
var compositeSound = SoundEventAccessorComposite(rKey, 1, 1, category);
|
||||
var compositeSound = makeSoundEventAccessorComposite(rKey, 1, 1, category);
|
||||
var compositeSoundWrapped = ModAPI.util.wrap(compositeSound);
|
||||
soundPool.forEach(sound => {
|
||||
compositeSoundWrapped.addSoundToEventPool(sound);
|
||||
compositeSoundWrapped.soundPool.add(sound);
|
||||
});
|
||||
AsyncSink.Audio.Objects.push([rKey, compositeSound]);
|
||||
registry.$put(rKey, compositeSound);
|
||||
registry.put(rKey, compositeSound);
|
||||
}
|
||||
})();
|
166
examplemods/DuckMod.js
Normal file
166
examplemods/DuckMod.js
Normal file
File diff suppressed because one or more lines are too long
33
postinit.js
33
postinit.js
@ -353,21 +353,14 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return this.constructors[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof item?.$meta?.superclass === "function" && item?.$meta?.superclass?.$meta) {
|
||||
ModAPI.hooks._classMap[compiledName].superclass = item.$meta.superclass;
|
||||
ModAPI.hooks._classMap[compiledName].superclassName = item.$meta.superclass.$meta.name ?? (item.$meta.superclass ? item.$meta.superclass.name.split("_").map((x, i) => {
|
||||
if (i === 0) {
|
||||
return x.split("").join(".") + "."
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
}).join("_").replace("._", ".") : null);
|
||||
ModAPI.hooks._classMap[compiledName].superclassRaw = item.$meta.superclass;
|
||||
} else {
|
||||
ModAPI.hooks._classMap[compiledName].superclass = null;
|
||||
ModAPI.hooks._classMap[compiledName].superclassName = null;
|
||||
ModAPI.hooks._classMap[compiledName].superclassRaw = null;
|
||||
}
|
||||
|
||||
if (item?.["$$constructor$$"]) {
|
||||
@ -414,7 +407,19 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
}));
|
||||
ModAPI.hooks._classMap[compiledName].staticVariableNames = Object.keys(ModAPI.hooks._classMap[compiledName].staticVariables);
|
||||
});
|
||||
|
||||
//populate superclasses
|
||||
compiledNames.forEach(compiledName => {
|
||||
var item = ModAPI.hooks._classMap[compiledName];
|
||||
if (item.superclassRaw) {
|
||||
item.superclass = ModAPI.hooks._classMap[item.superclassRaw.name];
|
||||
} else {
|
||||
item.superclass = null;
|
||||
}
|
||||
});
|
||||
|
||||
ModAPI.reflect.classes = Object.values(ModAPI.hooks._classMap);
|
||||
ModAPI.reflect.classMap = ModAPI.hooks._classMap;
|
||||
console.log("[ModAPI] Regenerated hook classmap.");
|
||||
}
|
||||
ModAPI.hooks.regenerateClassMap();
|
||||
@ -430,7 +435,13 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
//Magical function for making a subclass with a custom constructor that you can easily use super(...) on.
|
||||
ModAPI.reflect.getSuper = function getSuper(reflectClass, filter) {
|
||||
filter ||= (x) => x.length === 1;
|
||||
while (!reflectClass.internalConstructors.find(filter) && reflectClass.superclass) {
|
||||
reflectClass = reflectClass.superclass;
|
||||
}
|
||||
var initialiser = reflectClass.internalConstructors.find(filter);
|
||||
if (!initialiser) {
|
||||
throw new Error("[ModAPI] Failed to find matching superclass constructor in tree.");
|
||||
}
|
||||
return function superFunction(thisArg, ...extra_args) {
|
||||
reflectClass.class.call(thisArg);
|
||||
initialiser(thisArg, ...extra_args);
|
||||
|
Loading…
x
Reference in New Issue
Block a user