mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-10-25 20:22:23 +00:00
Add unload event handling to ClientNetworkManager (#137)
Added a new method `onWorldUnload` to `ClientNetworkManager` to destroy and clear any network instances when the world event `Unload` is triggered. The addition of this event handler was necessary to prevent the possibility of any network instances persisting on the client side beyond the World lifetime, thus potentially causing memory leaks.
This commit is contained in:
1 parent
0b0f7a4f1a
commit
123f22f20e
1 file changed
+15
@@ -4,13 +4,20 @@ import java.util.HashMap;
|
||||
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 class ClientNetworkManager {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user