Refactored Proxy classes.

This commit is contained in:
Micle
2022-11-03 18:37:18 +00:00
parent 2b204e764b
commit c993cc2375
3 changed files with 35 additions and 29 deletions

View File

@ -1,5 +1,8 @@
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 net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
@ -8,11 +11,8 @@ import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;
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.Random;
@Mod(TotemOfReviving.MOD_ID)
public final class TotemOfReviving {
@ -24,12 +24,12 @@ public final class TotemOfReviving {
}
};
private static ISideProxy proxy;
private static IProxy proxy;
public TotemOfReviving() {
proxy = DistExecutor.safeRunForDist(
() -> SideProxy.Client::new,
() -> SideProxy.Server::new
() -> Proxy.Client::new,
() -> Proxy.Server::new
);
}
@ -48,7 +48,7 @@ public final class TotemOfReviving {
return "0.0.0";
}
public static ISideProxy getProxy() {
public static IProxy getProxy() {
return proxy;
}
}

View File

@ -1,13 +1,11 @@
package dev.micle.totemofreviving;
package dev.micle.totemofreviving.proxy;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
public interface ISideProxy {
public interface IProxy {
MinecraftServer getServer();
Player getClientPlayer();
Level getClientWorld();
}

View File

@ -1,4 +1,4 @@
package dev.micle.totemofreviving;
package dev.micle.totemofreviving.proxy;
import dev.micle.totemofreviving.config.Config;
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.javafmlmod.FMLJavaModLoadingContext;
class SideProxy implements ISideProxy {
public class Proxy implements IProxy {
// Initialize variables
private static MinecraftServer server = null;
// Common setup
SideProxy() {
public Proxy() {
// Initialize setup
Registration.register();
Config.init();
Network.init();
// Register mod event bus listeners
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(DataGenerators::gatherData);
modEventBus.addListener(SideProxy::setup);
modEventBus.addListener(SideProxy::imcEnqueue);
modEventBus.addListener(SideProxy::imcProcess);
MinecraftForge.EVENT_BUS.addListener(SideProxy::onAddReloadListeners);
MinecraftForge.EVENT_BUS.addListener(SideProxy::serverStarted);
MinecraftForge.EVENT_BUS.addListener(SideProxy::serverStopping);
modEventBus.addListener(Proxy::setup);
modEventBus.addListener(Proxy::imcEnqueue);
modEventBus.addListener(Proxy::imcProcess);
// Register event bus listeners
MinecraftForge.EVENT_BUS.addListener(Proxy::onAddReloadListeners);
MinecraftForge.EVENT_BUS.addListener(Proxy::serverStarted);
MinecraftForge.EVENT_BUS.addListener(Proxy::serverStopping);
}
private static void setup(FMLCommonSetupEvent event) {}
@ -70,10 +74,12 @@ class SideProxy implements ISideProxy {
}
// Client setup
static class Client extends SideProxy {
Client() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(Client::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(Client::postSetup);
public static class Client extends Proxy {
public Client() {
// Register mod event bus listeners
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(Client::setup);
modEventBus.addListener(Client::postSetup);
}
private static void setup(FMLClientSetupEvent event) {}
@ -94,9 +100,11 @@ class SideProxy implements ISideProxy {
}
// Server setup
static class Server extends SideProxy {
Server() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(Server::setup);
public static class Server extends Proxy {
public Server() {
// Register mod event bus listeners
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(Server::setup);
}
private static void setup(FMLDedicatedServerSetupEvent event) {}