-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
701 additions
and
0 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
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
18 changes: 18 additions & 0 deletions
18
src/main/java/dev/stardust/mixin/MusicTrackerAccessor.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,18 @@ | ||
package dev.stardust.mixin; | ||
|
||
import javax.annotation.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import net.minecraft.client.sound.MusicTracker; | ||
import net.minecraft.client.sound.SoundInstance; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
|
||
@Mixin(MusicTracker.class) | ||
public interface MusicTrackerAccessor { | ||
@Accessor("timeUntilNextSong") | ||
void setTimeUntilNextSong(int time); | ||
|
||
@Accessor("current") | ||
@Nullable | ||
SoundInstance getCurrent(); | ||
} |
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,30 @@ | ||
package dev.stardust.mixin; | ||
|
||
import dev.stardust.modules.MusicTweaks; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import net.minecraft.client.sound.MusicTracker; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import meteordevelopment.meteorclient.systems.modules.Modules; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
|
||
/** | ||
* @author Tas [0xTas] <[email protected]> | ||
**/ | ||
@Mixin(MusicTracker.class) | ||
public class MusicTrackerMixin { | ||
// See MusicTweaks.java | ||
@Inject(method = "tick", at = @At("TAIL")) | ||
private void mixinTick(CallbackInfo ci) { | ||
MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); | ||
|
||
if (tweaks == null || !tweaks.isActive()) return; | ||
boolean currentlyPlaying = ((MusicTrackerAccessor) this).getCurrent() != null; | ||
|
||
if (!currentlyPlaying) { tweaks.nullifyCurrentType(); } | ||
if (tweaks.overrideDelay() && currentlyPlaying) { | ||
((MusicTrackerAccessor) this).setTimeUntilNextSong(tweaks.getTimeUntilNextSong()); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/dev/stardust/mixin/NarratorManagerMixin.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,26 @@ | ||
package dev.stardust.mixin; | ||
|
||
import net.minecraft.text.Text; | ||
import dev.stardust.modules.MusicTweaks; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import net.minecraft.client.util.NarratorManager; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import meteordevelopment.meteorclient.systems.modules.Modules; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
|
||
/** | ||
* @author Tas [0xTas] <[email protected]> | ||
**/ | ||
@Mixin(NarratorManager.class) | ||
public class NarratorManagerMixin { | ||
// See SoundSystemMixin.java | ||
@Inject(method = "narrate(Lnet/minecraft/text/Text;)V", at = @At("HEAD"), cancellable = true) | ||
private void mixinNarrate(Text text, CallbackInfo ci) { | ||
MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); | ||
|
||
if (tweaks == null || !tweaks.isActive()) return; | ||
if (text.getString().startsWith("Now Playing: ") || text.getString().contains("§2§oNow Playing§r§7: ")) ci.cancel(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/dev/stardust/mixin/PositionedSoundInstanceMixin.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,53 @@ | ||
package dev.stardust.mixin; | ||
|
||
import net.minecraft.sound.SoundEvent; | ||
import dev.stardust.modules.MusicTweaks; | ||
import net.minecraft.sound.SoundCategory; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.client.sound.SoundInstance; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import net.minecraft.client.sound.AbstractSoundInstance; | ||
import net.minecraft.client.sound.PositionedSoundInstance; | ||
import meteordevelopment.meteorclient.systems.modules.Modules; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
|
||
/** | ||
* @author Tas [0xTas] <[email protected]> | ||
**/ | ||
@Mixin(PositionedSoundInstance.class) | ||
public class PositionedSoundInstanceMixin extends AbstractSoundInstance { | ||
protected PositionedSoundInstanceMixin(SoundEvent sound, SoundCategory category, Random random) { | ||
super(sound, category, random); | ||
} | ||
|
||
// See MusicTweaks.java | ||
@Inject(method = "music", at = @At("HEAD"), cancellable = true) | ||
private static void mixinMusic(SoundEvent sound, CallbackInfoReturnable<PositionedSoundInstance> cir) { | ||
MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); | ||
if (tweaks == null || !tweaks.isActive()) return; | ||
|
||
float adjustedPitch; | ||
if (tweaks.randomPitch()) { | ||
adjustedPitch = 1.0f + tweaks.getRandomPitch(); | ||
} else { | ||
adjustedPitch = 1.0f + tweaks.getPitchAdjustment(); | ||
} | ||
|
||
if (adjustedPitch == 1.0f) return; | ||
|
||
cir.setReturnValue( | ||
new PositionedSoundInstance( | ||
sound.getId(), | ||
SoundCategory.MUSIC, | ||
1f, adjustedPitch, | ||
SoundInstance.createRandom(), | ||
false, 0, | ||
AttenuationType.NONE, | ||
0f, 0f, 0f, true | ||
) | ||
); | ||
} | ||
} |
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,88 @@ | ||
package dev.stardust.mixin; | ||
|
||
import java.util.Map; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.client.sound.*; | ||
import org.spongepowered.asm.mixin.*; | ||
import dev.stardust.modules.MusicTweaks; | ||
import net.minecraft.util.math.MathHelper; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import meteordevelopment.meteorclient.systems.modules.Modules; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
|
||
/** | ||
* @author Tas [0xTas] <[email protected]> | ||
**/ | ||
@Mixin(SoundSystem.class) | ||
public class SoundSystemMixin { | ||
@Shadow | ||
@Final | ||
private Map<SoundInstance, Channel.SourceManager> sources; | ||
|
||
@Unique | ||
@Mutable | ||
private int totalTicksPlaying; | ||
@Unique | ||
private boolean dirtyPitch = false; | ||
@Unique | ||
private boolean dirtyVolume = false; | ||
|
||
|
||
// See MusicTweaks.java | ||
@Inject(method = "tick()V", at = @At("TAIL")) | ||
private void mixinTick(CallbackInfo ci) { | ||
MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); | ||
if (tweaks == null) return; | ||
|
||
String songID = null; | ||
boolean playing = false; | ||
for (SoundInstance instance : sources.keySet()) { | ||
Sound sound = instance.getSound(); | ||
if (sound == null) continue; | ||
|
||
String location = sound.getLocation().toString(); | ||
if (!location.startsWith("minecraft:sounds/music/")) continue; | ||
Channel.SourceManager sourceManager = this.sources.get(instance); | ||
songID = location.substring(location.lastIndexOf('/')+1); | ||
|
||
playing = true; | ||
if (sourceManager == null) continue; | ||
Source source = ((SourceManagerAccessor) sourceManager).getSource(); | ||
|
||
if (source == null) continue; | ||
if (tweaks.isActive() && !tweaks.randomPitch()) { | ||
this.dirtyPitch = true; | ||
source.setPitch(1.0f + tweaks.getPitchAdjustment()); | ||
} else if (tweaks.isActive() && tweaks.randomPitch() && tweaks.trippyPitch()) { | ||
this.dirtyPitch = true; | ||
source.setPitch(tweaks.getNextPitchStep(instance.getPitch())); // !! | ||
} else if (!tweaks.isActive() && this.dirtyPitch) { | ||
source.setPitch(1f); | ||
this.dirtyPitch = false; | ||
} | ||
if (tweaks.isActive()) { | ||
this.dirtyVolume = true; | ||
source.setVolume(MathHelper.clamp(tweaks.getClient().options.getSoundVolume(instance.getCategory()) + tweaks.getVolumeAdjustment(), 0.0f, 4.0f)); | ||
} else if (this.dirtyVolume) { | ||
this.dirtyVolume = false; | ||
source.setVolume(tweaks.getClient().options.getSoundVolume(instance.getCategory())); | ||
} | ||
} | ||
if (playing) { | ||
++this.totalTicksPlaying; | ||
} else { | ||
this.totalTicksPlaying = 0; | ||
} | ||
|
||
if (tweaks.isActive() && totalTicksPlaying % 30 == 0 && tweaks.shouldDisplayNowPlaying() && songID != null) { | ||
String songName = tweaks.getSongName(songID); | ||
switch (tweaks.getDisplayMode()) { | ||
case Chat -> tweaks.sendNowPlayingMessage(songName); | ||
// See NarratorManagerMixin.java lol | ||
case Record -> tweaks.getClient().inGameHud.setRecordPlayingOverlay(Text.of(songName)); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/dev/stardust/mixin/SourceManagerAccessor.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,15 @@ | ||
package dev.stardust.mixin; | ||
|
||
import javax.annotation.Nullable; | ||
import net.minecraft.client.sound.Source; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import net.minecraft.client.sound.Channel; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
|
||
@Mixin(Channel.SourceManager.class) | ||
public interface SourceManagerAccessor { | ||
@Accessor("source") | ||
@Nullable | ||
Source getSource(); | ||
} |
Oops, something went wrong.