package mcjty.rftoolsdim.dimensions.dimlets;

import mcjty.rftoolsdim.dimensions.dimlets.types.DimletType;

/**
* Created by jorrit on 8/12/14.
*/
public class DimletKey implements Comparable<DimletKey> {
    private final DimletType type;
    private final String id;

    public DimletKey(DimletType type, String id) {
        this.type = type;
        this.id = id;
    }

    public DimletType getType() {
        return type;
    }

    public String getId() {
        return id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        DimletKey dimletKey = (DimletKey) o;

        if (type != dimletKey.type) {
            return false;
        }
        if (!id.equals(dimletKey.id)) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = type.hashCode();
        if (id != null) {
            result = 31 * result + id.hashCode();
        }
        return result;
    }

    @Override
    public String toString() {
        return type.dimletType.getOpcode() + id;
    }

    public static DimletKey parseKey(String skey) {
        String opcode = skey.substring(0, 1);
        String name = skey.substring(1);
        return new DimletKey(DimletType.getTypeByOpcode(opcode), name);
    }

    @Override
    public int compareTo(DimletKey o) {
        int result = type.compareTo(o.type);
        if(result != 0) return result;
        return id.compareTo(o.id);
    }
}

@@ -39,16 +39,74 @@
 mlets;%0A%0A
+import java.util.Arrays;%0A%0Aimport mcjty.lib.varia.Logging;%0A
 import m
@@ -158,16 +158,16 @@
 etType;%0A
-
 %0A/**%0A* C
@@ -416,24 +416,423 @@
 is.id = id;%0A
+        if(id == null) %7B%0A            // StatList.reinit makes objects without proper NBT; ignore these...%0A            if(!Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch(elem -%3E %22net.minecraft.stats.StatList%22.equals(elem.getClassName()) && %22reinit%22.equals(elem.getMethodName()))) %7B%0A                Logging.getLogger().catching(new NullPointerException(%22id%22));%0A            %7D%0A        %7D%0A
     %7D%0A%0A    p
@@ -1258,32 +1258,338 @@
 alse;%0A        %7D%0A
+        if (id == null) %7B%0A            Logging.getLogger().catching(new NullPointerException(%22id%22));%0A            if(dimletKey.id == null) %7B%0A                Logging.getLogger().catching(new NullPointerException(%22dimletKey.id%22));%0A                return true;%0A            %7D%0A            return false;%0A        %7D%0A
         if (!id.
@@ -1825,32 +1825,123 @@
  id.hashCode();%0A
+        %7D else %7B%0A            Logging.getLogger().catching(new NullPointerException(%22id%22));%0A
         %7D%0A      
@@ -2378,24 +2378,24 @@
 To(o.type);%0A
-
         if(r
@@ -2417,24 +2417,439 @@
 urn result;%0A
+        if(id == null) %7B%0A            Logging.getLogger().catching(new NullPointerException(%22id%22));%0A            if(o.id == null) %7B%0A                Logging.getLogger().catching(new NullPointerException(%22o.id%22));%0A                return 0;%0A            %7D%0A            return -1;%0A        %7D else if(o.id == null) %7B%0A            Logging.getLogger().catching(new NullPointerException(%22o.id%22));%0A            return 1;%0A        %7D%0A
         retu

Fix McJty/RFTools#1598: just complain about nulls instead of crashing