mirror of
https://github.com/GTMEGA/EndlessIDs.git
synced 2026-11-18 07:59:11 +00:00
externalize patching logic a bit
This commit is contained in:
6 files changed
+135
-21
No files matched your search
@@ -1,14 +1,13 @@
|
||||
package com.falsepattern.endlessids;
|
||||
|
||||
import code.elix_x.coremods.antiidconflict.managers.BiomesManager;
|
||||
import com.falsepattern.endlessids.constants.ExtendedConstants;
|
||||
import lombok.SneakyThrows;
|
||||
import com.falsepattern.endlessids.patching.CommonManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
@Mod(modid = Tags.MODID,
|
||||
@@ -20,29 +19,23 @@ public class EndlessIDs {
|
||||
public static final byte[] BIOME_ARRAY_PLACEHOLDER = new byte[0];
|
||||
public static final Logger LOG = LogManager.getLogger(Tags.MODNAME);
|
||||
|
||||
private static void antiIdConflictLatePatch() {
|
||||
BiomesManager.conflicts = new BiomesManager.ConflictingBiomes[ExtendedConstants.biomeIDCount];
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger earlier biome registration for tropicraft so that it can be caught by AntiIDConflict.
|
||||
*/
|
||||
@SneakyThrows
|
||||
private static void tropicraftInitPatch() {
|
||||
Class.forName("net.tropicraft.world.biomes.BiomeGenTropicraft");
|
||||
}
|
||||
@SidedProxy(clientSide = Tags.GROUPNAME + ".patching.ClientManager",
|
||||
serverSide = Tags.GROUPNAME + ".patching.ServerManager",
|
||||
modId = Tags.MODID)
|
||||
private static CommonManager patchManager;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
if (Loader.isModLoaded("antiidconflict")) {
|
||||
antiIdConflictLatePatch();
|
||||
}
|
||||
patchManager.preInit();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent e) {
|
||||
if (Loader.isModLoaded("tropicraft")) {
|
||||
tropicraftInitPatch();
|
||||
}
|
||||
patchManager.init();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void postInit(FMLPostInitializationEvent e) {
|
||||
patchManager.postInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.falsepattern.endlessids.patching;
|
||||
|
||||
public class ClientManager extends CommonManager {
|
||||
public ClientManager() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.falsepattern.endlessids.patching;
|
||||
|
||||
import com.falsepattern.endlessids.EndlessIDs;
|
||||
import com.falsepattern.endlessids.patching.patches.common.Tropicraft;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommonManager {
|
||||
protected final List<Patch> patches = new ArrayList<>();
|
||||
|
||||
public CommonManager() {
|
||||
patches.add(new Tropicraft());
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public final void preInit() {
|
||||
for (val patch : patches) {
|
||||
if (Loader.isModLoaded(patch.modid)) {
|
||||
try {
|
||||
if (patch.preInit()) {
|
||||
EndlessIDs.LOG.info("Applied preInit patches for " + patch.modid);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
EndlessIDs.LOG.fatal("Failed to apply preInit patches for " + patch.modid, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public final void init() {
|
||||
for (val patch : patches) {
|
||||
if (Loader.isModLoaded(patch.modid)) {
|
||||
try {
|
||||
if (patch.init()) {
|
||||
EndlessIDs.LOG.info("Applied init patches for " + patch.modid);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
EndlessIDs.LOG.fatal("Failed to apply init patches for " + patch.modid, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public final void postInit() {
|
||||
for (val patch : patches) {
|
||||
if (Loader.isModLoaded(patch.modid)) {
|
||||
try {
|
||||
if (patch.postInit()) {
|
||||
EndlessIDs.LOG.info("Applied postInit patches for " + patch.modid);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
EndlessIDs.LOG.fatal("Failed to apply postInit patches for " + patch.modid, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.falsepattern.endlessids.patching;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class Patch {
|
||||
public final String modid;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public boolean preInit() throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public boolean init() throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public boolean postInit() throws Exception {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.falsepattern.endlessids.patching;
|
||||
|
||||
public class ServerManager extends CommonManager {
|
||||
public ServerManager() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.falsepattern.endlessids.patching.patches.common;
|
||||
|
||||
import com.falsepattern.endlessids.patching.Patch;
|
||||
|
||||
public class Tropicraft extends Patch {
|
||||
public Tropicraft() {
|
||||
super("tropicraft");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init() throws ClassNotFoundException {
|
||||
Class.forName("net.tropicraft.world.biomes.BiomeGenTropicraft");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user