Эх сурвалжийг харах

Fix: Adapt custom ImmutableMap code to work with guava 27 as well as the usual guava 21

malte0811 3 жил өмнө
parent
commit
1cc2272662

+ 3 - 1
common/build.gradle

@@ -32,7 +32,9 @@ dependencies {
     modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
     testImplementation(platform('org.junit:junit-bom:5.7.1'))
     testImplementation('org.junit.jupiter:junit-jupiter')
-    googleaccessCompileOnly('com.google.guava:guava:21.0')
+    // Not what MC depends on (21), but Forge/FG sometimes end up with 27 because it's a transitive dependency of
+    // patchy (Mojang lib for chat blocking)
+    googleaccessCompileOnly('com.google.guava:guava:27.0.1-jre')
     googleaccessCompileOnly('org.jetbrains:annotations:19.0.0')
 }
 

+ 3 - 0
common/src/googleaccess/java/com/google/common/collect/FerriteCoreImmutableMapAccess.java

@@ -14,4 +14,7 @@ public abstract class FerriteCoreImmutableMapAccess<K, V> extends ImmutableMap<K
 
     @Override
     public abstract boolean isPartialView();
+
+    @Override
+    public abstract ImmutableSet<K> createKeySet();
 }

+ 1 - 2
common/src/googleimpl/java/malte0811/ferritecore/fastmap/immutable/FastMapEntryEntrySet.java

@@ -29,10 +29,9 @@ public class FastMapEntryEntrySet extends FerriteCoreEntrySetAccess<Property<?>,
 
     @Override
     public boolean contains(@Nullable Object object) {
-        if (!(object instanceof Map.Entry)) {
+        if (!(object instanceof Map.Entry<?, ?> entry)) {
             return false;
         }
-        Map.Entry<?, ?> entry = (Map.Entry<?, ?>) object;
         Comparable<?> valueInMap = viewedState.getStateMap().getValue(viewedState.getStateIndex(), entry.getKey());
         return valueInMap != null && valueInMap.equals(((Map.Entry<?, ?>) object).getValue());
     }

+ 5 - 0
common/src/googleimpl/java/malte0811/ferritecore/fastmap/immutable/FastMapEntryImmutableMap.java

@@ -37,4 +37,9 @@ public class FastMapEntryImmutableMap extends FerriteCoreImmutableMapAccess<Prop
     public boolean isPartialView() {
         return false;
     }
+
+    @Override
+    public ImmutableSet<Property<?>> createKeySet() {
+        return viewedState.getStateMap().getPropertySet();
+    }
 }

+ 9 - 1
common/src/main/java/malte0811/ferritecore/fastmap/FastMap.java

@@ -2,8 +2,10 @@ package malte0811.ferritecore.fastmap;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import javax.annotation.Nullable;
+import com.google.common.collect.ImmutableSet;
 import net.minecraft.world.level.block.state.properties.Property;
+
+import javax.annotation.Nullable;
 import java.util.*;
 
 /**
@@ -16,6 +18,7 @@ public class FastMap<Value> {
     // property name (natural order for values) and using a binary search above a given size, but choosing that size
     // would likely be more effort than it's worth
     private final Map<Property<?>, Integer> toKeyIndex;
+    private final ImmutableSet<Property<?>> propertySet;
 
     public FastMap(
             Collection<Property<?>> properties, Map<Map<Property<?>, Comparable<?>>, Value> valuesMap, boolean compact
@@ -45,6 +48,7 @@ public class FastMap<Value> {
             valuesList.set(getIndexOf(state.getKey()), state.getValue());
         }
         this.valueMatrix = Collections.unmodifiableList(valuesList);
+        this.propertySet = ImmutableSet.copyOf(properties);
     }
 
     /**
@@ -149,4 +153,8 @@ public class FastMap<Value> {
     public boolean isSingleState() {
         return valueMatrix.size() == 1;
     }
+
+    public ImmutableSet<Property<?>> getPropertySet() {
+        return propertySet;
+    }
 }

+ 1 - 1
gradle.properties

@@ -9,4 +9,4 @@ maven_group=malte0811.ferritecore
 
 fabric_loader_version=0.11.3
 
-forge_version=37.0.44
+forge_version=37.0.57