Skip to content

Commit

Permalink
Fix random crashes with Just Another Spawner mod (#103)
Browse files Browse the repository at this point in the history
* Fix load order hack

* Add some logs
  • Loading branch information
kuba6000 authored Nov 22, 2024
1 parent 1eb32c8 commit 5b3dfed
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/com/kuba6000/mobsinfo/MobsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class MobsInfo {
public static final String MODNAME = "MobsInfo";
@Mod.Instance
public static MobsInfo instance;
public static ModContainer container;

public static final SimpleNetworkWrapper NETWORK = new SimpleNetworkWrapper(MODID);

Expand All @@ -83,30 +84,35 @@ public class MobsInfo {
@SidedProxy(clientSide = "com.kuba6000.mobsinfo.ClientProxy", serverSide = "com.kuba6000.mobsinfo.CommonProxy")
public static CommonProxy proxy;

private static EventBus masterEventBus;

@Subscribe
public void iAmDependingOnEverything(FMLEvent event) {
if (event instanceof FMLPreInitializationEvent) {
ModContainer activecontainer = Loader.instance()
.activeModContainer();
LOG.info("I Am Depending On Everything -> reordering mod load order!");
List<ModContainer> list = Loader.instance()
.getActiveModList();
list.remove(activecontainer);
list.add(activecontainer);
list.remove(container);
list.add(container);
masterEventBus.unregister(this);
}
}

@Mod.EventHandler
public void construction(FMLConstructionEvent event) {
container = Loader.instance()
.activeModContainer();
// hack into load order only if JustAnotherSpawner mod is loaded
if (!Loader.isModLoaded("JustAnotherSpawner")) return;
LOG.info("Found JustAnotherSpawner mod, hacking load order");
try {
Field loaderControllerField = Loader.class.getDeclaredField("modController");
loaderControllerField.setAccessible(true);
LoadController controller = (LoadController) loaderControllerField.get(Loader.instance());
Field masterEventBus = LoadController.class.getDeclaredField("masterChannel");
masterEventBus.setAccessible(true);
EventBus bus = (EventBus) masterEventBus.get(controller);
bus.register(this);
Field masterEventBusField = LoadController.class.getDeclaredField("masterChannel");
masterEventBusField.setAccessible(true);
masterEventBus = (EventBus) masterEventBusField.get(controller);
masterEventBus.register(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
//
}
Expand Down

0 comments on commit 5b3dfed

Please sign in to comment.