Skip to content

Commit

Permalink
Merge pull request #1 from eigenraven/fix-classloading
Browse files Browse the repository at this point in the history
Fix Config loading the main mod classes too early, breaking lwjgl3ify's transformers
  • Loading branch information
mist475 authored Sep 3, 2023
2 parents ca02fc3 + 33bb8dc commit 932cb30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
35 changes: 7 additions & 28 deletions src/main/java/com/sonicether/soundphysics/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
import java.util.ArrayList;
import java.util.List;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import cpw.mods.fml.client.config.IConfigElement;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class Config {

public static final Config instance;
public static final Config instance = new Config();
private Configuration forgeConfig;

// general
Expand Down Expand Up @@ -63,34 +58,14 @@ public class Config {
private static final String categoryCompatibility = "Compatibility";
private static final String categoryMisc = "Misc";

static {
instance = new Config();
}

private Config() {
}

public void preInit(final FMLPreInitializationEvent event) {
this.forgeConfig = new Configuration(event.getSuggestedConfigurationFile());
syncConfig();
}

public void setConfig(Configuration config) {
this.forgeConfig = config;
syncConfig();
}

public void init(final FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
}

@SubscribeEvent
public void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
if (eventArgs.modID.equals(SoundPhysics.modid)) {
syncConfig();
}
}

@SuppressWarnings("rawtypes")
public List<IConfigElement> getConfigElements() {
final ArrayList<IConfigElement> list = new ArrayList<>();
Expand All @@ -104,7 +79,10 @@ public List<IConfigElement> getConfigElements() {
return list;
}

private void syncConfig() {
/**
* @return If the configuration has changed.
*/
public boolean syncConfig() {
// General
rolloffFactor = this.forgeConfig.getFloat("Attenuation Factor", categoryGeneral, 1.0f, 0.2f, 1.0f,
"Affects how quiet a sound gets based on distance. Lower values mean distant sounds are louder. 1.0 is the physically correct value.");
Expand Down Expand Up @@ -183,8 +161,9 @@ private void syncConfig() {

if (this.forgeConfig.hasChanged()) {
this.forgeConfig.save();
SoundPhysics.applyConfigChanges();
return true;
}
return false;
}

}
17 changes: 15 additions & 2 deletions src/main/java/com/sonicether/soundphysics/SoundPhysics.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.sonicether.soundphysics;

import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
Expand All @@ -12,6 +14,7 @@
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.BufferUtils;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.AL11;
Expand Down Expand Up @@ -50,12 +53,22 @@ public class SoundPhysics {

@Mod.EventHandler
public void preInit(final FMLPreInitializationEvent event) {
Config.instance.preInit(event);
Config.instance.syncConfig();
applyConfigChanges();
}

@Mod.EventHandler
public void init(final FMLInitializationEvent event) {
Config.instance.init(event);
MinecraftForge.EVENT_BUS.register(this);
}

@SubscribeEvent
public void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
if (eventArgs.modID.equals(SoundPhysics.modid)) {
if(Config.instance.syncConfig()) {
applyConfigChanges();
}
}
}

private static final String logPrefix = "[SOUND PHYSICS]";
Expand Down

0 comments on commit 932cb30

Please sign in to comment.