Skip to content

Commit

Permalink
feat(mod): change to use mod setup event and register to event buses
Browse files Browse the repository at this point in the history
  • Loading branch information
danorris709 committed May 24, 2023
1 parent 9be5937 commit 882f120
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/your/domain/path/ModFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.pixelmonmod.pixelmon.Pixelmon;
import com.pixelmonmod.pixelmon.api.config.api.yaml.YamlConfigFactory;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerStartedEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppedEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import your.domain.path.command.ExampleCommand;
Expand All @@ -34,19 +38,26 @@ public ModFile() {
instance = this;

reloadConfig();
}

@SubscribeEvent
public static void onServerStarting(FMLServerStartingEvent event) {
// Logic for when the server is starting here
MinecraftForge.EVENT_BUS.register(this);

IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
bus.addListener(ModFile::onModLoad);
}

public static void onModLoad(FMLCommonSetupEvent event) {
// Here is how you register a listener for Pixelmon events
// Pixelmon has its own event bus for its events, as does TCG
// So any event listener for those mods need to be registered to those specific event buses
Pixelmon.EVENT_BUS.register(new PixelmonEggHatchExampleListener());
Pixelmon.EVENT_BUS.register(new PokemonSpawnExampleListener());
}

@SubscribeEvent
public static void onServerStarting(FMLServerStartingEvent event) {
// Logic for when the server is starting here
}

public void reloadConfig() {
try {
this.config = YamlConfigFactory.getInstance(ExampleConfig.class);
Expand Down

0 comments on commit 882f120

Please sign in to comment.