Skip to content

Commit

Permalink
Added MusicTweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Dec 28, 2023
1 parent 9f024e7 commit fdc4257
Show file tree
Hide file tree
Showing 11 changed files with 701 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ It provides a handful of modules for enhancing your experience on old server.<br
- **AutoDrawDistance** - *Automatically adjusts your render distance to maintain an FPS target.* Some biomes/areas can drop my fps by half, so I found this somewhat useful at times.
- **BannerData** - *Right-click banners to display their pattern and color data.* Looks cool, gives you the base color without any fuss. Can also copy the raw nbt to your clipboard.
- **BookTools** - *Enhancements for working with books.* Adds buttons for inserting color & formatting codes into writable books, and adds a deobfuscation button to written books containing obfuscated/magic text.
- **MusicTweaks** - *Lets you tweak various things relating to the background music.* Change the pitch, volume, or cooldown between songs, or even choose and view which soundtracks play during your session.
- **RocketMan** - *Makes flying with fireworks much easier (bring lots of rockets!)* This doesn't feature any fancy grim control bypasses or anything like that. This is just a good clean quasi-control firework efly that won't be patched as long as you have access to rockets (which are currently afkable.)
- **Honker** - *Automatically uses goat horns when a player enters your render distance.* You can select your preferred horn type, or choose random for a surprise pick from your inventory each time.
- **ChatSigns** - *Read nearby signs in your chat.* Can also point-out possible old signs*.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/stardust/Stardust.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void onInitialize() {
Modules.get().add(new ChatSigns());
Modules.get().add(new RocketMan());
Modules.get().add(new BannerData());
Modules.get().add(new MusicTweaks());
Modules.get().add(new SignatureSign());
Modules.get().add(new UpdateNotifier());
Modules.get().add(new AutoDrawDistance());
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/dev/stardust/mixin/MinecraftClientMixin.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package dev.stardust.mixin;

import dev.stardust.modules.RocketMan;
import net.minecraft.sound.MusicSound;
import dev.stardust.modules.MusicTweaks;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.client.MinecraftClient;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;


/**
Expand Down Expand Up @@ -89,4 +92,17 @@ private void mixinRender(CallbackInfo ci) {
}

}

// See MusicTweaks.java
@Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true)
public void mixinGetMusicType(CallbackInfoReturnable<MusicSound> cir) {
MusicTweaks tweaks = Modules.get().get(MusicTweaks.class);

if (tweaks == null || !tweaks.isActive()) return;
MusicSound type = tweaks.getTypes();

if (type != null) {
cir.setReturnValue(type);
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/dev/stardust/mixin/MusicTrackerAccessor.java
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();
}
30 changes: 30 additions & 0 deletions src/main/java/dev/stardust/mixin/MusicTrackerMixin.java
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 src/main/java/dev/stardust/mixin/NarratorManagerMixin.java
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 src/main/java/dev/stardust/mixin/PositionedSoundInstanceMixin.java
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
)
);
}
}
88 changes: 88 additions & 0 deletions src/main/java/dev/stardust/mixin/SoundSystemMixin.java
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 src/main/java/dev/stardust/mixin/SourceManagerAccessor.java
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();
}
Loading

0 comments on commit fdc4257

Please sign in to comment.