diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java index 5cb41981e..c8a18374c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java @@ -73,6 +73,8 @@ public class FullDataPointIdMap private final ArrayList entryList = new ArrayList<>(); private final HashMap idMap = new HashMap<>(); + private int cachedHashCode = 0; + //=============// @@ -159,6 +161,9 @@ public class FullDataPointIdMap id = this.entryList.size(); this.entryList.add(biomeBlockStateEntry); this.idMap.put(biomeBlockStateEntry, id); + + // invalidate the cached hash code + this.cachedHashCode = 0; } return id; @@ -186,6 +191,9 @@ public class FullDataPointIdMap int id = this.entryList.size(); this.entryList.add(biomeBlockStateEntry); this.idMap.put(biomeBlockStateEntry, id); + + // invalidate the cached hash code + this.cachedHashCode = 0; } finally { @@ -275,6 +283,7 @@ public class FullDataPointIdMap this.pos = pos; this.entryList.clear(); this.idMap.clear(); + this.cachedHashCode = 0; } @@ -390,6 +399,26 @@ public class FullDataPointIdMap return false; } + /** Only includes the base data in this object, not the mapping */ + @Override + public int hashCode() + { + if (this.cachedHashCode == 0) + { + this.generateHashCode(); + } + return this.cachedHashCode; + } + private void generateHashCode() + { + int result = DhSectionPos.hashCode(this.pos); + for (int i = 0; i < this.entryList.size(); i++) + { + result = 31 * result + this.entryList.hashCode(); + } + this.cachedHashCode = result; + } + //==============//