package refinedstorage.api.network;

import net.minecraft.util.math.BlockPos;

import java.util.HashMap;
import java.util.Map;

public class NetworkMasterRegistry {
    public static final Map<Integer, Map<BlockPos, NetworkMaster>> NETWORKS = new HashMap<Integer, Map<BlockPos, NetworkMaster>>();

    public static void add(NetworkMaster network, int dimension) {
        if (NETWORKS.get(dimension) == null) {
            NETWORKS.put(dimension, new HashMap<BlockPos, NetworkMaster>());
        }

        NETWORKS.get(dimension).put(network.getPosition(), network);
    }

    public static void remove(BlockPos pos, int dimension) {
        if (get(dimension) != null) {
            get(dimension).get(pos).onRemoved();
            get(dimension).remove(pos);
        }
    }

    public static NetworkMaster get(BlockPos pos, int dimension) {
        return get(dimension) == null ? null : get(dimension).get(pos);
    }

    public static Map<BlockPos, NetworkMaster> get(int dimension) {
        return NETWORKS.get(dimension);
    }
}

@@ -680,39 +680,124 @@
         
-get(dimension).get(pos)
+NetworkMaster network = get(dimension).get(pos);%0A%0A            if (network != null) %7B%0A                network
 .onRemov
@@ -802,16 +802,21 @@
 oved();%0A
+%0A    
         
@@ -843,24 +843,38 @@
 emove(pos);%0A
+            %7D%0A
         %7D%0A  

Fix NPE