Skip to content

Commit

Permalink
Add button to refresh the sounds (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexdoru authored Nov 10, 2024
1 parent 6967ed6 commit 8b68289
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mitchej123.hodgepodge.Common;
import com.mitchej123.hodgepodge.Compat;
import com.mitchej123.hodgepodge.client.handlers.ClientKeyListener;
import com.mitchej123.hodgepodge.client.handlers.ReloadSoundsGui;
import com.mitchej123.hodgepodge.config.DebugConfig;
import com.mitchej123.hodgepodge.config.FixesConfig;
import com.mitchej123.hodgepodge.config.TweaksConfig;
Expand Down Expand Up @@ -44,6 +45,8 @@ public static void postInit() {
FMLCommonHandler.instance().bus().register(ClientTicker.INSTANCE);
ClientRegistry.registerKeyBinding(ClientKeyListener.FastBlockPlacingKey);

MinecraftForge.EVENT_BUS.register(new ReloadSoundsGui());

if (TweaksConfig.addSystemInfo) {
MinecraftForge.EVENT_BUS.register(DebugScreenHandler.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.mitchej123.hodgepodge.client.handlers;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreenOptionsSounds;
import net.minecraft.util.StatCollector;
import net.minecraftforge.client.event.GuiScreenEvent;

import com.mitchej123.hodgepodge.config.TweaksConfig;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class ReloadSoundsGui {

private static final int BUTTON_ID = 51861;

@SubscribeEvent
public void onInitGui(GuiScreenEvent.InitGuiEvent.Post event) {
if (TweaksConfig.reloadSoundsButton && event.gui instanceof GuiScreenOptionsSounds) {
int posX = event.gui.width / 2 - 100;
int posY = 0;
for (Object o : event.buttonList) {
if (o instanceof GuiButton guiButton
&& o.getClass().getName().endsWith("GuiScreenOptionsSounds$Button")) {
posY = Math.max(posY, guiButton.yPosition);
}
}
if (posY == 0) {
posY = event.gui.height / 6 + 168 - (20 + 4) * 2;
}
posY += 20 + 4;
event.buttonList.add(
new GuiButton(
BUTTON_ID,
posX,
posY,
StatCollector.translateToLocal("hodgepodge.soundsmenu.refreshsounds")));
}
}

@SubscribeEvent
public void onClick(GuiScreenEvent.ActionPerformedEvent.Post event) {
if (TweaksConfig.reloadSoundsButton && event.gui instanceof GuiScreenOptionsSounds) {
if (event.button.id == BUTTON_ID) {
Minecraft mc = Minecraft.getMinecraft();
mc.getSoundHandler().onResourceManagerReload(mc.getResourceManager());
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class TweaksConfig {

// Minecraft

@Config.Comment("Adds a button in the sounds menu to reload the sound system without needing to press F3 + S")
@Config.DefaultBoolean(true)
public static boolean reloadSoundsButton;

@Config.Comment("Adds system info to the F3 overlay (Java version and vendor; GPU name; OpenGL version; CPU cores; OS name, version and architecture)")
@Config.DefaultBoolean(true)
public static boolean addSystemInfo;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/hodgepodge/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ tile.doublePlant.name=Large Plant
item.dyePowder.name=Dye
item.skull.name=Skull
item.fish.name=Fish

hodgepodge.soundsmenu.refreshsounds=Refresh Sounds

0 comments on commit 8b68289

Please sign in to comment.