diff --git a/src/main/java/crazypants/enderio/CommonProxy.java b/src/main/java/crazypants/enderio/CommonProxy.java index 8d0b8ec4..18e01285 100644 --- a/src/main/java/crazypants/enderio/CommonProxy.java +++ b/src/main/java/crazypants/enderio/CommonProxy.java @@ -9,12 +9,18 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; +import cpw.mods.fml.common.event.FMLServerStartedEvent; +import cpw.mods.fml.common.event.FMLServerStoppedEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent; +import crazypants.enderio.conduit.ConduitNetworkTickHandler; import crazypants.enderio.conduit.IConduit; import crazypants.enderio.conduit.render.ConduitRenderer; +import crazypants.enderio.machine.hypercube.HyperCubeRegister; +import crazypants.enderio.machine.transceiver.ServerChannelRegister; public class CommonProxy { @@ -23,6 +29,7 @@ public class CommonProxy { protected long serverTickCount = 0; protected long clientTickCount = 0; protected final TickTimer tickTimer = new TickTimer(); + public ConduitNetworkTickHandler conduitNetworkTickHandler = null; public CommonProxy() {} @@ -44,7 +51,7 @@ public class CommonProxy { } public void loadIcons() { - ; + } public void load() { @@ -76,6 +83,22 @@ public class CommonProxy { return new ResourceLocation(EnderIO.DOMAIN + TEXTURE_PATH + name + TEXTURE_EXT); } + public void onServerAboutToStart(FMLServerAboutToStartEvent event) { + conduitNetworkTickHandler = new ConduitNetworkTickHandler(); + FMLCommonHandler.instance().bus().register(conduitNetworkTickHandler); + } + + public void onServerStarted(FMLServerStartedEvent event) { + HyperCubeRegister.load(); + ServerChannelRegister.load(); + } + + public void onServerStopped(FMLServerStoppedEvent event) { + HyperCubeRegister.unload(); + FMLCommonHandler.instance().bus().unregister(conduitNetworkTickHandler); + conduitNetworkTickHandler = null; + } + public final class TickTimer { @SubscribeEvent diff --git a/src/main/java/crazypants/enderio/EnderIO.java b/src/main/java/crazypants/enderio/EnderIO.java index ab17b0d6..127a5556 100644 --- a/src/main/java/crazypants/enderio/EnderIO.java +++ b/src/main/java/crazypants/enderio/EnderIO.java @@ -38,6 +38,7 @@ import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import cpw.mods.fml.common.event.FMLMissingMappingsEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerAboutToStartEvent; import cpw.mods.fml.common.event.FMLServerStartedEvent; import cpw.mods.fml.common.event.FMLServerStoppedEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -111,7 +112,6 @@ import crazypants.enderio.machine.generator.zombie.BlockZombieGenerator.BlockEnd import crazypants.enderio.machine.generator.zombie.BlockZombieGenerator.BlockFrankenZombieGenerator; import crazypants.enderio.machine.generator.zombie.PacketNutrientTank; import crazypants.enderio.machine.hypercube.BlockHyperCube; -import crazypants.enderio.machine.hypercube.HyperCubeRegister; import crazypants.enderio.machine.invpanel.BlockInventoryPanel; import crazypants.enderio.machine.killera.BlockKillerJoe; import crazypants.enderio.machine.light.BlockElectricLight; @@ -894,22 +894,18 @@ public class EnderIO { } @EventHandler - public void serverStarted(FMLServerStartedEvent event) { - HyperCubeRegister.load(); - ServerChannelRegister.load(); - } - - @SubscribeEvent - public void worldSaved(WorldEvent.Save event) { - // Only save together with the overworld, because this gets called for every dimension separately - if (event.world.provider != null && event.world.provider.dimensionId == 0) { - ServerChannelRegister.store(); - } + public void onServerAboutToStart(FMLServerAboutToStartEvent event) { + proxy.onServerAboutToStart(event); } @EventHandler - public void serverStopped(FMLServerStoppedEvent event) { - HyperCubeRegister.unload(); + public void onServerStarted(FMLServerStartedEvent event) { + proxy.onServerStarted(event); + } + + @EventHandler + public void onServerStopped(FMLServerStoppedEvent event) { + proxy.onServerStopped(event); } @EventHandler @@ -921,4 +917,12 @@ public class EnderIO { } } } + + @SubscribeEvent + public void worldSaved(WorldEvent.Save event) { + // Only save together with the overworld, because this gets called for every dimension separately + if (event.world.provider != null && event.world.provider.dimensionId == 0) { + ServerChannelRegister.store(); + } + } } diff --git a/src/main/java/crazypants/enderio/conduit/AbstractConduitNetwork.java b/src/main/java/crazypants/enderio/conduit/AbstractConduitNetwork.java index ee3d82a5..adecf839 100644 --- a/src/main/java/crazypants/enderio/conduit/AbstractConduitNetwork.java +++ b/src/main/java/crazypants/enderio/conduit/AbstractConduitNetwork.java @@ -7,6 +7,8 @@ import java.util.List; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import crazypants.enderio.EnderIO; + // I=base type, I is the base class of the implementations accepted by the network public abstract class AbstractConduitNetwork { @@ -64,7 +66,7 @@ public abstract class AbstractConduitNetwork { public void addConduit(I con) { if (!conduits.contains(con)) { if (conduits.isEmpty()) { - ConduitNetworkTickHandler.instance.registerNetwork(this); + EnderIO.proxy.conduitNetworkTickHandler.registerNetwork(this); } conduits.add(con); } @@ -75,7 +77,7 @@ public abstract class AbstractConduitNetwork { con.setNetwork(null); } conduits.clear(); - ConduitNetworkTickHandler.instance.unregisterNetwork(this); + EnderIO.proxy.conduitNetworkTickHandler.unregisterNetwork(this); } public List getConduits() { diff --git a/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java b/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java index ad7fbe19..3ba108ef 100644 --- a/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java +++ b/src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java @@ -32,7 +32,6 @@ import com.enderio.core.client.render.BoundingBox; import com.enderio.core.common.util.BlockCoord; import com.enderio.core.common.util.Util; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -93,9 +92,6 @@ public class BlockConduitBundle extends BlockEio public static BlockConduitBundle create() { - MinecraftForge.EVENT_BUS.register(ConduitNetworkTickHandler.instance); - FMLCommonHandler.instance().bus().register(ConduitNetworkTickHandler.instance); - PacketHandler.INSTANCE .registerMessage(PacketFluidLevel.class, PacketFluidLevel.class, PacketHandler.nextID(), Side.CLIENT); PacketHandler.INSTANCE diff --git a/src/main/java/crazypants/enderio/conduit/ConduitNetworkTickHandler.java b/src/main/java/crazypants/enderio/conduit/ConduitNetworkTickHandler.java index c19a34ae..4dbe6c73 100644 --- a/src/main/java/crazypants/enderio/conduit/ConduitNetworkTickHandler.java +++ b/src/main/java/crazypants/enderio/conduit/ConduitNetworkTickHandler.java @@ -10,18 +10,15 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase; public class ConduitNetworkTickHandler { - public static final ConduitNetworkTickHandler instance = new ConduitNetworkTickHandler(); + public interface TickListener { - public static interface TickListener { + void tickStart(TickEvent.ServerTickEvent evt); - public void tickStart(TickEvent.ServerTickEvent evt); - - public void tickEnd(TickEvent.ServerTickEvent evt); + void tickEnd(TickEvent.ServerTickEvent evt); } - private final List listeners = new ArrayList(); - - private final IdentityHashMap, Boolean> networks = new IdentityHashMap, Boolean>(); + private final List listeners = new ArrayList<>(); + private final IdentityHashMap, Boolean> networks = new IdentityHashMap<>(); public void addListener(TickListener listener) { listeners.add(listener); diff --git a/src/main/java/crazypants/enderio/machine/capbank/network/CapBankNetwork.java b/src/main/java/crazypants/enderio/machine/capbank/network/CapBankNetwork.java index d3fcd648..be1ca9da 100644 --- a/src/main/java/crazypants/enderio/machine/capbank/network/CapBankNetwork.java +++ b/src/main/java/crazypants/enderio/machine/capbank/network/CapBankNetwork.java @@ -16,7 +16,7 @@ import com.enderio.core.common.util.RoundRobinIterator; import cofh.api.energy.IEnergyContainerItem; import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent; -import crazypants.enderio.conduit.ConduitNetworkTickHandler; +import crazypants.enderio.EnderIO; import crazypants.enderio.conduit.ConduitNetworkTickHandler.TickListener; import crazypants.enderio.conduit.ConnectionMode; import crazypants.enderio.conduit.power.IPowerConduit; @@ -212,7 +212,7 @@ public class CapBankNetwork implements ICapBankNetwork { long curTime = world.getTotalWorldTime(); if (curTime != timeAtLastApply) { timeAtLastApply = curTime; - ConduitNetworkTickHandler.instance.addListener(tickListener); + EnderIO.proxy.conduitNetworkTickHandler.addListener(tickListener); } }