Browse Source

Fixes for merge from 1.16

malte0811 4 năm trước cách đây
mục cha
commit
5ed7650605

+ 1 - 1
common/src/main/java/malte0811/ferritecore/fastmap/table/CrashNeighborTable.java

@@ -1,6 +1,6 @@
 package malte0811.ferritecore.fastmap.table;
 
-import net.minecraft.state.Property;
+import net.minecraft.world.level.block.state.properties.Property;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 

+ 9 - 9
common/src/main/java/malte0811/ferritecore/fastmap/table/FastmapNeighborTable.java

@@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Tables;
 import malte0811.ferritecore.ducks.FastMapStateHolder;
 import malte0811.ferritecore.fastmap.FastMap;
-import net.minecraft.state.Property;
+import net.minecraft.world.level.block.state.properties.Property;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -33,7 +33,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
             // We contain the row, and we only ever contain non-null row keys
             Preconditions.checkNotNull(rowKey);
             // Is value allowed for property?
-            return ((Property<?>) rowKey).getAllowedValues().contains(columnKey);
+            return ((Property<?>) rowKey).getPossibleValues().contains(columnKey);
         }
     }
 
@@ -52,7 +52,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
         FastMap<S> map = owner.getStateMap();
         for (int i = 0; i < map.numProperties(); ++i) {
             Map.Entry<Property<?>, Comparable<?>> entry = map.getEntry(i, owner.getStateIndex());
-            if (!entry.getValue().equals(columnKey) && entry.getKey().getAllowedValues().contains(columnKey)) {
+            if (!entry.getValue().equals(columnKey) && entry.getKey().getPossibleValues().contains(columnKey)) {
                 return true;
             }
         }
@@ -76,7 +76,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
     private <T extends Comparable<T>> boolean isNeighbor(Property<T> prop, Object potentialNeighbor) {
         final FastMap<S> map = owner.getStateMap();
         final T valueInState = map.getValue(owner.getStateIndex(), prop);
-        for (final T neighborValue : prop.getAllowedValues()) {
+        for (final T neighborValue : prop.getPossibleValues()) {
             if (neighborValue.equals(valueInState)) {
                 continue;
             }
@@ -114,7 +114,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
     public Map<Comparable<?>, S> row(@NotNull Property<?> rowKey) {
         final Map<Comparable<?>, S> rowMap = new HashMap<>();
         final Comparable<?> contained = owner.getStateMap().getValue(owner.getStateIndex(), rowKey);
-        for (Comparable<?> val : rowKey.getAllowedValues()) {
+        for (Comparable<?> val : rowKey.getPossibleValues()) {
             if (!val.equals(contained)) {
                 rowMap.put(val, owner.getStateMap().withUnsafe(owner.getStateIndex(), rowKey, val));
             }
@@ -130,7 +130,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
         for (int i = 0; i < map.numProperties(); ++i) {
             final Property<?> rowKey = map.getKey(i).getProperty();
             final Comparable<?> contained = map.getValue(index, rowKey);
-            for (Comparable<?> val : rowKey.getAllowedValues()) {
+            for (Comparable<?> val : rowKey.getPossibleValues()) {
                 if (!val.equals(contained) && val.equals(columnKey)) {
                     rowMap.put(rowKey, map.withUnsafe(index, rowKey, val));
                 }
@@ -147,7 +147,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
         for (int i = 0; i < map.numProperties(); ++i) {
             final Property<?> rowKey = map.getKey(i).getProperty();
             final Comparable<?> contained = map.getValue(index, rowKey);
-            for (Comparable<?> val : rowKey.getAllowedValues()) {
+            for (Comparable<?> val : rowKey.getPossibleValues()) {
                 if (!val.equals(contained)) {
                     rowMap.add(Tables.immutableCell(rowKey, val, map.withUnsafe(index, rowKey, val)));
                 }
@@ -168,7 +168,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
         for (int i = 0; i < map.numProperties(); ++i) {
             final Property<?> rowKey = map.getKey(i).getProperty();
             final Comparable<?> contained = map.getValue(owner.getStateIndex(), rowKey);
-            for (Comparable<?> val : rowKey.getAllowedValues()) {
+            for (Comparable<?> val : rowKey.getPossibleValues()) {
                 if (!val.equals(contained)) {
                     rowMap.add(val);
                 }
@@ -185,7 +185,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
         for (int i = 0; i < map.numProperties(); ++i) {
             final Property<?> rowKey = map.getKey(i).getProperty();
             final Comparable<?> contained = map.getValue(index, rowKey);
-            for (Comparable<?> val : rowKey.getAllowedValues()) {
+            for (Comparable<?> val : rowKey.getPossibleValues()) {
                 if (!val.equals(contained)) {
                     rowMap.add(map.withUnsafe(index, rowKey, val));
                 }

+ 1 - 1
common/src/main/java/malte0811/ferritecore/fastmap/table/NeighborTableBase.java

@@ -1,7 +1,7 @@
 package malte0811.ferritecore.fastmap.table;
 
 import com.google.common.collect.Table;
-import net.minecraft.state.Property;
+import net.minecraft.world.level.block.state.properties.Property;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 

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

@@ -1,5 +1,6 @@
 package malte0811.ferritecore.impl;
 
+import com.google.common.base.Suppliers;
 import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
 import malte0811.ferritecore.hash.VoxelShapeArrayHash;
 import malte0811.ferritecore.hash.VoxelShapeHash;
@@ -8,7 +9,6 @@ import malte0811.ferritecore.mixin.blockstatecache.VSArrayAccess;
 import malte0811.ferritecore.mixin.blockstatecache.VSSplitAccess;
 import malte0811.ferritecore.mixin.blockstatecache.VoxelShapeAccess;
 import malte0811.ferritecore.util.Constants;
-import net.minecraft.util.LazyLoadedValue;
 import net.minecraft.world.level.block.state.BlockBehaviour.BlockStateBase;
 import net.minecraft.world.phys.shapes.ArrayVoxelShape;
 import net.minecraft.world.phys.shapes.SliceShape;
@@ -21,6 +21,7 @@ import java.lang.invoke.MethodHandles;
 import java.lang.reflect.Field;
 import java.util.Map;
 import java.util.function.Function;
+import java.util.function.Supplier;
 
 public class BlockStateCacheImpl {
     public static final Map<ArrayVoxelShape, ArrayVoxelShape> CACHE_COLLIDE = new Object2ObjectOpenCustomHashMap<>(
@@ -32,18 +33,17 @@ public class BlockStateCacheImpl {
 
     // Get the cache from a blockstate. Mixin does not handle private inner classes too well, so method handles and
     // manual remapping it is
-    private static final LazyLoadedValue<Function<BlockStateBase, BlockStateCacheAccess>> GET_CACHE =
-            new LazyLoadedValue<>(() -> {
+    private static final Supplier<Function<BlockStateBase, BlockStateCacheAccess>> GET_CACHE = Suppliers.memoize(() -> {
+        try {
+            Field cacheField = BlockStateBase.class.getDeclaredField(Constants.blockstateCacheFieldName);
+            cacheField.setAccessible(true);
+            MethodHandle getter = MethodHandles.lookup().unreflectGetter(cacheField);
+            return state -> {
                 try {
-                    Field cacheField = BlockStateBase.class.getDeclaredField(Constants.blockstateCacheFieldName);
-                    cacheField.setAccessible(true);
-                    MethodHandle getter = MethodHandles.lookup().unreflectGetter(cacheField);
-                    return state -> {
-                        try {
-                            return (BlockStateCacheAccess) getter.invoke(state);
-                        } catch (Throwable throwable) {
-                            throw new RuntimeException(throwable);
-                        }
+                    return (BlockStateCacheAccess) getter.invoke(state);
+                } catch (Throwable throwable) {
+                    throw new RuntimeException(throwable);
+                }
                     };
                 } catch (NoSuchFieldException | IllegalAccessException e) {
                     throw new RuntimeException(e);

+ 2 - 1
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/BlockStateCacheAccess.java

@@ -7,7 +7,8 @@ import org.spongepowered.asm.mixin.gen.Accessor;
 
 import javax.annotation.Nullable;
 
-@Mixin(targets = "net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase$Cache")
+// TODO this does not work in Dev, but BB$BSB$C causes build issues
+@Mixin(targets = "net.minecraft.world.level.block.state.BlockBehaviour.BlockStateBase.Cache")
 public interface BlockStateCacheAccess {
     @Accessor
     VoxelShape getCollisionShape();

+ 3 - 3
common/src/main/java/malte0811/ferritecore/mixin/fastmap/FastMapStateHolderMixin.java

@@ -20,7 +20,7 @@ public abstract class FastMapStateHolderMixin<O, S> implements FastMapStateHolde
     @Final
     private ImmutableMap<Property<?>, Comparable<?>> values;
     @Shadow
-    private Table<Property<?>, Comparable<?>, S> propertyToStateTable;
+    private Table<Property<?>, Comparable<?>, S> neighbours;
 
     private int globalTableIndex;
     private FastMap<S> globalTable;
@@ -79,11 +79,11 @@ public abstract class FastMapStateHolderMixin<O, S> implements FastMapStateHolde
 
     @Override
     public void setNeighborTable(Table<Property<?>, Comparable<?>, S> table) {
-        propertyToStateTable = table;
+        neighbours = table;
     }
 
     @Override
     public Table<Property<?>, Comparable<?>, S> getNeighborTable() {
-        return propertyToStateTable;
+        return neighbours;
     }
 }

+ 1 - 1
fabric/src/main/java/malte0811/ferritecore/mixin/fabric/MinecraftMixin.java

@@ -14,7 +14,7 @@ public class MinecraftMixin {
             method = "<init>",
             at = @At(
                     value = "INVOKE",
-                    target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;<init>(Lnet/minecraft/client/renderer/texture/TextureManager;Lnet/minecraft/client/resources/model/ModelManager;Lnet/minecraft/client/color/item/ItemColors;)V"
+                    target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;<init>(Lnet/minecraft/client/renderer/texture/TextureManager;Lnet/minecraft/client/resources/model/ModelManager;Lnet/minecraft/client/color/item/ItemColors;Lnet/minecraft/client/renderer/BlockEntityWithoutLevelRenderer;)V"
             )
     )
     private void injectAfterModels(GameConfig gameConfig, CallbackInfo ci) {