Client side implementation of the jukebox overhaul

Uses a mixin into the sound system to determine the sound played at the position of the jukebox, then tries to get the record item of the sound.
If it fails it will fall back to the server side implementation.
This commit is contained in:
Motschen
2021-03-28 12:07:47 +02:00
parent f802e803b9
commit afac024e9e
5 changed files with 88 additions and 2 deletions

View File

@@ -0,0 +1,36 @@
package eu.midnightdust.visualoverhaul.mixin;
import eu.midnightdust.visualoverhaul.util.sound.SoundTest;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.client.sound.SoundSystem;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(SoundSystem.class)
public abstract class MixinSoundSystem {
@Shadow private boolean started;
private BlockPos jukeboxPos;
@Inject(at = @At("TAIL"),method = "play(Lnet/minecraft/client/sound/SoundInstance;)V")
public void onPlayRecordSound(SoundInstance soundInstance, CallbackInfo ci) {
if (soundInstance.getCategory().equals(SoundCategory.RECORDS) && this.started) {
jukeboxPos = new BlockPos(soundInstance.getX(),soundInstance.getY(),soundInstance.getZ());
SoundTest.soundPos.put(jukeboxPos, soundInstance.getId());
}
}
@Inject(at = @At("TAIL"),method = "stop(Lnet/minecraft/client/sound/SoundInstance;)V")
public void onStopRecordSound(SoundInstance soundInstance, CallbackInfo ci) {
if (soundInstance.getCategory().equals(SoundCategory.RECORDS) && SoundTest.soundPos.containsKey(new BlockPos(soundInstance.getX(),soundInstance.getY(),soundInstance.getZ()))) {
jukeboxPos = new BlockPos(soundInstance.getX(),soundInstance.getY(),soundInstance.getZ());
SoundTest.soundPos.remove(jukeboxPos,soundInstance.getId());
}
}
}