-
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.
and it only cost me my sanity :^)
- Loading branch information
Showing
5 changed files
with
735 additions
and
146 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
src/main/java/dev/stardust/mixin/PositionedSoundInstanceMixin.java
This file was deleted.
Oops, something went wrong.
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
67 changes: 67 additions & 0 deletions
67
src/main/java/dev/stardust/mixin/WeightedSoundSetMixin.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,67 @@ | ||
package dev.stardust.mixin; | ||
|
||
import java.util.List; | ||
import dev.stardust.modules.MusicTweaks; | ||
import net.minecraft.client.sound.Sound; | ||
import net.minecraft.sound.SoundCategory; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import io.netty.util.internal.ThreadLocalRandom; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import net.minecraft.client.sound.SoundContainer; | ||
import net.minecraft.client.sound.WeightedSoundSet; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import meteordevelopment.meteorclient.systems.modules.Modules; | ||
import net.minecraft.util.math.floatprovider.ConstantFloatProvider; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
|
||
/** | ||
* @author Tas [0xTas] <[email protected]> | ||
**/ | ||
@Mixin(WeightedSoundSet.class) | ||
public abstract class WeightedSoundSetMixin implements SoundContainer<Sound> { | ||
@Shadow | ||
@Final | ||
private List<SoundContainer<Sound>> sounds; | ||
|
||
// See MusicTweaks.java | ||
@Inject(method = "getSound(Lnet/minecraft/util/math/random/Random;)Lnet/minecraft/client/sound/Sound;", at = @At("HEAD"), cancellable = true) | ||
private void mixinGetSound(net.minecraft.util.math.random.Random random, CallbackInfoReturnable<Sound> cir) { | ||
MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); | ||
if (tweaks == null || !tweaks.isActive()) return; | ||
|
||
boolean overwrite = false; | ||
for (SoundContainer<Sound> sound : this.sounds) { | ||
String id = sound.getSound(random).toString(); | ||
|
||
if (id.contains("minecraft:music/")) { | ||
overwrite = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!overwrite) return; | ||
List<String> soundIDs = tweaks.getSoundSet(); | ||
if (soundIDs.isEmpty()) return; | ||
|
||
float adjustedPitch; | ||
if (tweaks.randomPitch()) { | ||
adjustedPitch = 1.0f + tweaks.getRandomPitch(); | ||
} else { | ||
adjustedPitch = 1.0f + tweaks.getPitchAdjustment(); | ||
} | ||
float adjustedVolume = tweaks.getClient().options.getSoundVolume(SoundCategory.MUSIC) + tweaks.getVolumeAdjustment(); | ||
|
||
cir.setReturnValue( | ||
new Sound( | ||
soundIDs.get(ThreadLocalRandom.current().nextInt(soundIDs.size())), | ||
ConstantFloatProvider.create(adjustedVolume), | ||
ConstantFloatProvider.create(adjustedPitch), | ||
this.getWeight(), Sound.RegistrationType.SOUND_EVENT, | ||
true, true, 16 | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.