diff --git a/src/main/java/crazypants/enderio/machine/capbank/network/ClientNetworkManager.java b/src/main/java/crazypants/enderio/machine/capbank/network/ClientNetworkManager.java index 7a578a245a..3d74ca9efc 100644 --- a/src/main/java/crazypants/enderio/machine/capbank/network/ClientNetworkManager.java +++ b/src/main/java/crazypants/enderio/machine/capbank/network/ClientNetworkManager.java @@ -4,13 +4,20 @@ import java.util.Map; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.WorldEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import crazypants.enderio.machine.capbank.TileCapBank; public class ClientNetworkManager { private static final ClientNetworkManager instance = new ClientNetworkManager(); + static { + MinecraftForge.EVENT_BUS.register(instance); + } + public static ClientNetworkManager getInstance() { return instance; } @@ -53,4 +60,12 @@ public void addToNetwork(int id, TileCapBank tileCapBank) { CapBankClientNetwork network = getOrCreateNetwork(id); network.addMember(tileCapBank); } + + @SubscribeEvent + public void onWorldUnload(WorldEvent.Unload event) { + if (event.world.isRemote) { + networks.forEach((id, network) -> network.destroyNetwork()); + networks.clear(); + } + } }