Skip to content

Commit

Permalink
Make mod no-op on server
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
makamys committed Jan 8, 2024
1 parent 034eccc commit 64a8fa4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/main/java/makamys/neodymium/MixinConfigPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
import org.spongepowered.asm.mixin.MixinEnvironment.Side;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

Expand All @@ -18,6 +20,8 @@ public class MixinConfigPlugin implements IMixinConfigPlugin {

@Override
public void onLoad(String mixinPackage) {
if(MixinEnvironment.getCurrentEnvironment().getSide() == Side.SERVER) return;

Config.reloadConfig();

Phase phase = MixinEnvironment.getCurrentEnvironment().getPhase();
Expand All @@ -41,6 +45,8 @@ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> getMixins() {
if(MixinEnvironment.getCurrentEnvironment().getSide() == Side.SERVER) return Collections.emptyList();

List<String> mixins = new ArrayList<>();
Phase phase = MixinEnvironment.getCurrentEnvironment().getPhase();
if(phase == Phase.DEFAULT) {
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/makamys/neodymium/Neodymium.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
Expand All @@ -33,6 +34,7 @@
import makamys.neodymium.config.Config;
import makamys.neodymium.renderer.NeoRenderer;
import makamys.neodymium.util.ChatUtil;
import makamys.neodymium.util.Proxy;
import makamys.neodymium.util.WarningHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -42,9 +44,19 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;

@Mod(modid = MODID, version = VERSION, guiFactory = "makamys.neodymium.config.GuiFactory")
public class Neodymium
{
public class Neodymium implements Proxy {

@Mod(modid = MODID, version = VERSION, guiFactory = "makamys.neodymium.config.GuiFactory")
public static class ModContainer {
@SidedProxy(serverSide = "makamys.neodymium.util.Proxy$NullProxy", clientSide = "makamys.neodymium.Neodymium")
private static Proxy proxy;
@EventHandler
public void construct(FMLConstructionEvent event) { proxy.construct(event); }
@EventHandler
public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); }
@EventHandler
public void init(FMLInitializationEvent event) { proxy.init(event); }
}

private static final Config.ReloadInfo CONFIG_RELOAD_INFO = new Config.ReloadInfo();

Expand All @@ -56,15 +68,12 @@ public class Neodymium

private static World rendererWorld;

@EventHandler
public void preInit(FMLConstructionEvent event) {
public void construct(FMLConstructionEvent event) {
MCLib.init();
Compat.init();
}

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
public void preInit(FMLPreInitializationEvent event) {
MCLibModules.updateCheckAPI.submitModTask(MODID, "@UPDATE_URL@");

if(VERSION.equals("@VERSION@")) {
Expand All @@ -73,9 +82,7 @@ public void preInit(FMLPreInitializationEvent event)
}
}

@EventHandler
public void init(FMLInitializationEvent event)
{
public void init(FMLInitializationEvent event) {
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
NeodymiumCommand.init();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/makamys/neodymium/util/Proxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package makamys.neodymium.util;

import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

public interface Proxy {
public default void construct(FMLConstructionEvent event) {}
public default void preInit(FMLPreInitializationEvent event) {}
public default void init(FMLInitializationEvent event) {}
public default void postInit(FMLPostInitializationEvent event) {}
public default void loadComplete(FMLLoadCompleteEvent event) {}

public static class NullProxy implements Proxy {}
}

0 comments on commit 64a8fa4

Please sign in to comment.