Skip to content

Commit

Permalink
use forges soundRegistry instead of vanilla mcs so we can get modded …
Browse files Browse the repository at this point in the history
…sounds in the all sounds list.
  • Loading branch information
EdgarAllen committed Feb 3, 2019
1 parent 4efff77 commit e24f880
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
apply plugin: 'maven'
apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.0.2.10-RC1"
version = "1.0.2.10-RC2"
group= "edgarallen.soundmuffler" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "supersoundmuffler-1.12.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class SuperSoundMuffler {
public static final String MOD_ID = "supersoundmuffler";
public static final String NAME = "Super Sound Muffler";
public static final String VERSION = "1.0.2.10-RC1";
public static final String VERSION = "1.0.2.10-RC2";
public static final String DEPENDENCIES = "after:baubles;after:theoneprobe;after:waila";

@Mod.Instance(MOD_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import edgarallen.soundmuffler.SuperSoundMuffler;
import edgarallen.soundmuffler.gui.data.IMufflerAccessor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.audio.SoundRegistry;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
Expand All @@ -16,13 +18,14 @@
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.client.GuiScrollingList;
import net.minecraftforge.fml.client.config.GuiButtonExt;
import net.minecraftforge.fml.relauncher.CoreModManager;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

public class GuiSoundMufflerAddSound extends GuiContainer {
Expand Down Expand Up @@ -68,10 +71,35 @@ public boolean canInteractWith(EntityPlayer playerIn) {

private void lazyLoadAllSoundsList() {
allSounds = new ArrayList<>();
allSounds.addAll(SoundEvent.REGISTRY.getKeys());
allSounds.addAll(getSoundList());
allSounds.sort(Comparator.comparing(ResourceLocation::toString));
}

private Set<ResourceLocation> getSoundList() {
boolean isDeobf = false;
try {
final Field f = CoreModManager.class.getDeclaredField("deobfuscatedEnvironment");
f.setAccessible(true);
isDeobf = f.getBoolean(null);
} catch (@Nonnull final Throwable t) {
SuperSoundMuffler.log.error("Are we in a dev environment? No clue... Error'd before I could find out. RIP", t);
}
Set<ResourceLocation> sounds = Collections.EMPTY_SET;
try {
final Field f = SoundHandler.class.getDeclaredField(isDeobf ? "soundRegistry": "field_147697_e");
f.setAccessible(true);
SoundRegistry registry = (SoundRegistry) f.get(Minecraft.getMinecraft().getSoundHandler());

if(registry != null) {
sounds = registry.getKeys();
}
} catch (@Nonnull final Throwable t) {
SuperSoundMuffler.log.error("Couldn't access sound registry for sounds list", t);
}

return sounds;
}

@Override
public void initGui() {
super.initGui();
Expand Down

0 comments on commit e24f880

Please sign in to comment.