Refactored Proxy classes.
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
package dev.micle.totemofreviving;
|
package dev.micle.totemofreviving;
|
||||||
|
|
||||||
|
import dev.micle.totemofreviving.proxy.IProxy;
|
||||||
|
import dev.micle.totemofreviving.proxy.IProxy;
|
||||||
|
import dev.micle.totemofreviving.proxy.Proxy;
|
||||||
import dev.micle.totemofreviving.setup.ModItems;
|
import dev.micle.totemofreviving.setup.ModItems;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.CreativeModeTab;
|
import net.minecraft.world.item.CreativeModeTab;
|
||||||
@ -8,11 +11,8 @@ import net.minecraftforge.fml.DistExecutor;
|
|||||||
import net.minecraftforge.fml.ModContainer;
|
import net.minecraftforge.fml.ModContainer;
|
||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.ModList;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
@Mod(TotemOfReviving.MOD_ID)
|
@Mod(TotemOfReviving.MOD_ID)
|
||||||
public final class TotemOfReviving {
|
public final class TotemOfReviving {
|
||||||
@ -24,12 +24,12 @@ public final class TotemOfReviving {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static ISideProxy proxy;
|
private static IProxy proxy;
|
||||||
|
|
||||||
public TotemOfReviving() {
|
public TotemOfReviving() {
|
||||||
proxy = DistExecutor.safeRunForDist(
|
proxy = DistExecutor.safeRunForDist(
|
||||||
() -> SideProxy.Client::new,
|
() -> Proxy.Client::new,
|
||||||
() -> SideProxy.Server::new
|
() -> Proxy.Server::new
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public final class TotemOfReviving {
|
|||||||
return "0.0.0";
|
return "0.0.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ISideProxy getProxy() {
|
public static IProxy getProxy() {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package dev.micle.totemofreviving;
|
package dev.micle.totemofreviving.proxy;
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
public interface ISideProxy {
|
public interface IProxy {
|
||||||
MinecraftServer getServer();
|
MinecraftServer getServer();
|
||||||
|
|
||||||
Player getClientPlayer();
|
Player getClientPlayer();
|
||||||
|
|
||||||
Level getClientWorld();
|
Level getClientWorld();
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package dev.micle.totemofreviving;
|
package dev.micle.totemofreviving.proxy;
|
||||||
|
|
||||||
import dev.micle.totemofreviving.config.Config;
|
import dev.micle.totemofreviving.config.Config;
|
||||||
import dev.micle.totemofreviving.data.DataGenerators;
|
import dev.micle.totemofreviving.data.DataGenerators;
|
||||||
@ -18,24 +18,28 @@ import net.minecraftforge.eventbus.api.IEventBus;
|
|||||||
import net.minecraftforge.fml.event.lifecycle.*;
|
import net.minecraftforge.fml.event.lifecycle.*;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
|
||||||
class SideProxy implements ISideProxy {
|
public class Proxy implements IProxy {
|
||||||
|
// Initialize variables
|
||||||
private static MinecraftServer server = null;
|
private static MinecraftServer server = null;
|
||||||
|
|
||||||
// Common setup
|
// Common setup
|
||||||
SideProxy() {
|
public Proxy() {
|
||||||
|
// Initialize setup
|
||||||
Registration.register();
|
Registration.register();
|
||||||
Config.init();
|
Config.init();
|
||||||
Network.init();
|
Network.init();
|
||||||
|
|
||||||
|
// Register mod event bus listeners
|
||||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
modEventBus.addListener(DataGenerators::gatherData);
|
modEventBus.addListener(DataGenerators::gatherData);
|
||||||
modEventBus.addListener(SideProxy::setup);
|
modEventBus.addListener(Proxy::setup);
|
||||||
modEventBus.addListener(SideProxy::imcEnqueue);
|
modEventBus.addListener(Proxy::imcEnqueue);
|
||||||
modEventBus.addListener(SideProxy::imcProcess);
|
modEventBus.addListener(Proxy::imcProcess);
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.addListener(SideProxy::onAddReloadListeners);
|
// Register event bus listeners
|
||||||
MinecraftForge.EVENT_BUS.addListener(SideProxy::serverStarted);
|
MinecraftForge.EVENT_BUS.addListener(Proxy::onAddReloadListeners);
|
||||||
MinecraftForge.EVENT_BUS.addListener(SideProxy::serverStopping);
|
MinecraftForge.EVENT_BUS.addListener(Proxy::serverStarted);
|
||||||
|
MinecraftForge.EVENT_BUS.addListener(Proxy::serverStopping);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setup(FMLCommonSetupEvent event) {}
|
private static void setup(FMLCommonSetupEvent event) {}
|
||||||
@ -70,10 +74,12 @@ class SideProxy implements ISideProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Client setup
|
// Client setup
|
||||||
static class Client extends SideProxy {
|
public static class Client extends Proxy {
|
||||||
Client() {
|
public Client() {
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(Client::setup);
|
// Register mod event bus listeners
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(Client::postSetup);
|
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
modEventBus.addListener(Client::setup);
|
||||||
|
modEventBus.addListener(Client::postSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setup(FMLClientSetupEvent event) {}
|
private static void setup(FMLClientSetupEvent event) {}
|
||||||
@ -94,9 +100,11 @@ class SideProxy implements ISideProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Server setup
|
// Server setup
|
||||||
static class Server extends SideProxy {
|
public static class Server extends Proxy {
|
||||||
Server() {
|
public Server() {
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(Server::setup);
|
// Register mod event bus listeners
|
||||||
|
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
modEventBus.addListener(Server::setup);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setup(FMLDedicatedServerSetupEvent event) {}
|
private static void setup(FMLDedicatedServerSetupEvent event) {}
|
Reference in New Issue
Block a user