From 88654e3ad2b2814679ad4340ac38e8f220332dbe Mon Sep 17 00:00:00 2001 From: Mist475 Date: Sun, 20 Aug 2023 12:38:49 +0200 Subject: [PATCH] fix using lotr code without proxy --- .../blockartistry/mod/DynSurround/Module.java | 25 +++++++++++++---- .../mod/DynSurround/compat/ILOTRProxy.java | 5 ++++ .../mod/DynSurround/compat/LotrProxy.java | 10 +++++++ .../mod/DynSurround/compat/NoLotrProxy.java | 8 ++++++ .../DynSurround/data/DimensionRegistry.java | 27 +++++++++---------- 5 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/blockartistry/mod/DynSurround/compat/ILOTRProxy.java create mode 100644 src/main/java/org/blockartistry/mod/DynSurround/compat/LotrProxy.java create mode 100644 src/main/java/org/blockartistry/mod/DynSurround/compat/NoLotrProxy.java diff --git a/src/main/java/org/blockartistry/mod/DynSurround/Module.java b/src/main/java/org/blockartistry/mod/DynSurround/Module.java index 7aee8a7..e55f5ac 100644 --- a/src/main/java/org/blockartistry/mod/DynSurround/Module.java +++ b/src/main/java/org/blockartistry/mod/DynSurround/Module.java @@ -24,11 +24,6 @@ package org.blockartistry.mod.DynSurround; -import java.io.File; - -import org.apache.logging.log4j.LogManager; -import org.blockartistry.mod.DynSurround.proxy.Proxy; - import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; @@ -39,6 +34,12 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.common.config.Configuration; +import org.apache.logging.log4j.LogManager; +import org.blockartistry.mod.DynSurround.compat.ILOTRProxy; +import org.blockartistry.mod.DynSurround.compat.NoLotrProxy; +import org.blockartistry.mod.DynSurround.proxy.Proxy; + +import java.io.File; @Mod(modid = Module.MOD_ID, useMetadata = true, dependencies = Module.DEPENDENCIES, version = Module.VERSION, guiFactory = Module.GUI_FACTORY) public class Module { @@ -48,6 +49,10 @@ public class Module { public static final String DEPENDENCIES = "required-after:Forge@[10.13.4.1614,);required-after:gtnhmixins@[2.0.0,)"; public static final String GUI_FACTORY = "org.blockartistry.mod.DynSurround.client.gui.ConfigGuiFactory"; + public static final String LOTR_PROXY_LOCATION = "org.blockartistry.mod.DynSurround.compat.ILotrProxy"; + + public static ILOTRProxy LOTR_PROXY; + @Instance(MOD_ID) protected static Module instance; @@ -105,6 +110,16 @@ public void init(final FMLInitializationEvent event) { @EventHandler public void postInit(final FMLPostInitializationEvent event) { proxy.postInit(event); + if (Proxy.LOTR) { + try { + LOTR_PROXY = Class.forName(LOTR_PROXY_LOCATION).asSubclass(ILOTRProxy.class).newInstance(); + } + catch (ClassNotFoundException | InstantiationException | IllegalAccessException ignored) { + LOTR_PROXY = new NoLotrProxy(); + } + } else { + LOTR_PROXY = new NoLotrProxy(); + } config.save(); } diff --git a/src/main/java/org/blockartistry/mod/DynSurround/compat/ILOTRProxy.java b/src/main/java/org/blockartistry/mod/DynSurround/compat/ILOTRProxy.java new file mode 100644 index 0000000..87f1f07 --- /dev/null +++ b/src/main/java/org/blockartistry/mod/DynSurround/compat/ILOTRProxy.java @@ -0,0 +1,5 @@ +package org.blockartistry.mod.DynSurround.compat; + +public interface ILOTRProxy { + String getSeason(); +} diff --git a/src/main/java/org/blockartistry/mod/DynSurround/compat/LotrProxy.java b/src/main/java/org/blockartistry/mod/DynSurround/compat/LotrProxy.java new file mode 100644 index 0000000..6e46724 --- /dev/null +++ b/src/main/java/org/blockartistry/mod/DynSurround/compat/LotrProxy.java @@ -0,0 +1,10 @@ +package org.blockartistry.mod.DynSurround.compat; + +import lotr.common.LOTRDate; + +public class LotrProxy implements ILOTRProxy { + @Override + public String getSeason() { + return LOTRDate.ShireReckoning.getSeason().name(); + } +} diff --git a/src/main/java/org/blockartistry/mod/DynSurround/compat/NoLotrProxy.java b/src/main/java/org/blockartistry/mod/DynSurround/compat/NoLotrProxy.java new file mode 100644 index 0000000..2a92dba --- /dev/null +++ b/src/main/java/org/blockartistry/mod/DynSurround/compat/NoLotrProxy.java @@ -0,0 +1,8 @@ +package org.blockartistry.mod.DynSurround.compat; + +public class NoLotrProxy implements ILOTRProxy{ + @Override + public String getSeason() { + return "noseason"; + } +} diff --git a/src/main/java/org/blockartistry/mod/DynSurround/data/DimensionRegistry.java b/src/main/java/org/blockartistry/mod/DynSurround/data/DimensionRegistry.java index 47a9cb3..0e48515 100644 --- a/src/main/java/org/blockartistry/mod/DynSurround/data/DimensionRegistry.java +++ b/src/main/java/org/blockartistry/mod/DynSurround/data/DimensionRegistry.java @@ -23,17 +23,6 @@ package org.blockartistry.mod.DynSurround.data; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import lotr.common.LOTRDate; -import org.blockartistry.mod.DynSurround.ModLog; -import org.blockartistry.mod.DynSurround.ModOptions; -import org.blockartistry.mod.DynSurround.Module; -import org.blockartistry.mod.DynSurround.data.config.DimensionConfig; -import org.blockartistry.mod.DynSurround.util.DiurnalUtils; - import cpw.mods.fml.common.Loader; import foxie.calendar.api.CalendarAPI; import foxie.calendar.api.ICalendarProvider; @@ -43,13 +32,21 @@ import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldType; import net.minecraftforge.common.DimensionManager; +import org.blockartistry.mod.DynSurround.ModLog; +import org.blockartistry.mod.DynSurround.ModOptions; +import org.blockartistry.mod.DynSurround.Module; +import org.blockartistry.mod.DynSurround.data.config.DimensionConfig; +import org.blockartistry.mod.DynSurround.proxy.Proxy; +import org.blockartistry.mod.DynSurround.util.DiurnalUtils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; public final class DimensionRegistry implements Comparable { private static final int SPACE_HEIGHT_OFFSET = 32; private static final boolean CALENDAR_API = Loader.isModLoaded("CalendarAPI"); - //Lotr has its own date system - private static final boolean LOTR = Loader.isModLoaded("lotr"); private static final String SEASON_NOT_AVAILABLE = "noseason"; private static final List cache = new ArrayList<>(); @@ -220,8 +217,8 @@ public boolean getHasWeather() { public String getSeason() { //TODO: lotr shire reckoning -> CalenderAPI bridge in MistLotrTweaks - if (LOTR && this.name.equals("MiddleEarth")) { - return LOTRDate.ShireReckoning.getSeason().name(); + if (Proxy.LOTR && this.name.equals("MiddleEarth")) { + return Module.LOTR_PROXY.getSeason(); } if (!CALENDAR_API) { return SEASON_NOT_AVAILABLE;