-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
5 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/eu/midnightdust/visualoverhaul/mixin/MixinSoundSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/eu/midnightdust/visualoverhaul/util/sound/SoundTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package eu.midnightdust.visualoverhaul.util.sound; | ||
|
||
import com.google.common.collect.Maps; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import java.util.Map; | ||
|
||
public class SoundTest { | ||
|
||
public static Map<BlockPos, Identifier> soundPos = Maps.newHashMap(); | ||
|
||
/** | ||
* Returns the Sound provided in MixinSoundSystem | ||
* {@link eu.midnightdust.visualoverhaul.mixin.MixinSoundSystem} | ||
*/ | ||
public static Identifier getSound(BlockPos pos) { | ||
if (soundPos.containsKey(pos)) { | ||
return soundPos.get(pos); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters