asyncsink audio fixed!

This commit is contained in:
ZXMushroom63 2025-05-29 17:21:33 +08:00
parent 337aff679d
commit e3c7d474c5

View File

@ -349,12 +349,12 @@ ModAPI.meta.credits("By ZXMushroom63");
wrapped.rnd = EaglercraftRandom();
return object;
}
function makeSoundEventAccessor112(rKey) {
function makeSoundEventAccessor112(rKey, subttl) {
const SoundEventAccessorClass = ModAPI.reflect.getClassByName("SoundEventAccessor").class;
var object = new SoundEventAccessorClass;
var wrapped = ModAPI.util.wrap(object).getCorrective();
wrapped.location = rKey;
wrapped.subtitle = null;
wrapped.subtitle = ModAPI.util.str(subttl);
wrapped.accessorList = ModAPI.hooks.methods.cgcc_Lists_newArrayList0();
wrapped.rnd = EaglercraftRandom();
return object;
@ -362,18 +362,30 @@ ModAPI.meta.credits("By ZXMushroom63");
if (ModAPI.is_1_12) {
const soundType = ModAPI.reflect.getClassById("net.minecraft.client.audio.Sound$Type").staticVariables.FILE;
const mkSound = ModAPI.reflect.getClassById("net.minecraft.client.audio.Sound").constructors[0];
const SoundEvent = ModAPI.reflect.getClassById("net.minecraft.util.SoundEvent");
const SoundEvents = ModAPI.reflect.getClassById("net.minecraft.init.SoundEvents");
AsyncSink.Audio.register = function addSfx(key, category, values) {
if (!category) {
throw new Error("[AsyncSink] Invalid audio category provided: "+category);
AsyncSink.Audio.register = function addSfx(key, unused, values, subtitle) {
subtitle ||= "(AsyncSink Sound)";
if (unused) {
console.log("Category is not a property of the sound in 1.12, category for " + key + " will be unused.");
}
const rKey = ResourceLocation(ModAPI.util.str(key));
const ev = new SoundEvent.class;
ev.$soundName = rKey;
ModAPI.util.wrap(SoundEvent.staticVariables.REGISTRY).register(ModAPI.keygen.sound(key), rKey, ev);
const outObj = SoundEvents.staticMethods.getRegisteredSoundEvent.method(ModAPI.util.str(key));
var snd = ModAPI.mc.mcSoundHandler.getCorrective();
var registry = snd.soundRegistry.soundRegistry;
var rKey = ResourceLocation(ModAPI.util.str(key));
var soundPool = values.map(se => {
return mkSound(ModAPI.util.str(se.path), se.volume, se.pitch, 1, soundType, 1 * se.streaming);
return mkSound(ModAPI.util.str(se.path.replace("sounds/", "").replace(".ogg", "")), se.volume, se.pitch, 1, soundType, 1 * se.streaming);
});
var eventAccessor = makeSoundEventAccessor112(rKey);
var eventAccessor = makeSoundEventAccessor112(rKey, subtitle);
var eventAccessorWrapped = ModAPI.util.wrap(eventAccessor);
soundPool.forEach(sound => {
eventAccessorWrapped.accessorList.add(sound);
@ -381,7 +393,7 @@ ModAPI.meta.credits("By ZXMushroom63");
AsyncSink.Audio.Objects.push([rKey, eventAccessor]);
registry.put(rKey, eventAccessor);
values.map(x => "resourcepacks/AsyncSinkLib/assets/minecraft/" + x.path + ".mcmeta").forEach(x => AsyncSink.setFile(x, new ArrayBuffer(0)));
return soundPool;
return outObj;
}
} else {
const SoundPoolEntry = ModAPI.reflect.getClassByName("SoundPoolEntry").constructors.find(x => x.length === 4);