diff --git a/build.properties b/build.properties index c18ff2213..2916673c4 100644 --- a/build.properties +++ b/build.properties @@ -4,7 +4,7 @@ mod_id=RTG mod_name=Realistic Terrain Generation mod_desc=Adds a new world type which generates realistic terrain for Overworld biomes. -mod_version=1.1.0 +mod_version=1.1.1 mc_version=1.7.10 mod_url=https://github.com/Team-RTG/Realistic-Terrain-Generation mod_author="Team RTG" diff --git a/etc/config/RTG/rtg.cfg b/etc/config/RTG/rtg.cfg index a6dbf3a27..c287284d2 100644 --- a/etc/config/RTG/rtg.cfg +++ b/etc/config/RTG/rtg.cfg @@ -275,6 +275,11 @@ saplings { "scattered features" { + # Must be set to TRUE for the other scattered feature settings to have any effect. + # If FALSE, RTG won't interfere with scattered feature generation at all. + # [default: true] + B:"Enable Scattered Feature Modifications"=true + # [default: true] B:"Generate Scattered Features"=true diff --git a/src/main/java/rtg/RTG.java b/src/main/java/rtg/RTG.java index ac0800e8d..41b663476 100755 --- a/src/main/java/rtg/RTG.java +++ b/src/main/java/rtg/RTG.java @@ -6,13 +6,19 @@ import net.minecraftforge.common.MinecraftForge; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.Mod.Instance; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStoppedEvent; + import rtg.api.event.BiomeConfigEvent; import rtg.config.BiomeConfigManager; import rtg.config.ConfigManager; import rtg.event.EventManagerRTG; import rtg.event.WorldTypeMessageEventHandler; import rtg.reference.ModInfo; -import rtg.util.Logger; import rtg.util.RealisticBiomePresenceTester; import rtg.world.WorldTypeRTG; import rtg.world.biome.realistic.abyssalcraft.RealisticBiomeACBase; @@ -38,13 +44,6 @@ import rtg.world.gen.structure.MapGenScatteredFeatureRTG; import rtg.world.gen.structure.MapGenVillageRTG; -import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.Mod.EventHandler; -import cpw.mods.fml.common.Mod.Instance; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStoppedEvent; - //@Mod(modid = "RTG", name = "Realistic Terrain Generaton", version = "0.8.0d", dependencies = "required-after:Forge@[10.13.4.1448,)", acceptableRemoteVersions = "*") @Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = "required-after:Forge@[" + ModInfo.FORGE_DEP + ",)" + ModInfo.MOD_DEPS, acceptableRemoteVersions = "*") @@ -56,6 +55,9 @@ public class RTG { public static WorldTypeRTG worldtype; public static EventManagerRTG eventMgr; + private ArrayList oneShotServerCloseActions = new ArrayList<>(); + private ArrayList serverCloseActions = new ArrayList<>(); + private ConfigManager configManager = new ConfigManager(); public ConfigManager configManager(int dimension) { @@ -64,36 +66,37 @@ public ConfigManager configManager(int dimension) { @EventHandler public void preInit(FMLPreInitializationEvent event) - { + { instance = this; - + + worldtype = new WorldTypeRTG("RTG"); + MapGenStructureIO.registerStructure(MapGenScatteredFeatureRTG.Start.class, "rtg_MapGenScatteredFeatureRTG"); MapGenStructureIO.registerStructure(MapGenVillageRTG.Start.class, "rtg_MapGenVillageRTG"); - Logger.info("[FMLPreInitializationEvent] Creating RTG's EventManager"); eventMgr = new EventManagerRTG(); + eventMgr.registerEventHandlers(); + // This event handler unregisters itself, so it doesn't need to be a part of the event management system. MinecraftForge.EVENT_BUS.register(WorldTypeMessageEventHandler.instance); + // Biome configs MUST get initialised before the main config. MinecraftForge.EVENT_BUS.post(new BiomeConfigEvent.Pre()); - - // This MUST get called before the config is initialised. BiomeConfigManager.initBiomeConfigs(); - MinecraftForge.EVENT_BUS.post(new BiomeConfigEvent.Post()); configPath = event.getModConfigurationDirectory() + "/RTG/"; ConfigManager.init(configPath); - - worldtype = new WorldTypeRTG("RTG"); } - -// @EventHandler public void init(FMLInitializationEvent event) {} + + /* + @EventHandler + public void init(FMLInitializationEvent event) {} + */ @EventHandler public void postInit(FMLPostInitializationEvent event) { - RealisticBiomeVanillaBase.addBiomes(); RealisticBiomeBOPBase.addBiomes(); @@ -118,8 +121,8 @@ public void postInit(FMLPostInitializationEvent event) RealisticBiomePresenceTester.doBiomeCheck(); } - -/* + + /* @EventHandler public void serverAboutToStart(FMLServerAboutToStartEvent event) {} @@ -131,8 +134,7 @@ public void serverStarted(FMLServerStartedEvent event) {} @EventHandler public void serverStopping(FMLServerStoppingEvent event) {} -*/ - + */ public void runOnServerClose(Runnable action) { serverCloseActions.add(action); @@ -142,8 +144,6 @@ public void runOnNextServerCloseOnly(Runnable action) { serverCloseActions.add(action); } - private ArrayList oneShotServerCloseActions = new ArrayList<>(); - private ArrayList serverCloseActions = new ArrayList<>(); @EventHandler public void serverStopped(FMLServerStoppedEvent event) { @@ -154,12 +154,5 @@ public void serverStopped(FMLServerStoppedEvent event) action.run(); } oneShotServerCloseActions.clear(); - - if (eventMgr.isRegistered()) { - Logger.info("Unregistering RTG's Terrain Event Handlers..."); - RTG.eventMgr.unRegisterEventHandlers(); - if (!eventMgr.isRegistered()) Logger.info("RTG's Terrain Event Handlers have been unregistered successfully."); - } - } } diff --git a/src/main/java/rtg/config/rtg/ConfigRTG.java b/src/main/java/rtg/config/rtg/ConfigRTG.java index 1c3112afc..f45292fbb 100755 --- a/src/main/java/rtg/config/rtg/ConfigRTG.java +++ b/src/main/java/rtg/config/rtg/ConfigRTG.java @@ -5,11 +5,12 @@ import net.minecraftforge.common.config.Configuration; +import cpw.mods.fml.common.Loader; + import org.apache.commons.lang3.ArrayUtils; import rtg.util.Logger; import rtg.util.ModPresenceTester; -import cpw.mods.fml.common.Loader; public class ConfigRTG { @@ -113,7 +114,8 @@ public class ConfigRTG public static int rtgTreeChance = 2; /* ==================== Scattered Features ==================== */ - + + public static boolean enableScatteredFeatureModifications = true; public static boolean generateScatteredFeatures = true; public static int minDistanceScatteredFeatures = 12; // Vanilla = 8 public static int maxDistanceScatteredFeatures = 48; // Vanilla = 32 @@ -417,7 +419,17 @@ public static void init(File configFile) ); /* ==================== Scattered Features ==================== */ - + + enableScatteredFeatureModifications = config.getBoolean( + "Enable Scattered Feature Modifications", + "Scattered Features", + enableScatteredFeatureModifications, + "Must be set to TRUE for the other scattered feature settings to have any effect." + + Configuration.NEW_LINE + + "If FALSE, RTG won't interfere with scattered feature generation at all." + + Configuration.NEW_LINE + ); + generateScatteredFeatures = config.getBoolean("Generate Scattered Features", "Scattered Features", generateScatteredFeatures, ""); minDistanceScatteredFeatures = config.getInt("Minimum distance between scattered features", "Scattered Features", minDistanceScatteredFeatures, 1, Integer.MAX_VALUE, "Scattered features = desert temples, jungle temples, and witch huts; 8 = Vanilla" + Configuration.NEW_LINE); diff --git a/src/main/java/rtg/event/EventManagerRTG.java b/src/main/java/rtg/event/EventManagerRTG.java index f8f63e416..c39b61ec6 100755 --- a/src/main/java/rtg/event/EventManagerRTG.java +++ b/src/main/java/rtg/event/EventManagerRTG.java @@ -1,20 +1,24 @@ package rtg.event; -import cpw.mods.fml.common.eventhandler.Event.Result; -import cpw.mods.fml.common.eventhandler.EventPriority; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import java.util.ArrayList; +import java.util.Random; +import java.util.WeakHashMap; + import net.minecraft.block.Block; import net.minecraft.init.Blocks; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; + import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.terraingen.InitMapGenEvent; -import net.minecraftforge.event.terraingen.OreGenEvent; -import net.minecraftforge.event.terraingen.SaplingGrowTreeEvent; -import net.minecraftforge.event.terraingen.WorldTypeEvent; +import net.minecraftforge.event.terraingen.*; import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.WorldEvent; -import rtg.RTG; + +import cpw.mods.fml.common.eventhandler.Event.Result; +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + import rtg.config.rtg.ConfigRTG; import rtg.util.Acceptor; import rtg.util.Logger; @@ -29,41 +33,40 @@ import rtg.world.gen.structure.MapGenScatteredFeatureRTG; import rtg.world.gen.structure.MapGenVillageRTG; -import java.util.ArrayList; -import java.util.Random; -import java.util.WeakHashMap; public class EventManagerRTG { - private final LoadChunkRTG LOAD_CHUNK_RTG = new LoadChunkRTG(); - private final GenerateMinableRTG GENERATE_MINABLE_RTG = new GenerateMinableRTG(); - private final InitBiomeGensRTG INIT_BIOME_GENS_RTG = new InitBiomeGensRTG(); - private final InitMapGenRTG INIT_MAP_GEN_RTG = new InitMapGenRTG(); - private final SaplingGrowTreeRTG SAPLING_GROW_TREE_RTG = new SaplingGrowTreeRTG(); - - public final WorldEventRTG WORLD_EVENT_RTG = new WorldEventRTG(); - public final RTGEventRegister RTG_EVENT_REGISTER = new RTGEventRegister(); + // Event handlers. + private final WorldEventRTG WORLD_EVENT_HANDLER = new WorldEventRTG(); + private final LoadChunkRTG LOAD_CHUNK_EVENT_HANDLER = new LoadChunkRTG(); + private final GenerateMinableRTG GENERATE_MINABLE_EVENT_HANDLER = new GenerateMinableRTG(); + private final InitBiomeGensRTG INIT_BIOME_GENS_EVENT_HANDLER = new InitBiomeGensRTG(); + private final InitMapGenRTG INIT_MAP_GEN_EVENT_HANDLER = new InitMapGenRTG(); + private final SaplingGrowTreeRTG SAPLING_GROW_TREE_EVENT_HANDLER = new SaplingGrowTreeRTG(); + private final DecorateBiomeEventRTG DECORATE_BIOME_EVENT_HANDLER = new DecorateBiomeEventRTG(); private WeakHashMap> chunkLoadEvents = new WeakHashMap<>(); - private boolean registered = false; private long worldSeed; - private final String EVENT_SYSTEM = "RTG Event System: "; + private boolean isWorldTypeRTG = true; public EventManagerRTG() { - // These should be registered once, and stay registered -srs - MinecraftForge.TERRAIN_GEN_BUS.register(RTG_EVENT_REGISTER); - MinecraftForge.EVENT_BUS.register(WORLD_EVENT_RTG); - Logger.info(EVENT_SYSTEM + "Initialising EventManagerRTG"); + } public class LoadChunkRTG { LoadChunkRTG() { - Logger.debug(EVENT_SYSTEM + "Initialising LoadChunkRTG"); + logEventMessage("Initialising LoadChunkRTG..."); } @SubscribeEvent public void loadChunkRTG(ChunkEvent.Load event) { + + // Are we in an RTG world? + if (!(event.world.getWorldInfo().getTerrainType() instanceof WorldTypeRTG)) { + return; + } + Acceptor acceptor = chunkLoadEvents.get(event.world.provider.dimensionId); if (acceptor != null) { acceptor.accept(event); @@ -74,12 +77,17 @@ public void loadChunkRTG(ChunkEvent.Load event) { public class GenerateMinableRTG { GenerateMinableRTG() { - Logger.debug(EVENT_SYSTEM + "Initialising GenerateMinableRTG"); + logEventMessage("Initialising GenerateMinableRTG..."); } @SubscribeEvent public void generateMinableRTG(OreGenEvent.GenerateMinable event) { + // Are we in an RTG world? + if (!(event.world.getWorldInfo().getTerrainType() instanceof WorldTypeRTG)) { + return; + } + switch (event.type) { case COAL: @@ -107,22 +115,28 @@ public void generateMinableRTG(OreGenEvent.GenerateMinable event) { return; default: - return; + break; } } } public class InitBiomeGensRTG { - InitBiomeGensRTG() - { - Logger.debug(EVENT_SYSTEM + "Initialising InitBiomeGensRTG"); + InitBiomeGensRTG() { + logEventMessage("Initialising InitBiomeGensRTG..."); } @SubscribeEvent public void initBiomeGensRTG(WorldTypeEvent.InitBiomeGens event) { - if (event.newBiomeGens[0].getClass().getName().contains("GenLayerEB")) return; + // Are we in an RTG world? + if (!(event.worldType instanceof WorldTypeRTG)) { + return; + } + + if (event.newBiomeGens[0].getClass().getName().contains("GenLayerEB")) { + return; + } try { event.newBiomeGens = new RiverRemover().riverLess(event.originalBiomeGens); @@ -136,18 +150,38 @@ public void initBiomeGensRTG(WorldTypeEvent.InitBiomeGens event) { public class InitMapGenRTG { InitMapGenRTG() { - Logger.debug(EVENT_SYSTEM + "Initialising InitMapGenRTG"); + logEventMessage("Initialising InitMapGenRTG..."); } @SubscribeEvent(priority = EventPriority.LOW) public void initMapGenRTG(InitMapGenEvent event) { + // If the Overworld isn't an RTG dimension, then we definitely don't want to get involved here. + // We need to do a try/catch because sometimes this event gets fired before the Overworld has loaded. + try { + if (!(MinecraftServer.getServer().worldServerForDimension(0).getWorldInfo().getTerrainType() instanceof WorldTypeRTG)) { + return; + } + } + catch (Exception e) { + + Logger.debug("Overworld not loaded... checking global variable."); + + // Let's do one last sanity check to make sure it's safe to proceed. + if (!isWorldTypeRTG) { + return; + } + } + Logger.debug("event type = %s", event.type.toString()); Logger.debug("event originalGen = %s", event.originalGen.toString()); switch (event.type) { + case SCATTERED_FEATURE: - event.newGen = new MapGenScatteredFeatureRTG(); + if (ConfigRTG.enableScatteredFeatureModifications) { + event.newGen = new MapGenScatteredFeatureRTG(); + } break; case VILLAGE: @@ -179,7 +213,7 @@ public void initMapGenRTG(InitMapGenEvent event) { public class SaplingGrowTreeRTG { SaplingGrowTreeRTG() { - Logger.debug(EVENT_SYSTEM + "Initialising SaplingGrowTreeRTG"); + logEventMessage("Initialising SaplingGrowTreeRTG..."); } @SubscribeEvent @@ -260,7 +294,7 @@ public void saplingGrowTreeRTG(SaplingGrowTreeEvent event) { tree.crownSize = RandomUtil.getRandomInt(rand, tree.minCrownSize, tree.maxCrownSize); } - /** + /* * Set the generateFlag to what it needs to be for growing trees from saplings, * generate the tree, and then set it back to what it was before. * @@ -294,12 +328,12 @@ public void saplingGrowTreeRTG(SaplingGrowTreeEvent event) { public class WorldEventRTG { WorldEventRTG() { - Logger.debug(EVENT_SYSTEM + "Initialising WorldEventRTG"); + logEventMessage("Initialising WorldEventRTG..."); } @SubscribeEvent public void onWorldLoad(WorldEvent.Load event) { - + // This event fires for each dimension loaded (and then one last time in which it returns 0?), // so initialise a field to 0 and set it to the world seed and only display it in the log once. if (worldSeed != event.world.getSeed() && event.world.getSeed() != 0) { @@ -312,56 +346,52 @@ public void onWorldLoad(WorldEvent.Load event) { @SubscribeEvent public void onWorldUnload(WorldEvent.Unload event) { - // Reset WORLD_SEED so that it logs on the next server start if the seed is the same as the last load. + // Reset the world seed so that it logs on the next server start if the seed is the same as the last load. worldSeed = 0; } } - public class RTGEventRegister + public class DecorateBiomeEventRTG { - RTGEventRegister() { - Logger.debug(EVENT_SYSTEM + "Initialising RTGEventRegister"); + DecorateBiomeEventRTG() { + logEventMessage("Initialising DecorateBiomeEventRTG..."); } @SubscribeEvent - public void registerRTGEventHandlers(WorldTypeEvent.InitBiomeGens event) { - - if (event.worldType instanceof WorldTypeRTG) { - if (!registered) { - Logger.info(EVENT_SYSTEM + "Registering RTG's Terrain Event Handlers..."); - RTG.eventMgr.registerEventHandlers(); - if (registered) Logger.info(EVENT_SYSTEM + "RTG's Terrain Event Handlers have been registered successfully."); - } - } - else { - if (registered) RTG.eventMgr.unRegisterEventHandlers(); - } + public void preBiomeDecorate(DecorateBiomeEvent.Pre event) + { + //Are we in an RTG world? + isWorldTypeRTG = (event.world.getWorldInfo().getTerrainType() instanceof WorldTypeRTG); } } + /* + * This method registers most of RTG's event handlers. + * + * We don't need to check if the event handlers are unregistered before registering them + * because Forge already performs those checks. This means that we could execute this method a + * million times, and each event handler would still only be registered once. + */ public void registerEventHandlers() { - MinecraftForge.EVENT_BUS.register(LOAD_CHUNK_RTG); - MinecraftForge.ORE_GEN_BUS.register(GENERATE_MINABLE_RTG); - MinecraftForge.TERRAIN_GEN_BUS.register(INIT_BIOME_GENS_RTG); - MinecraftForge.TERRAIN_GEN_BUS.register(INIT_MAP_GEN_RTG); - MinecraftForge.TERRAIN_GEN_BUS.register(SAPLING_GROW_TREE_RTG); - registered = true; - } - public void unRegisterEventHandlers() { - MinecraftForge.EVENT_BUS.unregister(LOAD_CHUNK_RTG); - MinecraftForge.ORE_GEN_BUS.unregister(GENERATE_MINABLE_RTG); - MinecraftForge.TERRAIN_GEN_BUS.unregister(INIT_BIOME_GENS_RTG); - MinecraftForge.TERRAIN_GEN_BUS.unregister(INIT_MAP_GEN_RTG); - MinecraftForge.TERRAIN_GEN_BUS.unregister(SAPLING_GROW_TREE_RTG); - registered = false; + logEventMessage("Registering RTG's event handlers..."); + + MinecraftForge.EVENT_BUS.register(WORLD_EVENT_HANDLER); + MinecraftForge.EVENT_BUS.register(LOAD_CHUNK_EVENT_HANDLER); + MinecraftForge.ORE_GEN_BUS.register(GENERATE_MINABLE_EVENT_HANDLER); + MinecraftForge.TERRAIN_GEN_BUS.register(INIT_BIOME_GENS_EVENT_HANDLER); + MinecraftForge.TERRAIN_GEN_BUS.register(INIT_MAP_GEN_EVENT_HANDLER); + MinecraftForge.TERRAIN_GEN_BUS.register(SAPLING_GROW_TREE_EVENT_HANDLER); + MinecraftForge.TERRAIN_GEN_BUS.register(DECORATE_BIOME_EVENT_HANDLER); + + logEventMessage("RTG's event handlers have been registered successfully."); } public void setDimensionChunkLoadEvent(int dimension, Acceptor action) { chunkLoadEvents.put(dimension, action); } - public boolean isRegistered() { - return registered; + private static void logEventMessage(String message) { + Logger.debug("RTG Event System: " + message); } } \ No newline at end of file