Browse Source

Update some class names to match Mojmap rather than MCP

malte0811 4 years ago
parent
commit
cab7699875
21 changed files with 187 additions and 241 deletions
  1. 15 24
      common/src/main/java/malte0811/ferritecore/fastmap/PropertyIndexer.java
  2. 29 0
      common/src/main/java/malte0811/ferritecore/hash/ArrayVoxelShapeHash.java
  3. 30 0
      common/src/main/java/malte0811/ferritecore/hash/SliceShapeHash.java
  4. 0 45
      common/src/main/java/malte0811/ferritecore/hash/VoxelShapeArrayHash.java
  5. 26 17
      common/src/main/java/malte0811/ferritecore/hash/VoxelShapeHash.java
  6. 24 38
      common/src/main/java/malte0811/ferritecore/hash/VoxelShapePartHash.java
  7. 0 45
      common/src/main/java/malte0811/ferritecore/hash/VoxelShapeSplitHash.java
  8. 16 27
      common/src/main/java/malte0811/ferritecore/impl/BlockStateCacheImpl.java
  9. 5 2
      common/src/main/java/malte0811/ferritecore/impl/Deduplicator.java
  10. 10 6
      common/src/main/java/malte0811/ferritecore/impl/KeyValueConditionImpl.java
  11. 1 1
      common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/ArrayVSAccess.java
  12. 1 1
      common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/BitSetDVSAccess.java
  13. 1 1
      common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/BlockStateBaseMixin.java
  14. 1 1
      common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/DiscreteVSAccess.java
  15. 1 2
      common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/SliceShapeAccess.java
  16. 1 1
      common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/SubShapeAccess.java
  17. 1 4
      common/src/main/java/malte0811/ferritecore/mixin/mrl/ModelResourceLocationMixin.java
  18. 3 3
      common/src/main/java/malte0811/ferritecore/mixin/predicates/KeyValueConditionMixin.java
  19. 7 7
      common/src/main/resources/ferritecore.blockstatecache.mixin.json
  20. 2 2
      common/src/main/resources/ferritecore.predicates.mixin.json
  21. 13 14
      summary.md

+ 15 - 24
common/src/main/java/malte0811/ferritecore/fastmap/PropertyIndexer.java

@@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap;
 import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
 import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
-import javax.annotation.Nullable;
 import net.minecraft.Util;
 import net.minecraft.Util;
 import net.minecraft.core.Direction;
 import net.minecraft.core.Direction;
 import net.minecraft.util.StringRepresentable;
 import net.minecraft.util.StringRepresentable;
@@ -12,6 +11,8 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
 import net.minecraft.world.level.block.state.properties.EnumProperty;
 import net.minecraft.world.level.block.state.properties.EnumProperty;
 import net.minecraft.world.level.block.state.properties.IntegerProperty;
 import net.minecraft.world.level.block.state.properties.IntegerProperty;
 import net.minecraft.world.level.block.state.properties.Property;
 import net.minecraft.world.level.block.state.properties.Property;
+
+import javax.annotation.Nullable;
 import java.util.*;
 import java.util.*;
 
 
 /**
 /**
@@ -91,14 +92,11 @@ public abstract class PropertyIndexer<T extends Comparable<T>> {
         @Override
         @Override
         @Nullable
         @Nullable
         public Boolean byIndex(int index) {
         public Boolean byIndex(int index) {
-            switch (index) {
-                case 0:
-                    return Boolean.TRUE;
-                case 1:
-                    return Boolean.FALSE;
-                default:
-                    return null;
-            }
+            return switch (index) {
+                case 0 -> Boolean.TRUE;
+                case 1 -> Boolean.FALSE;
+                default -> null;
+            };
         }
         }
 
 
         @Override
         @Override
@@ -198,21 +196,14 @@ public abstract class PropertyIndexer<T extends Comparable<T>> {
 
 
         @Override
         @Override
         public int toIndex(Direction value) {
         public int toIndex(Direction value) {
-            switch (value) {
-                case NORTH:
-                    return 0;
-                case EAST:
-                    return 1;
-                case SOUTH:
-                    return 2;
-                case WEST:
-                    return 3;
-                case UP:
-                    return 4;
-                case DOWN:
-                    return 5;
-            }
-            return -1;
+            return switch (value) {
+                case NORTH -> 0;
+                case EAST -> 1;
+                case SOUTH -> 2;
+                case WEST -> 3;
+                case UP -> 4;
+                case DOWN -> 5;
+            };
         }
         }
     }
     }
 
 

+ 29 - 0
common/src/main/java/malte0811/ferritecore/hash/ArrayVoxelShapeHash.java

@@ -0,0 +1,29 @@
+package malte0811.ferritecore.hash;
+
+import it.unimi.dsi.fastutil.Hash;
+import malte0811.ferritecore.mixin.blockstatecache.ArrayVSAccess;
+
+import java.util.Objects;
+
+public class ArrayVoxelShapeHash implements Hash.Strategy<ArrayVSAccess> {
+    public static final ArrayVoxelShapeHash INSTANCE = new ArrayVoxelShapeHash();
+
+    @Override
+    public int hashCode(ArrayVSAccess o) {
+        return 31 * Objects.hash(o.getXPoints(), o.getYPoints(), o.getZPoints())
+                + VoxelShapePartHash.INSTANCE.hashCode(o.getShape());
+    }
+
+    @Override
+    public boolean equals(ArrayVSAccess a, ArrayVSAccess b) {
+        if (a == b) {
+            return true;
+        } else if (a == null || b == null) {
+            return false;
+        }
+        return Objects.equals(a.getXPoints(), b.getXPoints()) &&
+                Objects.equals(a.getYPoints(), b.getYPoints()) &&
+                Objects.equals(a.getZPoints(), b.getZPoints()) &&
+                VoxelShapePartHash.INSTANCE.equals(a.getShape(), b.getShape());
+    }
+}

+ 30 - 0
common/src/main/java/malte0811/ferritecore/hash/SliceShapeHash.java

@@ -0,0 +1,30 @@
+package malte0811.ferritecore.hash;
+
+import it.unimi.dsi.fastutil.Hash;
+import malte0811.ferritecore.mixin.blockstatecache.SliceShapeAccess;
+
+import java.util.Objects;
+
+public class SliceShapeHash implements Hash.Strategy<SliceShapeAccess> {
+    public static final SliceShapeHash INSTANCE = new SliceShapeHash();
+
+    @Override
+    public int hashCode(SliceShapeAccess o) {
+        int result = Objects.hashCode(o.getAxis());
+        result = 31 * result + VoxelShapePartHash.INSTANCE.hashCode(o.getShape());
+        result = 31 * result + VoxelShapeHash.INSTANCE.hashCode(o.getDelegate());
+        return result;
+    }
+
+    @Override
+    public boolean equals(SliceShapeAccess a, SliceShapeAccess b) {
+        if (a == b) {
+            return true;
+        } else if (a == null || b == null) {
+            return false;
+        }
+        return Objects.equals(a.getAxis(), b.getAxis()) &&
+                VoxelShapeHash.INSTANCE.equals(a.getDelegate(), b.getDelegate()) &&
+                VoxelShapePartHash.INSTANCE.equals(a.getShape(), b.getShape());
+    }
+}

+ 0 - 45
common/src/main/java/malte0811/ferritecore/hash/VoxelShapeArrayHash.java

@@ -1,45 +0,0 @@
-package malte0811.ferritecore.hash;
-
-import it.unimi.dsi.fastutil.Hash;
-import malte0811.ferritecore.mixin.blockstatecache.VSArrayAccess;
-import malte0811.ferritecore.mixin.blockstatecache.VoxelShapeAccess;
-import net.minecraft.world.phys.shapes.ArrayVoxelShape;
-import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
-import net.minecraft.world.phys.shapes.VoxelShape;
-
-import java.util.Objects;
-
-public class VoxelShapeArrayHash implements Hash.Strategy<ArrayVoxelShape> {
-    public static final VoxelShapeArrayHash INSTANCE = new VoxelShapeArrayHash();
-
-    @Override
-    public int hashCode(ArrayVoxelShape o) {
-        VSArrayAccess access = access(o);
-        return 31 * Objects.hash(access.getXPoints(), access.getYPoints(), access.getZPoints())
-                + VoxelShapePartHash.INSTANCE.hashCode(getPart(o));
-    }
-
-    @Override
-    public boolean equals(ArrayVoxelShape a, ArrayVoxelShape b) {
-        if (a == b) {
-            return true;
-        } else if (a == null || b == null) {
-            return false;
-        }
-        VSArrayAccess accessA = access(a);
-        VSArrayAccess accessB = access(b);
-        return Objects.equals(accessA.getXPoints(), accessB.getXPoints()) &&
-                Objects.equals(accessA.getYPoints(), accessB.getYPoints()) &&
-                Objects.equals(accessA.getZPoints(), accessB.getZPoints()) &&
-                VoxelShapePartHash.INSTANCE.equals(getPart(a), getPart(b));
-    }
-
-    @SuppressWarnings("ConstantConditions")
-    private static VSArrayAccess access(ArrayVoxelShape a) {
-        return (VSArrayAccess) (Object) a;
-    }
-
-    private static DiscreteVoxelShape getPart(VoxelShape a) {
-        return ((VoxelShapeAccess) a).getShape();
-    }
-}

+ 26 - 17
common/src/main/java/malte0811/ferritecore/hash/VoxelShapeHash.java

@@ -1,10 +1,10 @@
 package malte0811.ferritecore.hash;
 package malte0811.ferritecore.hash;
 
 
 import it.unimi.dsi.fastutil.Hash;
 import it.unimi.dsi.fastutil.Hash;
+import malte0811.ferritecore.mixin.blockstatecache.ArrayVSAccess;
+import malte0811.ferritecore.mixin.blockstatecache.SliceShapeAccess;
 import malte0811.ferritecore.mixin.blockstatecache.VoxelShapeAccess;
 import malte0811.ferritecore.mixin.blockstatecache.VoxelShapeAccess;
-import net.minecraft.world.phys.shapes.ArrayVoxelShape;
 import net.minecraft.world.phys.shapes.CubeVoxelShape;
 import net.minecraft.world.phys.shapes.CubeVoxelShape;
-import net.minecraft.world.phys.shapes.SliceShape;
 import net.minecraft.world.phys.shapes.VoxelShape;
 import net.minecraft.world.phys.shapes.VoxelShape;
 
 
 public class VoxelShapeHash implements Hash.Strategy<VoxelShape> {
 public class VoxelShapeHash implements Hash.Strategy<VoxelShape> {
@@ -12,36 +12,45 @@ public class VoxelShapeHash implements Hash.Strategy<VoxelShape> {
 
 
     @Override
     @Override
     public int hashCode(VoxelShape o) {
     public int hashCode(VoxelShape o) {
-        if (o instanceof SliceShape) {
-            return VoxelShapeSplitHash.INSTANCE.hashCode((SliceShape) o);
-        } else if (o instanceof ArrayVoxelShape) {
-            return VoxelShapeArrayHash.INSTANCE.hashCode((ArrayVoxelShape) o);
-        } else if (o instanceof CubeVoxelShape) {
-            return VoxelShapePartHash.INSTANCE.hashCode(((VoxelShapeAccess) o).getShape());
+        return hashCode((VoxelShapeAccess) o);
+    }
+
+    public int hashCode(VoxelShapeAccess o) {
+        if (o instanceof SliceShapeAccess access) {
+            return SliceShapeHash.INSTANCE.hashCode(access);
+        } else if (o instanceof ArrayVSAccess access) {
+            return ArrayVoxelShapeHash.INSTANCE.hashCode(access);
+        } else if (isCubeShape(o)) {
+            return VoxelShapePartHash.INSTANCE.hashCode(o.getShape());
         } else {
         } else {
-            //TODO VSCube?
             return o.hashCode();
             return o.hashCode();
         }
         }
     }
     }
 
 
     @Override
     @Override
     public boolean equals(VoxelShape a, VoxelShape b) {
     public boolean equals(VoxelShape a, VoxelShape b) {
+        return equals((VoxelShapeAccess) a, (VoxelShapeAccess) b);
+    }
+
+    public boolean equals(VoxelShapeAccess a, VoxelShapeAccess b) {
         if (a == b) {
         if (a == b) {
             return true;
             return true;
         } else if (a == null || b == null) {
         } else if (a == null || b == null) {
             return false;
             return false;
         } else if (a.getClass() != b.getClass()) {
         } else if (a.getClass() != b.getClass()) {
             return false;
             return false;
-        } else if (a instanceof SliceShape) {
-            return VoxelShapeSplitHash.INSTANCE.equals((SliceShape) a, (SliceShape) b);
-        } else if (a instanceof ArrayVoxelShape) {
-            return VoxelShapeArrayHash.INSTANCE.equals((ArrayVoxelShape) a, (ArrayVoxelShape) b);
-        } else if (a instanceof CubeVoxelShape) {
-            return VoxelShapePartHash.INSTANCE.equals(
-                    ((VoxelShapeAccess) a).getShape(), ((VoxelShapeAccess) b).getShape()
-            );
+        } else if (a instanceof SliceShapeAccess accessA) {
+            return SliceShapeHash.INSTANCE.equals(accessA, (SliceShapeAccess) b);
+        } else if (a instanceof ArrayVSAccess accessA) {
+            return ArrayVoxelShapeHash.INSTANCE.equals(accessA, (ArrayVSAccess) b);
+        } else if (isCubeShape(a)) {
+            return VoxelShapePartHash.INSTANCE.equals(a.getShape(), b.getShape());
         } else {
         } else {
             return a.equals(b);
             return a.equals(b);
         }
         }
     }
     }
+
+    private boolean isCubeShape(Object o) {
+        return o instanceof CubeVoxelShape;
+    }
 }
 }

+ 24 - 38
common/src/main/java/malte0811/ferritecore/hash/VoxelShapePartHash.java

@@ -1,12 +1,10 @@
 package malte0811.ferritecore.hash;
 package malte0811.ferritecore.hash;
 
 
 import it.unimi.dsi.fastutil.Hash;
 import it.unimi.dsi.fastutil.Hash;
-import malte0811.ferritecore.mixin.blockstatecache.VSPBitSetAccess;
-import malte0811.ferritecore.mixin.blockstatecache.VSPSplitAccess;
-import malte0811.ferritecore.mixin.blockstatecache.VSPartAccess;
-import net.minecraft.world.phys.shapes.BitSetDiscreteVoxelShape;
+import malte0811.ferritecore.mixin.blockstatecache.BitSetDVSAccess;
+import malte0811.ferritecore.mixin.blockstatecache.DiscreteVSAccess;
+import malte0811.ferritecore.mixin.blockstatecache.SubShapeAccess;
 import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
 import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
-import net.minecraft.world.phys.shapes.SubShape;
 
 
 import java.util.Objects;
 import java.util.Objects;
 
 
@@ -14,23 +12,24 @@ public class VoxelShapePartHash implements Hash.Strategy<DiscreteVoxelShape> {
     public static final VoxelShapePartHash INSTANCE = new VoxelShapePartHash();
     public static final VoxelShapePartHash INSTANCE = new VoxelShapePartHash();
 
 
     @Override
     @Override
-    public int hashCode(DiscreteVoxelShape o) {
-        VSPartAccess generalAccess = (VSPartAccess) o;
-        int result = generalAccess.getXSize();
-        result = 31 * result + generalAccess.getYSize();
-        result = 31 * result + generalAccess.getZSize();
-        if (o instanceof SubShape) {
-            VSPSplitAccess access = access((SubShape) o);
+    public int hashCode(DiscreteVoxelShape shape) {
+        return hashCode((DiscreteVSAccess) shape);
+    }
+
+    public int hashCode(DiscreteVSAccess o) {
+        int result = o.getXSize();
+        result = 31 * result + o.getYSize();
+        result = 31 * result + o.getZSize();
+        if (o instanceof SubShapeAccess access) {
             result = 31 * result + access.getStartX();
             result = 31 * result + access.getStartX();
             result = 31 * result + access.getStartY();
             result = 31 * result + access.getStartY();
             result = 31 * result + access.getStartZ();
             result = 31 * result + access.getStartZ();
             result = 31 * result + access.getEndX();
             result = 31 * result + access.getEndX();
             result = 31 * result + access.getEndY();
             result = 31 * result + access.getEndY();
             result = 31 * result + access.getEndZ();
             result = 31 * result + access.getEndZ();
-            result = 31 * result + hashCode(access.getParent());
+            result = 31 * result + hashCode((DiscreteVSAccess) access.getParent());
             return result;
             return result;
-        } else if (o instanceof BitSetDiscreteVoxelShape) {
-            VSPBitSetAccess access = access((BitSetDiscreteVoxelShape) o);
+        } else if (o instanceof BitSetDVSAccess access) {
             result = 31 * result + access.getXMin();
             result = 31 * result + access.getXMin();
             result = 31 * result + access.getYMin();
             result = 31 * result + access.getYMin();
             result = 31 * result + access.getZMin();
             result = 31 * result + access.getZMin();
@@ -46,6 +45,10 @@ public class VoxelShapePartHash implements Hash.Strategy<DiscreteVoxelShape> {
 
 
     @Override
     @Override
     public boolean equals(DiscreteVoxelShape a, DiscreteVoxelShape b) {
     public boolean equals(DiscreteVoxelShape a, DiscreteVoxelShape b) {
+        return equals((DiscreteVSAccess) a, (DiscreteVSAccess) b);
+    }
+
+    public boolean equals(DiscreteVSAccess a, DiscreteVSAccess b) {
         if (a == b) {
         if (a == b) {
             return true;
             return true;
         } else if (a == null || b == null) {
         } else if (a == null || b == null) {
@@ -53,27 +56,20 @@ public class VoxelShapePartHash implements Hash.Strategy<DiscreteVoxelShape> {
         } else if (a.getClass() != b.getClass()) {
         } else if (a.getClass() != b.getClass()) {
             return false;
             return false;
         }
         }
-        VSPartAccess genAccessA = (VSPartAccess) a;
-        VSPartAccess genAccessB = (VSPartAccess) b;
-        if (genAccessA.getXSize() != genAccessB.getXSize() ||
-                genAccessA.getYSize() != genAccessB.getYSize() ||
-                genAccessA.getZSize() != genAccessB.getZSize()
-        ) {
+        if (a.getXSize() != b.getXSize() || a.getYSize() != b.getYSize() || a.getZSize() != b.getZSize()) {
             return false;
             return false;
         }
         }
-        if (a instanceof SubShape) {
-            VSPSplitAccess accessA = access((SubShape) a);
-            VSPSplitAccess accessB = access((SubShape) b);
+        if (a instanceof SubShapeAccess accessA) {
+            SubShapeAccess accessB = (SubShapeAccess) b;
             return accessA.getEndX() == accessB.getEndX() &&
             return accessA.getEndX() == accessB.getEndX() &&
                     accessA.getEndY() == accessB.getEndY() &&
                     accessA.getEndY() == accessB.getEndY() &&
                     accessA.getEndZ() == accessB.getEndZ() &&
                     accessA.getEndZ() == accessB.getEndZ() &&
                     accessA.getStartX() == accessB.getStartX() &&
                     accessA.getStartX() == accessB.getStartX() &&
                     accessA.getStartY() == accessB.getStartY() &&
                     accessA.getStartY() == accessB.getStartY() &&
                     accessA.getStartZ() == accessB.getStartZ() &&
                     accessA.getStartZ() == accessB.getStartZ() &&
-                    equals(accessA.getParent(), accessB.getParent());
-        } else if (a instanceof BitSetDiscreteVoxelShape) {
-            VSPBitSetAccess accessA = access((BitSetDiscreteVoxelShape) a);
-            VSPBitSetAccess accessB = access((BitSetDiscreteVoxelShape) b);
+                    equals((DiscreteVSAccess) accessA.getParent(), (DiscreteVSAccess) accessB.getParent());
+        } else if (a instanceof BitSetDVSAccess accessA) {
+            BitSetDVSAccess accessB = (BitSetDVSAccess) b;
             return accessA.getXMax() == accessB.getXMax() &&
             return accessA.getXMax() == accessB.getXMax() &&
                     accessA.getYMax() == accessB.getYMax() &&
                     accessA.getYMax() == accessB.getYMax() &&
                     accessA.getZMax() == accessB.getZMax() &&
                     accessA.getZMax() == accessB.getZMax() &&
@@ -85,14 +81,4 @@ public class VoxelShapePartHash implements Hash.Strategy<DiscreteVoxelShape> {
             return a.equals(b);
             return a.equals(b);
         }
         }
     }
     }
-
-    @SuppressWarnings("ConstantConditions")
-    private static VSPSplitAccess access(SubShape part) {
-        return (VSPSplitAccess) (Object) part;
-    }
-
-    @SuppressWarnings("ConstantConditions")
-    private static VSPBitSetAccess access(BitSetDiscreteVoxelShape part) {
-        return (VSPBitSetAccess) (Object) part;
-    }
 }
 }

+ 0 - 45
common/src/main/java/malte0811/ferritecore/hash/VoxelShapeSplitHash.java

@@ -1,45 +0,0 @@
-package malte0811.ferritecore.hash;
-
-import it.unimi.dsi.fastutil.Hash;
-import malte0811.ferritecore.mixin.blockstatecache.VSSplitAccess;
-import malte0811.ferritecore.mixin.blockstatecache.VoxelShapeAccess;
-import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
-import net.minecraft.world.phys.shapes.SliceShape;
-import net.minecraft.world.phys.shapes.VoxelShape;
-
-import java.util.Objects;
-
-public class VoxelShapeSplitHash implements Hash.Strategy<SliceShape> {
-    public static final VoxelShapeSplitHash INSTANCE = new VoxelShapeSplitHash();
-
-    @Override
-    public int hashCode(SliceShape o) {
-        VSSplitAccess access = access(o);
-        int result = Objects.hashCode(access.getAxis());
-        result = 31 * result + VoxelShapePartHash.INSTANCE.hashCode(getPart(o));
-        result = 31 * result + VoxelShapeHash.INSTANCE.hashCode(access.getDelegate());
-        return result;
-    }
-
-    @Override
-    public boolean equals(SliceShape a, SliceShape b) {
-        if (a == b) {
-            return true;
-        } else if (a == null || b == null) {
-            return false;
-        }
-        VSSplitAccess accessA = access(a);
-        VSSplitAccess accessB = access(b);
-        return Objects.equals(accessA.getAxis(), accessB.getAxis()) &&
-                VoxelShapeHash.INSTANCE.equals(accessA.getDelegate(), accessB.getDelegate()) &&
-                VoxelShapePartHash.INSTANCE.equals(getPart(a), getPart(b));
-    }
-
-    private static VSSplitAccess access(SliceShape a) {
-        return (VSSplitAccess) a;
-    }
-
-    private static DiscreteVoxelShape getPart(VoxelShape a) {
-        return ((VoxelShapeAccess) a).getShape();
-    }
-}

+ 16 - 27
common/src/main/java/malte0811/ferritecore/impl/BlockStateCacheImpl.java

@@ -2,16 +2,14 @@ package malte0811.ferritecore.impl;
 
 
 import com.google.common.base.Suppliers;
 import com.google.common.base.Suppliers;
 import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
 import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
-import malte0811.ferritecore.hash.VoxelShapeArrayHash;
+import malte0811.ferritecore.hash.ArrayVoxelShapeHash;
 import malte0811.ferritecore.hash.VoxelShapeHash;
 import malte0811.ferritecore.hash.VoxelShapeHash;
+import malte0811.ferritecore.mixin.blockstatecache.ArrayVSAccess;
 import malte0811.ferritecore.mixin.blockstatecache.BlockStateCacheAccess;
 import malte0811.ferritecore.mixin.blockstatecache.BlockStateCacheAccess;
-import malte0811.ferritecore.mixin.blockstatecache.VSArrayAccess;
-import malte0811.ferritecore.mixin.blockstatecache.VSSplitAccess;
-import malte0811.ferritecore.mixin.blockstatecache.VoxelShapeAccess;
+import malte0811.ferritecore.mixin.blockstatecache.SliceShapeAccess;
 import malte0811.ferritecore.util.Constants;
 import malte0811.ferritecore.util.Constants;
 import net.minecraft.world.level.block.state.BlockBehaviour.BlockStateBase;
 import net.minecraft.world.level.block.state.BlockBehaviour.BlockStateBase;
 import net.minecraft.world.phys.shapes.ArrayVoxelShape;
 import net.minecraft.world.phys.shapes.ArrayVoxelShape;
-import net.minecraft.world.phys.shapes.SliceShape;
 import net.minecraft.world.phys.shapes.VoxelShape;
 import net.minecraft.world.phys.shapes.VoxelShape;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.lang3.tuple.Pair;
 
 
@@ -24,8 +22,8 @@ import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.function.Supplier;
 
 
 public class BlockStateCacheImpl {
 public class BlockStateCacheImpl {
-    public static final Map<ArrayVoxelShape, ArrayVoxelShape> CACHE_COLLIDE = new Object2ObjectOpenCustomHashMap<>(
-            VoxelShapeArrayHash.INSTANCE
+    public static final Map<ArrayVSAccess, ArrayVSAccess> CACHE_COLLIDE = new Object2ObjectOpenCustomHashMap<>(
+            ArrayVoxelShapeHash.INSTANCE
     );
     );
     // Maps a shape to the "canonical instance" of that shape and its side projections
     // Maps a shape to the "canonical instance" of that shape and its side projections
     public static final Map<VoxelShape, Pair<VoxelShape, VoxelShape[]>> CACHE_PROJECT =
     public static final Map<VoxelShape, Pair<VoxelShape, VoxelShape[]>> CACHE_PROJECT =
@@ -79,10 +77,8 @@ public class BlockStateCacheImpl {
             dedupedCollisionShape = oldCache.getCollisionShape();
             dedupedCollisionShape = oldCache.getCollisionShape();
         } else {
         } else {
             dedupedCollisionShape = newCache.getCollisionShape();
             dedupedCollisionShape = newCache.getCollisionShape();
-            if (dedupedCollisionShape instanceof ArrayVoxelShape) {
-                dedupedCollisionShape = CACHE_COLLIDE.computeIfAbsent(
-                        (ArrayVoxelShape) dedupedCollisionShape, Function.identity()
-                );
+            if (dedupedCollisionShape instanceof ArrayVSAccess access) {
+                dedupedCollisionShape = (VoxelShape) CACHE_COLLIDE.computeIfAbsent(access, Function.identity());
             }
             }
         }
         }
         replaceInternals(dedupedCollisionShape, newCache.getCollisionShape());
         replaceInternals(dedupedCollisionShape, newCache.getCollisionShape());
@@ -131,28 +127,21 @@ public class BlockStateCacheImpl {
         // that we can't do anything about shallow size and replace the internals with those used in the cache. This is
         // that we can't do anything about shallow size and replace the internals with those used in the cache. This is
         // not theoretically 100% safe since VSs can technically be modified after they are created, but handing out VSs
         // not theoretically 100% safe since VSs can technically be modified after they are created, but handing out VSs
         // that will be modified is unsafe in any case since a lot of vanilla code relies on VSs being immutable.
         // that will be modified is unsafe in any case since a lot of vanilla code relies on VSs being immutable.
-        access(toReplace).setXPoints(access(toKeep).getXPoints());
-        access(toReplace).setYPoints(access(toKeep).getYPoints());
-        access(toReplace).setZPoints(access(toKeep).getZPoints());
-        accessVS(toReplace).setFaces(accessVS(toKeep).getFaces());
-        accessVS(toReplace).setShape(accessVS(toKeep).getShape());
-    }
-
-    @SuppressWarnings("ConstantConditions")
-    private static VSArrayAccess access(ArrayVoxelShape a) {
-        return (VSArrayAccess) (Object) a;
-    }
-
-    private static VoxelShapeAccess accessVS(VoxelShape a) {
-        return (VoxelShapeAccess) a;
+        ArrayVSAccess toReplaceAccess = (ArrayVSAccess) toReplace;
+        ArrayVSAccess toKeepAccess = (ArrayVSAccess) toKeep;
+        toReplaceAccess.setXPoints(toKeepAccess.getXPoints());
+        toReplaceAccess.setYPoints(toKeepAccess.getYPoints());
+        toReplaceAccess.setZPoints(toKeepAccess.getZPoints());
+        toReplaceAccess.setFaces(toKeepAccess.getFaces());
+        toReplaceAccess.setShape(toKeepAccess.getShape());
     }
     }
 
 
     @Nullable
     @Nullable
     private static VoxelShape getRenderShape(@Nullable VoxelShape[] projected) {
     private static VoxelShape getRenderShape(@Nullable VoxelShape[] projected) {
         if (projected != null) {
         if (projected != null) {
             for (VoxelShape side : projected) {
             for (VoxelShape side : projected) {
-                if (side instanceof SliceShape) {
-                    return ((VSSplitAccess) side).getDelegate();
+                if (side instanceof SliceShapeAccess slice) {
+                    return slice.getDelegate();
                 }
                 }
             }
             }
         }
         }

+ 5 - 2
common/src/main/java/malte0811/ferritecore/impl/Deduplicator.java

@@ -15,6 +15,7 @@ import net.minecraft.server.packs.resources.SimplePreparableReloadListener;
 import net.minecraft.util.profiling.ProfilerFiller;
 import net.minecraft.util.profiling.ProfilerFiller;
 import net.minecraft.world.level.block.state.BlockState;
 import net.minecraft.world.level.block.state.BlockState;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.lang3.tuple.Pair;
+import org.jetbrains.annotations.NotNull;
 
 
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
@@ -60,12 +61,14 @@ public class Deduplicator {
         // Register the reload listener s.t. its "sync" part runs after the model loader reload
         // Register the reload listener s.t. its "sync" part runs after the model loader reload
         ((ReloadableResourceManager) Minecraft.getInstance().getResourceManager()).registerReloadListener(new SimplePreparableReloadListener<Unit>() {
         ((ReloadableResourceManager) Minecraft.getInstance().getResourceManager()).registerReloadListener(new SimplePreparableReloadListener<Unit>() {
             @Override
             @Override
-            protected Unit prepare(ResourceManager iResourceManager, ProfilerFiller iProfiler) {
+            protected Unit prepare(@NotNull ResourceManager resourceManager, @NotNull ProfilerFiller profiler) {
                 return Unit.INSTANCE;
                 return Unit.INSTANCE;
             }
             }
 
 
             @Override
             @Override
-            protected void apply(Unit object, ResourceManager iResourceManager, ProfilerFiller iProfiler) {
+            protected void apply(
+                    @NotNull Unit object, @NotNull ResourceManager resourceManager, @NotNull ProfilerFiller profiler
+            ) {
                 VARIANT_IDENTITIES.clear();
                 VARIANT_IDENTITIES.clear();
                 KNOWN_MULTIPART_MODELS.clear();
                 KNOWN_MULTIPART_MODELS.clear();
                 OR_PREDICATE_CACHE.clear();
                 OR_PREDICATE_CACHE.clear();

+ 10 - 6
common/src/main/java/malte0811/ferritecore/impl/PropertyValueConditionImpl.java → common/src/main/java/malte0811/ferritecore/impl/KeyValueConditionImpl.java

@@ -15,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Predicate;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
-public class PropertyValueConditionImpl {
+public class KeyValueConditionImpl {
     private static final Map<Pair<Property<?>, Comparable<?>>, Predicate<BlockState>> STATE_HAS_PROPERTY_CACHE = new ConcurrentHashMap<>();
     private static final Map<Pair<Property<?>, Comparable<?>>, Predicate<BlockState>> STATE_HAS_PROPERTY_CACHE = new ConcurrentHashMap<>();
 
 
     /**
     /**
@@ -46,10 +46,10 @@ public class PropertyValueConditionImpl {
             } else {
             } else {
                 Predicate<BlockState> isMatchedState;
                 Predicate<BlockState> isMatchedState;
                 if (matchedStates.size() == 1) {
                 if (matchedStates.size() == 1) {
-                    isMatchedState = makePropertyPredicate(stateContainer, property, valueNoInvert, key, value);
+                    isMatchedState = getBlockStatePredicate(stateContainer, property, valueNoInvert, key, value);
                 } else {
                 } else {
                     List<Predicate<BlockState>> subPredicates = matchedStates.stream()
                     List<Predicate<BlockState>> subPredicates = matchedStates.stream()
-                            .map(subValue -> makePropertyPredicate(stateContainer, property, subValue, key, value))
+                            .map(subValue -> getBlockStatePredicate(stateContainer, property, subValue, key, value))
                             .collect(Collectors.toList());
                             .collect(Collectors.toList());
                     // This line is the only functional change, but targeting it with anything but Overwrite appears to
                     // This line is the only functional change, but targeting it with anything but Overwrite appears to
                     // be impossible
                     // be impossible
@@ -63,11 +63,15 @@ public class PropertyValueConditionImpl {
     }
     }
 
 
     private static <T extends Comparable<T>>
     private static <T extends Comparable<T>>
-    Predicate<BlockState> makePropertyPredicate(
-            StateDefinition<Block, BlockState> container, Property<T> property, String subValue, String key, String value
+    Predicate<BlockState> getBlockStatePredicate(
+            StateDefinition<Block, BlockState> container,
+            Property<T> property,
+            String subValue,
+            String key,
+            String value
     ) {
     ) {
         Optional<T> optional = property.getValue(subValue);
         Optional<T> optional = property.getValue(subValue);
-        if (!optional.isPresent()) {
+        if (optional.isEmpty()) {
             throw new RuntimeException(String.format(
             throw new RuntimeException(String.format(
                     "Unknown value '%s' for property '%s' on '%s' in '%s'",
                     "Unknown value '%s' for property '%s' on '%s' in '%s'",
                     subValue, key, container.getOwner().toString(), value
                     subValue, key, container.getOwner().toString(), value

+ 1 - 1
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/VSArrayAccess.java → common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/ArrayVSAccess.java

@@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.Mutable;
 import org.spongepowered.asm.mixin.gen.Accessor;
 import org.spongepowered.asm.mixin.gen.Accessor;
 
 
 @Mixin(ArrayVoxelShape.class)
 @Mixin(ArrayVoxelShape.class)
-public interface VSArrayAccess {
+public interface ArrayVSAccess extends VoxelShapeAccess {
     @Accessor("xs")
     @Accessor("xs")
     @Mutable
     @Mutable
     void setXPoints(DoubleList newPoints);
     void setXPoints(DoubleList newPoints);

+ 1 - 1
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/VSPBitSetAccess.java → common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/BitSetDVSAccess.java

@@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.gen.Accessor;
 import java.util.BitSet;
 import java.util.BitSet;
 
 
 @Mixin(BitSetDiscreteVoxelShape.class)
 @Mixin(BitSetDiscreteVoxelShape.class)
-public interface VSPBitSetAccess {
+public interface BitSetDVSAccess extends DiscreteVSAccess {
     @Accessor
     @Accessor
     BitSet getStorage();
     BitSet getStorage();
 
 

+ 1 - 1
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/AbstractBlockStateMixin.java → common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/BlockStateBaseMixin.java

@@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 
 
 @Mixin(BlockBehaviour.BlockStateBase.class)
 @Mixin(BlockBehaviour.BlockStateBase.class)
-public class AbstractBlockStateMixin {
+public class BlockStateBaseMixin {
     @Inject(method = "initCache", at = @At("HEAD"))
     @Inject(method = "initCache", at = @At("HEAD"))
     public void cacheStateHead(CallbackInfo ci) {
     public void cacheStateHead(CallbackInfo ci) {
         BlockStateCacheImpl.deduplicateCachePre((BlockBehaviour.BlockStateBase) (Object) this);
         BlockStateCacheImpl.deduplicateCachePre((BlockBehaviour.BlockStateBase) (Object) this);

+ 1 - 1
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/VSPartAccess.java → common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/DiscreteVSAccess.java

@@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.gen.Accessor;
 import org.spongepowered.asm.mixin.gen.Accessor;
 
 
 @Mixin(DiscreteVoxelShape.class)
 @Mixin(DiscreteVoxelShape.class)
-public interface VSPartAccess {
+public interface DiscreteVSAccess {
     @Accessor
     @Accessor
     int getXSize();
     int getXSize();
 
 

+ 1 - 2
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/VSSplitAccess.java → common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/SliceShapeAccess.java

@@ -4,11 +4,10 @@ import net.minecraft.core.Direction;
 import net.minecraft.world.phys.shapes.SliceShape;
 import net.minecraft.world.phys.shapes.SliceShape;
 import net.minecraft.world.phys.shapes.VoxelShape;
 import net.minecraft.world.phys.shapes.VoxelShape;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Mutable;
 import org.spongepowered.asm.mixin.gen.Accessor;
 import org.spongepowered.asm.mixin.gen.Accessor;
 
 
 @Mixin(SliceShape.class)
 @Mixin(SliceShape.class)
-public interface VSSplitAccess {
+public interface SliceShapeAccess extends VoxelShapeAccess {
     @Accessor
     @Accessor
     VoxelShape getDelegate();
     VoxelShape getDelegate();
 
 

+ 1 - 1
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/VSPSplitAccess.java → common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/SubShapeAccess.java

@@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.gen.Accessor;
 import org.spongepowered.asm.mixin.gen.Accessor;
 
 
 @Mixin(SubShape.class)
 @Mixin(SubShape.class)
-public interface VSPSplitAccess {
+public interface SubShapeAccess extends DiscreteVSAccess {
     @Accessor
     @Accessor
     DiscreteVoxelShape getParent();
     DiscreteVoxelShape getParent();
 
 

+ 1 - 4
common/src/main/java/malte0811/ferritecore/mixin/mrl/ModelResourceLocationMixin.java

@@ -18,10 +18,7 @@ public class ModelResourceLocationMixin {
     @Mutable
     @Mutable
     private String variant;
     private String variant;
 
 
-    @Inject(
-            method = "<init>(Lnet/minecraft/resources/ResourceLocation;Ljava/lang/String;)V",
-            at = @At("TAIL")
-    )
+    @Inject(method = "<init>(Lnet/minecraft/resources/ResourceLocation;Ljava/lang/String;)V", at = @At("TAIL"))
     private void constructTail(ResourceLocation location, String variantIn, CallbackInfo ci) {
     private void constructTail(ResourceLocation location, String variantIn, CallbackInfo ci) {
         // Do not use new strings for path and namespace, and deduplicate the variant string
         // Do not use new strings for path and namespace, and deduplicate the variant string
         ((ResourceLocationAccess) this).setPath(location.getPath());
         ((ResourceLocationAccess) this).setPath(location.getPath());

+ 3 - 3
common/src/main/java/malte0811/ferritecore/mixin/predicates/PropertyValueConditionMixin.java → common/src/main/java/malte0811/ferritecore/mixin/predicates/KeyValueConditionMixin.java

@@ -1,7 +1,7 @@
 package malte0811.ferritecore.mixin.predicates;
 package malte0811.ferritecore.mixin.predicates;
 
 
 import com.google.common.base.Splitter;
 import com.google.common.base.Splitter;
-import malte0811.ferritecore.impl.PropertyValueConditionImpl;
+import malte0811.ferritecore.impl.KeyValueConditionImpl;
 import net.minecraft.client.renderer.block.model.multipart.KeyValueCondition;
 import net.minecraft.client.renderer.block.model.multipart.KeyValueCondition;
 import net.minecraft.world.level.block.Block;
 import net.minecraft.world.level.block.Block;
 import net.minecraft.world.level.block.state.BlockState;
 import net.minecraft.world.level.block.state.BlockState;
@@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.Shadow;
 import java.util.function.Predicate;
 import java.util.function.Predicate;
 
 
 @Mixin(value = KeyValueCondition.class, priority = 2000)
 @Mixin(value = KeyValueCondition.class, priority = 2000)
-public class PropertyValueConditionMixin {
+public class KeyValueConditionMixin {
     @Shadow
     @Shadow
     @Final
     @Final
     private String key;
     private String key;
@@ -34,6 +34,6 @@ public class PropertyValueConditionMixin {
      */
      */
     @Overwrite
     @Overwrite
     public Predicate<BlockState> getPredicate(StateDefinition<Block, BlockState> stateContainer) {
     public Predicate<BlockState> getPredicate(StateDefinition<Block, BlockState> stateContainer) {
-        return PropertyValueConditionImpl.getPredicate(stateContainer, key, value, PIPE_SPLITTER);
+        return KeyValueConditionImpl.getPredicate(stateContainer, key, value, PIPE_SPLITTER);
     }
     }
 }
 }

+ 7 - 7
common/src/main/resources/ferritecore.blockstatecache.mixin.json

@@ -10,13 +10,13 @@
   "minVersion": "0.8",
   "minVersion": "0.8",
   "plugin": "malte0811.ferritecore.mixin.blockstatecache.Config",
   "plugin": "malte0811.ferritecore.mixin.blockstatecache.Config",
   "mixins": [
   "mixins": [
-    "AbstractBlockStateMixin",
+    "ArrayVSAccess",
+    "BitSetDVSAccess",
+    "BlockStateBaseMixin",
     "BlockStateCacheAccess",
     "BlockStateCacheAccess",
-    "VoxelShapeAccess",
-    "VSArrayAccess",
-    "VSPartAccess",
-    "VSPBitSetAccess",
-    "VSPSplitAccess",
-    "VSSplitAccess"
+    "DiscreteVSAccess",
+    "SliceShapeAccess",
+    "SubShapeAccess",
+    "VoxelShapeAccess"
   ]
   ]
 }
 }

+ 2 - 2
common/src/main/resources/ferritecore.predicates.mixin.json

@@ -4,8 +4,8 @@
   "compatibilityLevel": "JAVA_16",
   "compatibilityLevel": "JAVA_16",
   "client": [
   "client": [
     "AndConditionMixin",
     "AndConditionMixin",
-    "OrConditionMixin",
-    "PropertyValueConditionMixin"
+    "KeyValueConditionMixin",
+    "OrConditionMixin"
   ],
   ],
   "injectors": {
   "injectors": {
     "defaultRequire": 1
     "defaultRequire": 1

+ 13 - 14
summary.md

@@ -4,7 +4,7 @@ first 4 points refers to a ForgeCraft 1 instance around 19th December 2020, afte
 which is great for rapid mod updates, but also makes reproducible tests near-impossible (and means that I can't test
 which is great for rapid mod updates, but also makes reproducible tests near-impossible (and means that I can't test
 when the server is down :smile:)
 when the server is down :smile:)
 
 
-### 1. Optionals in `PropertyValueCondition`
+### 1. Optionals in `KeyValueCondition`
 
 
 This change is made obsolete by the 4th point, it is only included in this list for completeness.
 This change is made obsolete by the 4th point, it is only included in this list for completeness.
 
 
@@ -62,19 +62,18 @@ Notes: If this is ever included in Forge the custom `ImmutableMap` should probab
 new `getValues` method returning a `map` rather than an `ImmutableMap` should be added
 new `getValues` method returning a `map` rather than an `ImmutableMap` should be added
 
 
 ### 4. Multipart model predicate caching
 ### 4. Multipart model predicate caching
-Each multipart model stores a number of predicates to determine which parts to show under
-what conditions. These predicates take up 300-400 MB. However in many cases these
-predicates are checking the same thing, they are just newly created every time. For
-`PropertyValueCondition` the predicates can be cached by using the property and its value
-as a key, for `And/OrCondition` (and multi-value `PropertyValueCondition`s) the key is the
-list of input predicates sorted by hash value.  
-One detail that makes this even more effective is that a block can never have two
-properties that are equal according to `equals`, while the common property implementations
-include `equals`. Additionally `StateHolder#get` also considers `equals` (as opposed to
-reference equality), so using the same lambda for equivalent (but non reference-equivalent) properties and values is
-actually possible. This is particularly useful as one of the most common usages of multipart models is pipes, where the
-states are nearly always boolean properties named `north` etc. As a result the number of predicates is reduced from
-between 10s of thousands and millions to a few ten or hundred instances.
+
+Each multipart model stores a number of predicates to determine which parts to show under what conditions. These
+predicates take up 300-400 MB. However in many cases these predicates are checking the same thing, they are just newly
+created every time. For
+`KeyValueCondition` the predicates can be cached by using the property and its value as a key, for `And/OrCondition` (
+and multi-value `KeyValueCondition`s) the key is the list of input predicates sorted by hash value.  
+One detail that makes this even more effective is that a block can never have two properties that are equal according
+to `equals`, while the common property implementations include `equals`. Additionally `StateHolder#get` also
+considers `equals` (as opposed to reference equality), so using the same lambda for equivalent (but non
+reference-equivalent) properties and values is actually possible. This is particularly useful as one of the most common
+usages of multipart models is pipes, where the states are nearly always boolean properties named `north` etc. As a
+result the number of predicates is reduced from between 10s of thousands and millions to a few ten or hundred instances.
 
 
 Saved memory: 300-400 MB (relative to the state after the first change, so 100 MB more compared to a "clean" instance)  
 Saved memory: 300-400 MB (relative to the state after the first change, so 100 MB more compared to a "clean" instance)  
 CPU impact: Some impact in model loading (but less allocations), zero while playing  
 CPU impact: Some impact in model loading (but less allocations), zero while playing