mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
Clean Up Module System
This commit is contained in:
1 parent
26f44a2862
commit
11e8a06a48
14 files changed
+263
-265
No files matched your search
@@ -114,18 +114,19 @@ public class Forestry {
|
||||
MinecraftForge.EVENT_BUS.post(new ForestryEvent.PreInit(this, event));
|
||||
|
||||
ModuleManager.runSetup(event);
|
||||
ModuleManager.getInternalHandler().runSetup();
|
||||
|
||||
String gameMode = Config.gameMode;
|
||||
Preconditions.checkState(gameMode != null);
|
||||
ForestryAPI.activeMode = new GameMode(gameMode);
|
||||
|
||||
ModuleManager.runPreInit(event.getSide());
|
||||
ModuleManager.getInternalHandler().runPreInit(event.getSide());
|
||||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerModels(ModelRegistryEvent event) {
|
||||
ModuleManager.runRegisterBackpacksAndCrates();
|
||||
ModuleManager.getInternalHandler().runRegisterBackpacksAndCrates();
|
||||
Proxies.render.registerModels();
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ public class Forestry {
|
||||
// Register gui handler
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());
|
||||
|
||||
ModuleManager.runInit();
|
||||
ModuleManager.getInternalHandler().runInit();
|
||||
|
||||
Proxies.render.registerItemAndBlockColors();
|
||||
AdvancementManager.registerTriggers();
|
||||
@@ -142,7 +143,7 @@ public class Forestry {
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
ModuleManager.runPostInit();
|
||||
ModuleManager.getInternalHandler().runPostInit();
|
||||
|
||||
// Register world generator
|
||||
WorldGenerator worldGenerator = new WorldGenerator();
|
||||
@@ -152,7 +153,7 @@ public class Forestry {
|
||||
Proxies.common.registerTickHandlers(worldGenerator);
|
||||
|
||||
// Handle IMC messages.
|
||||
ModuleManager.processIMCMessages(FMLInterModComms.fetchRuntimeMessages(ForestryAPI.instance));
|
||||
ModuleManager.getInternalHandler().processIMCMessages(FMLInterModComms.fetchRuntimeMessages(ForestryAPI.instance));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -167,6 +168,6 @@ public class Forestry {
|
||||
|
||||
@EventHandler
|
||||
public void processIMCMessages(IMCEvent event) {
|
||||
ModuleManager.processIMCMessages(event.getMessages());
|
||||
ModuleManager.getInternalHandler().processIMCMessages(event.getMessages());
|
||||
}
|
||||
}
|
||||
@@ -75,18 +75,6 @@ public interface IForestryModule {
|
||||
default void registerTriggers() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to register items to the backpack via the {@link forestry.api.storage.IBackpackInterface}.
|
||||
*/
|
||||
default void registerBackpackItems() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to register crates via the {@link forestry.api.storage.ICrateRegistry}.
|
||||
*/
|
||||
default void registerCrates() {
|
||||
}
|
||||
|
||||
default void doInit() {
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.modules;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
public interface IModuleContainer {
|
||||
@@ -25,7 +27,7 @@ public interface IModuleContainer {
|
||||
/**
|
||||
* Called after configured the modules.
|
||||
*/
|
||||
default void onConfiguredModules(IModuleHandler handler){
|
||||
default void onConfiguredModules(Collection<IForestryModule> activeModules, Collection<IForestryModule> unloadedModules){
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package forestry.api.modules;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface IModuleHandler {
|
||||
|
||||
void runSetup();
|
||||
|
||||
void runPreInit();
|
||||
|
||||
void runInit();
|
||||
|
||||
void runPostInit();
|
||||
|
||||
Collection<IForestryModule> getModules();
|
||||
}
|
||||
@@ -24,11 +24,12 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.MigrationHelper;
|
||||
import forestry.modules.InternalModuleHandler;
|
||||
import forestry.modules.ModuleManager;
|
||||
|
||||
public abstract class BlockRegistry {
|
||||
protected <T extends Block> void registerBlock(T block, @Nullable ItemBlock itemBlock, String name) {
|
||||
if (ModuleManager.getStage() != ModuleManager.Stage.REGISTER) {
|
||||
if (ModuleManager.getInternalHandler().getStage() != InternalModuleHandler.Stage.REGISTER) {
|
||||
throw new RuntimeException("Tried to register Block outside of REGISTER");
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,12 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.MigrationHelper;
|
||||
import forestry.modules.InternalModuleHandler;
|
||||
import forestry.modules.ModuleManager;
|
||||
|
||||
public abstract class ItemRegistry {
|
||||
protected static <T extends Item> T registerItem(T item, String name) {
|
||||
if (ModuleManager.getStage() != ModuleManager.Stage.REGISTER) {
|
||||
if (ModuleManager.getInternalHandler().getStage() != InternalModuleHandler.Stage.REGISTER) {
|
||||
throw new RuntimeException("Tried to register Item outside of REGISTER");
|
||||
}
|
||||
|
||||
|
||||
@@ -53,17 +53,17 @@ public class WorldGenerator implements IWorldGenerator {
|
||||
@SubscribeEvent
|
||||
public void populateChunk(PopulateChunkEvent.Post event) {
|
||||
// / PLUGIN WORLD GENERATION
|
||||
ModuleManager.populateChunk(event.getGen(), event.getWorld(), event.getRand(), event.getChunkX(), event.getChunkZ(), event.isHasVillageGenerated());
|
||||
ModuleManager.getInternalHandler().populateChunk(event.getGen(), event.getWorld(), event.getRand(), event.getChunkX(), event.getChunkZ(), event.isHasVillageGenerated());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void decorateBiome(DecorateBiomeEvent.Post event) {
|
||||
ModuleManager.decorateBiome(event.getWorld(), event.getRand(), event.getPos());
|
||||
ModuleManager.getInternalHandler().decorateBiome(event.getWorld(), event.getRand(), event.getPos());
|
||||
}
|
||||
|
||||
public void retroGen(Random random, int chunkX, int chunkZ, World world) {
|
||||
generateWorld(random, chunkX, chunkZ, world);
|
||||
ModuleManager.populateChunkRetroGen(world, random, chunkX, chunkZ);
|
||||
ModuleManager.getInternalHandler().populateChunkRetroGen(world, random, chunkX, chunkZ);
|
||||
world.getChunkFromChunkCoords(chunkX, chunkZ).markDirty();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,18 @@ public class BlankForestryModule implements IForestryModule {
|
||||
public void decorateBiome(World world, Random rand, BlockPos pos){
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to register items to the backpack via the {@link forestry.api.storage.IBackpackInterface}.
|
||||
*/
|
||||
public void registerBackpackItems() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to register crates via the {@link forestry.api.storage.ICrateRegistry}.
|
||||
*/
|
||||
public void registerCrates() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to hide items in JEI.
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forestry.modules;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
@@ -46,4 +47,9 @@ public class ForestryModules implements IModuleContainer {
|
||||
Property prop = getModulesConfig().get(CONFIG_CATEGORY, info.moduleID(), true, comment);
|
||||
return prop.getBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfiguredModules(Collection<IForestryModule> activeModules, Collection<IForestryModule> unloadedModules) {
|
||||
ModuleManager.getInternalHandler().addModules(activeModules, unloadedModules);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package forestry.modules;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.IChunkGenerator;
|
||||
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import forestry.api.modules.IForestryModule;
|
||||
import forestry.core.IPickupHandler;
|
||||
import forestry.core.IResupplyHandler;
|
||||
import forestry.core.ISaveEventHandler;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
public class InternalModuleHandler {
|
||||
|
||||
public enum Stage {
|
||||
SETUP, // setup API to make it functional. GameMode Configs are not yet accessible
|
||||
SETUP_DISABLED, // setup fallback API to avoid crashes
|
||||
REGISTER, // register basic blocks and items
|
||||
PRE_INIT, // register handlers, triggers, definitions, and anything that depends on basic items
|
||||
BACKPACKS_CRATES, // backpacks, crates
|
||||
INIT, // anything that depends on PreInit stages, recipe registration
|
||||
POST_INIT, // stubborn mod integration, dungeon loot, and finalization of things that take input from mods
|
||||
FINISHED
|
||||
}
|
||||
|
||||
protected final Set<BlankForestryModule> modules = new LinkedHashSet();
|
||||
protected final Set<IForestryModule> disabledModules = new LinkedHashSet();
|
||||
protected final ModuleManager moduleManager;
|
||||
private Stage stage = Stage.SETUP;
|
||||
|
||||
public InternalModuleHandler(ModuleManager moduleManager) {
|
||||
this.moduleManager = moduleManager;
|
||||
}
|
||||
|
||||
public void addModules(Collection<IForestryModule> modules, Collection<IForestryModule> disabledModules) {
|
||||
if (stage != Stage.SETUP) {
|
||||
throw new RuntimeException("Tried to register Modules outside of SETUP");
|
||||
}
|
||||
for(IForestryModule module : modules) {
|
||||
if(!(module instanceof BlankForestryModule)){
|
||||
continue;
|
||||
}
|
||||
this.modules.add((BlankForestryModule) module);
|
||||
}
|
||||
this.disabledModules.addAll(disabledModules);
|
||||
}
|
||||
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
public void runSetup() {
|
||||
stage = Stage.SETUP;
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Setup API Start: {}", module);
|
||||
module.setupAPI();
|
||||
Log.debug("Setup API Complete: {}", module);
|
||||
}
|
||||
stage = Stage.SETUP_DISABLED;
|
||||
for (IForestryModule module : disabledModules) {
|
||||
Log.debug("Disabled-Setup Start: {}", module);
|
||||
module.disabledSetupAPI();
|
||||
Log.debug("Disabled-Setup Complete: {}", module);
|
||||
}
|
||||
stage = Stage.REGISTER;
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Register Items and Blocks Start: {}", module);
|
||||
module.registerItemsAndBlocks();
|
||||
Log.debug("Register Items and Blocks Complete: {}", module);
|
||||
}
|
||||
}
|
||||
|
||||
public void runPreInit(Side side) {
|
||||
stage = Stage.PRE_INIT;
|
||||
for (BlankForestryModule module : modules) {
|
||||
Log.debug("Pre-Init Start: {}", module);
|
||||
registerHandlers(module, side);
|
||||
module.preInit();
|
||||
if (moduleManager.isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.BUILDCRAFT_STATEMENTS)) {
|
||||
module.registerTriggers();
|
||||
}
|
||||
Log.debug("Pre-Init Complete: {}", module);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerHandlers(BlankForestryModule module, Side side) {
|
||||
Log.debug("Registering Handlers for Module: {}", module);
|
||||
|
||||
IPacketRegistry packetRegistry = module.getPacketRegistry();
|
||||
if (packetRegistry != null) {
|
||||
packetRegistry.registerPacketsServer();
|
||||
if (side == Side.CLIENT) {
|
||||
packetRegistry.registerPacketsClient();
|
||||
}
|
||||
}
|
||||
|
||||
IPickupHandler pickupHandler = module.getPickupHandler();
|
||||
if (pickupHandler != null) {
|
||||
ModuleManager.pickupHandlers.add(pickupHandler);
|
||||
}
|
||||
|
||||
ISaveEventHandler saveHandler = module.getSaveEventHandler();
|
||||
if (saveHandler != null) {
|
||||
ModuleManager.saveEventHandlers.add(saveHandler);
|
||||
}
|
||||
|
||||
IResupplyHandler resupplyHandler = module.getResupplyHandler();
|
||||
if (resupplyHandler != null) {
|
||||
ModuleManager.resupplyHandlers.add(resupplyHandler);
|
||||
}
|
||||
}
|
||||
|
||||
public void runInit() {
|
||||
stage = Stage.INIT;
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Init Start: {}", module);
|
||||
module.doInit();
|
||||
module.registerRecipes();
|
||||
Log.debug("Init Complete: {}", module);
|
||||
}
|
||||
}
|
||||
|
||||
public void runPostInit() {
|
||||
stage = Stage.POST_INIT;
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Post-Init Start: {}", module);
|
||||
module.postInit();
|
||||
Log.debug("Post-Init Complete: {}", module);
|
||||
}
|
||||
stage = Stage.FINISHED;
|
||||
}
|
||||
|
||||
public void runRegisterBackpacksAndCrates() {
|
||||
stage = Stage.BACKPACKS_CRATES;
|
||||
for (BlankForestryModule module : modules) {
|
||||
if (moduleManager.isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.BACKPACKS)) {
|
||||
Log.debug("Backpacks Start: {}", module);
|
||||
module.registerBackpackItems();
|
||||
Log.debug("Backpacks Complete: {}", module);
|
||||
}
|
||||
|
||||
if (moduleManager.isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.CRATE)) {
|
||||
Log.debug("Crates Start: {}", module);
|
||||
module.registerCrates();
|
||||
Log.debug("Crates Complete: {}", module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void processIMCMessages(ImmutableList<FMLInterModComms.IMCMessage> messages) {
|
||||
for (FMLInterModComms.IMCMessage message : messages) {
|
||||
for (BlankForestryModule module : modules) {
|
||||
if (module.processIMCMessage(message)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void populateChunk(IChunkGenerator chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) {
|
||||
for (BlankForestryModule module : modules) {
|
||||
module.populateChunk(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
|
||||
}
|
||||
}
|
||||
|
||||
public void decorateBiome(World world, Random rand, BlockPos pos) {
|
||||
for (BlankForestryModule module : modules) {
|
||||
module.decorateBiome(world, rand, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ) {
|
||||
for (BlankForestryModule module : modules) {
|
||||
module.populateChunkRetroGen(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getHiddenItems() {
|
||||
List<ItemStack> hiddenItems = new ArrayList<>();
|
||||
for (BlankForestryModule module : modules) {
|
||||
module.getHiddenItems(hiddenItems);
|
||||
}
|
||||
return hiddenItems;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package forestry.modules;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
import forestry.api.modules.IForestryModule;
|
||||
import forestry.api.modules.IModuleHandler;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
public class ModuleHandler implements IModuleHandler {
|
||||
|
||||
private final Set<IForestryModule> modules;
|
||||
private final ModuleManager manager;
|
||||
|
||||
public ModuleHandler(Collection<IForestryModule> modules, ModuleManager manager) {
|
||||
this.modules = ImmutableSet.copyOf(modules);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public void runSetup() {
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Setup API Start: {}", module);
|
||||
module.setupAPI();
|
||||
Log.debug("Setup API Complete: {}", module);
|
||||
}
|
||||
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Disabled-Setup Start: {}", module);
|
||||
module.disabledSetupAPI();
|
||||
Log.debug("Disabled-Setup Complete: {}", module);
|
||||
}
|
||||
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Register Items and Blocks Start: {}", module);
|
||||
module.registerItemsAndBlocks();
|
||||
Log.debug("Register Items and Blocks Complete: {}", module);
|
||||
}
|
||||
}
|
||||
|
||||
public void runPreInit() {
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Pre-Init Start: {}", module);
|
||||
if(module instanceof BlankForestryModule) {
|
||||
BlankForestryModule moduleInternal = (BlankForestryModule) module;
|
||||
ModuleManager.registerHandlers(moduleInternal, FMLCommonHandler.instance().getEffectiveSide());
|
||||
}
|
||||
module.preInit();
|
||||
if (manager.isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.BUILDCRAFT_STATEMENTS)) {
|
||||
module.registerTriggers();
|
||||
}
|
||||
Log.debug("Pre-Init Complete: {}", module);
|
||||
}
|
||||
}
|
||||
|
||||
public void runInit() {
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Init Start: {}", module);
|
||||
module.doInit();
|
||||
module.registerRecipes();
|
||||
Log.debug("Init Complete: {}", module);
|
||||
}
|
||||
}
|
||||
|
||||
public void runPostInit() {
|
||||
for (IForestryModule module : modules) {
|
||||
Log.debug("Post-Init Start: {}", module);
|
||||
module.postInit();
|
||||
Log.debug("Post-Init Complete: {}", module);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IForestryModule> getModules() {
|
||||
return modules;
|
||||
}
|
||||
}
|
||||
@@ -25,39 +25,28 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.command.CommandHandler;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.IChunkGenerator;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.modules.ForestryModule;
|
||||
import forestry.api.modules.IForestryModule;
|
||||
import forestry.api.modules.IModuleContainer;
|
||||
import forestry.api.modules.IModuleHandler;
|
||||
import forestry.api.modules.IModuleManager;
|
||||
import forestry.core.IPickupHandler;
|
||||
import forestry.core.IResupplyHandler;
|
||||
import forestry.core.ISaveEventHandler;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.plugins.ForestryCompatPlugins;
|
||||
|
||||
public class ModuleManager implements IModuleManager {
|
||||
|
||||
@@ -70,23 +59,10 @@ public class ModuleManager implements IModuleManager {
|
||||
|
||||
private static final HashMap<ResourceLocation, IForestryModule> sortedModules = new LinkedHashMap<>();
|
||||
private static final Set<IForestryModule> loadedModules = new LinkedHashSet<>();
|
||||
private static final Set<BlankForestryModule> internalModules = new LinkedHashSet<>();
|
||||
private static final Set<IModuleHandler> internalHandles = new LinkedHashSet<>();
|
||||
private static final Set<IForestryModule> unloadedModules = new LinkedHashSet<>();
|
||||
private static final HashMap<String, IModuleContainer> moduleContainers = new HashMap<>();
|
||||
public static final Set<IForestryModule> configDisabledModules = new HashSet<>();
|
||||
private static Stage stage = Stage.SETUP;
|
||||
|
||||
public enum Stage {
|
||||
SETUP, // setup API to make it functional. GameMode Configs are not yet accessible
|
||||
SETUP_DISABLED, // setup fallback API to avoid crashes
|
||||
REGISTER, // register basic blocks and items
|
||||
PRE_INIT, // register handlers, triggers, definitions, and anything that depends on basic items
|
||||
BACKPACKS_CRATES, // backpacks, crates
|
||||
INIT, // anything that depends on PreInit stages, recipe registration
|
||||
POST_INIT, // stubborn mod integration, dungeon loot, and finalization of things that take input from mods
|
||||
FINISHED
|
||||
}
|
||||
public static InternalModuleHandler internalHandler;
|
||||
|
||||
private ModuleManager() {
|
||||
}
|
||||
@@ -113,41 +89,10 @@ public class ModuleManager implements IModuleManager {
|
||||
return moduleContainers.values();
|
||||
}
|
||||
|
||||
public static Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
public static Set<IForestryModule> getLoadedModules() {
|
||||
return ImmutableSet.copyOf(sortedModules.values());
|
||||
}
|
||||
|
||||
static void registerHandlers(BlankForestryModule module, Side side) {
|
||||
Log.debug("Registering Handlers for Module: {}", module);
|
||||
|
||||
IPacketRegistry packetRegistry = module.getPacketRegistry();
|
||||
if (packetRegistry != null) {
|
||||
packetRegistry.registerPacketsServer();
|
||||
if (side == Side.CLIENT) {
|
||||
packetRegistry.registerPacketsClient();
|
||||
}
|
||||
}
|
||||
|
||||
IPickupHandler pickupHandler = module.getPickupHandler();
|
||||
if (pickupHandler != null) {
|
||||
pickupHandlers.add(pickupHandler);
|
||||
}
|
||||
|
||||
ISaveEventHandler saveHandler = module.getSaveEventHandler();
|
||||
if (saveHandler != null) {
|
||||
saveEventHandlers.add(saveHandler);
|
||||
}
|
||||
|
||||
IResupplyHandler resupplyHandler = module.getResupplyHandler();
|
||||
if (resupplyHandler != null) {
|
||||
resupplyHandlers.add(resupplyHandler);
|
||||
}
|
||||
}
|
||||
|
||||
private static IForestryModule getModuleCore(List<IForestryModule> forestryModules) {
|
||||
for (IForestryModule module : forestryModules) {
|
||||
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
|
||||
@@ -251,23 +196,26 @@ public class ModuleManager implements IModuleManager {
|
||||
if(config.hasChanged()){
|
||||
config.save();
|
||||
}
|
||||
Collection<IForestryModule> containerModules = sortedModules.values().stream().filter(m -> {
|
||||
}
|
||||
|
||||
loadedModules.addAll(sortedModules.values());
|
||||
unloadedModules.addAll(allModules);
|
||||
unloadedModules.removeAll(sortedModules.values());
|
||||
|
||||
for(IModuleContainer container : moduleContainers.values()){
|
||||
Collection<IForestryModule> loadedModules = sortedModules.values().stream().filter(m -> {
|
||||
ForestryModule info = m.getClass().getAnnotation(ForestryModule.class);
|
||||
return info.containerID().equals(container.getID());
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
IModuleHandler handler = new ModuleHandler(containerModules, getInstance());
|
||||
if(container instanceof ForestryModules || handler instanceof ForestryCompatPlugins){
|
||||
internalHandles.add(handler);
|
||||
}
|
||||
container.onConfiguredModules(handler);
|
||||
Collection<IForestryModule> unloadedModules = ModuleManager.unloadedModules.stream().filter(m -> {
|
||||
ForestryModule info = m.getClass().getAnnotation(ForestryModule.class);
|
||||
return info.containerID().equals(container.getID());
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
container.onConfiguredModules(loadedModules, unloadedModules);
|
||||
}
|
||||
|
||||
loadedModules.addAll(sortedModules.values());
|
||||
sortedModules.values().stream().filter((m)->m instanceof BlankForestryModule).forEach((IForestryModule m)->internalModules.add((BlankForestryModule) m));
|
||||
unloadedModules.addAll(allModules);
|
||||
unloadedModules.removeAll(sortedModules.values());
|
||||
|
||||
ForestryAPI.enabledModules = new HashSet<>();
|
||||
for (IForestryModule module : sortedModules.values()) {
|
||||
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
|
||||
@@ -278,51 +226,16 @@ public class ModuleManager implements IModuleManager {
|
||||
}
|
||||
|
||||
public static void runSetup(FMLPreInitializationEvent event) {
|
||||
|
||||
ASMDataTable asmDataTable = event.getAsmData();
|
||||
Map<String, List<IForestryModule>> forestryModules = ForestryPluginUtil.getForestryModules(asmDataTable);
|
||||
|
||||
stage = Stage.SETUP;
|
||||
internalHandler = new InternalModuleHandler(getInstance());
|
||||
configureModules(forestryModules);
|
||||
|
||||
for(IModuleHandler handler : internalHandles){
|
||||
handler.runSetup();
|
||||
}
|
||||
}
|
||||
|
||||
public static void runPreInit(Side side) {
|
||||
stage = Stage.PRE_INIT;
|
||||
for(IModuleHandler handler : internalHandles){
|
||||
handler.runPreInit();
|
||||
}
|
||||
}
|
||||
|
||||
public static void runRegisterBackpacksAndCrates() {
|
||||
stage = Stage.BACKPACKS_CRATES;
|
||||
for (IForestryModule module : loadedModules) {
|
||||
if (getInstance().isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.CRATE)) {
|
||||
Log.debug("BackpacksAndCrates Start: {}", module);
|
||||
module.registerBackpackItems();
|
||||
module.registerCrates();
|
||||
Log.debug("BackpacksAndCrates Complete: {}", module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void runInit() {
|
||||
stage = Stage.INIT;
|
||||
for(IModuleHandler handler : internalHandles){
|
||||
handler.runInit();
|
||||
}
|
||||
}
|
||||
|
||||
public static void runPostInit() {
|
||||
stage = Stage.POST_INIT;
|
||||
for(IModuleHandler handler : internalHandles){
|
||||
handler.runPostInit();
|
||||
}
|
||||
|
||||
stage = Stage.FINISHED;
|
||||
public static InternalModuleHandler getInternalHandler() {
|
||||
Preconditions.checkNotNull(internalHandler);
|
||||
return internalHandler;
|
||||
}
|
||||
|
||||
public static void serverStarting(MinecraftServer server) {
|
||||
@@ -339,43 +252,6 @@ public class ModuleManager implements IModuleManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void processIMCMessages(ImmutableList<FMLInterModComms.IMCMessage> messages) {
|
||||
for (FMLInterModComms.IMCMessage message : messages) {
|
||||
for (BlankForestryModule module : internalModules) {
|
||||
if (module.processIMCMessage(message)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void populateChunk(IChunkGenerator chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) {
|
||||
for (BlankForestryModule module : internalModules) {
|
||||
module.populateChunk(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
|
||||
}
|
||||
}
|
||||
|
||||
public static void decorateBiome(World world, Random rand, BlockPos pos) {
|
||||
for (BlankForestryModule module : internalModules) {
|
||||
module.decorateBiome(world, rand, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ) {
|
||||
for (BlankForestryModule module : internalModules) {
|
||||
module.populateChunkRetroGen(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<ItemStack> getHiddenItems() {
|
||||
List<ItemStack> hiddenItems = new ArrayList<>();
|
||||
for (BlankForestryModule module : internalModules) {
|
||||
module.getHiddenItems(hiddenItems);
|
||||
}
|
||||
return hiddenItems;
|
||||
}
|
||||
|
||||
|
||||
public static Set<String> getLootPoolNames() {
|
||||
Set<String> lootPoolNames = new HashSet<>();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package forestry.plugins;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
@@ -8,6 +10,7 @@ import forestry.api.modules.IForestryModule;
|
||||
import forestry.api.modules.IModuleContainer;
|
||||
import forestry.modules.ForestryModules;
|
||||
import forestry.modules.ForestryPluginUtil;
|
||||
import forestry.modules.ModuleManager;
|
||||
|
||||
public class ForestryCompatPlugins implements IModuleContainer {
|
||||
private static final String MODULE_CONFIG_FILE_NAME = "modules.cfg";
|
||||
@@ -38,4 +41,9 @@ public class ForestryCompatPlugins implements IModuleContainer {
|
||||
Property prop = getModulesConfig().get(CONFIG_CATEGORY, info.moduleID(), true, comment);
|
||||
return prop.getBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfiguredModules(Collection<IForestryModule> activeModules, Collection<IForestryModule> unloadedModules) {
|
||||
ModuleManager.getInternalHandler().addModules(activeModules, unloadedModules);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class ForestryJeiPlugin implements IModPlugin {
|
||||
public void register(IModRegistry registry) {
|
||||
IJeiHelpers jeiHelpers = registry.getJeiHelpers();
|
||||
IIngredientBlacklist ingredientBlacklist = jeiHelpers.getIngredientBlacklist();
|
||||
List<ItemStack> hiddenItems = ModuleManager.getHiddenItems();
|
||||
List<ItemStack> hiddenItems = ModuleManager.getInternalHandler().getHiddenItems();
|
||||
for (ItemStack hiddenItem : hiddenItems) {
|
||||
ingredientBlacklist.addIngredientToBlacklist(hiddenItem);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user