瀏覽代碼

General cleanup

malte0811 3 年之前
父節點
當前提交
28eb881a10

+ 20 - 10
common/src/main/java/malte0811/ferritecore/fastmap/PropertyIndexer.java

@@ -31,18 +31,28 @@ public abstract class PropertyIndexer<T extends Comparable<T>> {
         synchronized (KNOWN_INDEXERS) {
             PropertyIndexer<?> unchecked = KNOWN_INDEXERS.computeIfAbsent(prop, propInner -> {
                 PropertyIndexer<?> result = null;
-                if (propInner instanceof BooleanProperty) {
-                    result = new BoolIndexer((BooleanProperty) propInner);
-                } else if (propInner instanceof IntegerProperty) {
-                    result = new IntIndexer((IntegerProperty) propInner);
-                } else if (WeirdVanillaDirectionIndexer.isApplicable(propInner)) {
-                    result = new WeirdVanillaDirectionIndexer((Property<Direction>) propInner);
-                } else if (propInner instanceof EnumProperty<?>) {
-                    result = new EnumIndexer<>((EnumProperty<?>) propInner);
+                if(propInner instanceof BooleanProperty boolProp)
+                {
+                    result = new BoolIndexer(boolProp);
                 }
-                if (result == null || !result.isValid()) {
+                else if(propInner instanceof IntegerProperty intProp)
+                {
+                    result = new IntIndexer(intProp);
+                }
+                else if(WeirdVanillaDirectionIndexer.isApplicable(propInner))
+                {
+                    result = new WeirdVanillaDirectionIndexer((Property<Direction>)propInner);
+                }
+                else if(propInner instanceof EnumProperty<?> enumProp)
+                {
+                    result = new EnumIndexer<>(enumProp);
+                }
+                if(result==null||!result.isValid())
+                {
                     return new GenericIndexer<>(propInner);
-                } else {
+                }
+                else
+                {
                     return result;
                 }
             });

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

@@ -1,6 +1,5 @@
 package malte0811.ferritecore.fastmap.table;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Tables;
 import malte0811.ferritecore.ducks.FastMapStateHolder;
 import malte0811.ferritecore.fastmap.FastMap;
@@ -22,28 +21,30 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
 
     @Override
     public boolean contains(@Nullable Object rowKey, @Nullable Object columnKey) {
-        if (!(columnKey instanceof Comparable<?>) || !(rowKey instanceof Property<?>)) {
+        if(!(columnKey instanceof Comparable<?>)||!(rowKey instanceof Property<?> rowProperty))
+        {
             return false;
         }
-        Comparable<?> valueInState = owner.getStateMap().getValue(owner.getStateIndex(), (Property<?>) rowKey);
+        Comparable<?> valueInState = owner.getStateMap().getValue(owner.getStateIndex(), rowProperty);
         if (valueInState == null || valueInState.equals(columnKey)) {
             // Not contained in state, or the current value (which isn't added to the table)
             return false;
         } else {
-            // We contain the row, and we only ever contain non-null row keys
-            Preconditions.checkNotNull(rowKey);
             // Is value allowed for property?
-            return ((Property<?>) rowKey).getPossibleValues().contains(columnKey);
+            return rowProperty.getPossibleValues().contains(columnKey);
         }
     }
 
     @Override
     public boolean containsRow(@Nullable Object rowKey) {
-        if (!(rowKey instanceof Property<?>)) {
+        if(!(rowKey instanceof Property<?> rowProperty))
+        {
             return false;
-        } else {
+        }
+        else
+        {
             // Property is not in state
-            return owner.getStateMap().getValue(owner.getStateIndex(), (Property<?>) rowKey) != null;
+            return owner.getStateMap().getValue(owner.getStateIndex(), rowProperty)!=null;
         }
     }
 
@@ -90,10 +91,11 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
 
     @Override
     public S get(@Nullable Object rowKey, @Nullable Object columnKey) {
-        if (!(rowKey instanceof Property)) {
+        if(!(rowKey instanceof Property<?> rowProperty))
+        {
             return null;
         }
-        return owner.getStateMap().withUnsafe(owner.getStateIndex(), (Property<?>) rowKey, columnKey);
+        return owner.getStateMap().withUnsafe(owner.getStateIndex(), rowProperty, columnKey);
     }
 
     @Override

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

@@ -10,8 +10,8 @@ public class ArrayVoxelShapeHash implements Hash.Strategy<ArrayVSAccess> {
 
     @Override
     public int hashCode(ArrayVSAccess o) {
-        return 31 * Objects.hash(o.getXPoints(), o.getYPoints(), o.getZPoints())
-                + VoxelShapePartHash.INSTANCE.hashCode(o.getShape());
+        return 31*Objects.hash(o.getXPoints(), o.getYPoints(), o.getZPoints())
+                +DiscreteVSHash.INSTANCE.hashCode(o.getShape());
     }
 
     @Override
@@ -21,9 +21,9 @@ public class ArrayVoxelShapeHash implements Hash.Strategy<ArrayVSAccess> {
         } 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());
+        return Objects.equals(a.getXPoints(), b.getXPoints())&&
+                Objects.equals(a.getYPoints(), b.getYPoints())&&
+                Objects.equals(a.getZPoints(), b.getZPoints())&&
+                DiscreteVSHash.INSTANCE.equals(a.getShape(), b.getShape());
     }
 }

+ 10 - 7
common/src/main/java/malte0811/ferritecore/hash/VoxelShapePartHash.java → common/src/main/java/malte0811/ferritecore/hash/DiscreteVSHash.java

@@ -8,18 +8,21 @@ import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
 
 import java.util.Objects;
 
-public class VoxelShapePartHash implements Hash.Strategy<DiscreteVoxelShape> {
-    public static final VoxelShapePartHash INSTANCE = new VoxelShapePartHash();
+public class DiscreteVSHash implements Hash.Strategy<DiscreteVoxelShape>
+{
+    public static final DiscreteVSHash INSTANCE = new DiscreteVSHash();
 
     @Override
-    public int hashCode(DiscreteVoxelShape shape) {
-        return hashCode((DiscreteVSAccess) shape);
+    public int hashCode(DiscreteVoxelShape shape)
+    {
+        return hashCode((DiscreteVSAccess)shape);
     }
 
-    public int hashCode(DiscreteVSAccess o) {
+    public int hashCode(DiscreteVSAccess o)
+    {
         int result = o.getXSize();
-        result = 31 * result + o.getYSize();
-        result = 31 * result + o.getZSize();
+        result = 31*result+o.getYSize();
+        result = 31*result+o.getZSize();
         if (o instanceof SubShapeAccess access) {
             result = 31 * result + access.getStartX();
             result = 31 * result + access.getStartY();

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

@@ -11,8 +11,8 @@ public class SliceShapeHash implements Hash.Strategy<SliceShapeAccess> {
     @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());
+        result = 31*result+DiscreteVSHash.INSTANCE.hashCode(o.getShape());
+        result = 31*result+VoxelShapeHash.INSTANCE.hashCode(o.getDelegate());
         return result;
     }
 
@@ -23,8 +23,8 @@ public class SliceShapeHash implements Hash.Strategy<SliceShapeAccess> {
         } 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());
+        return Objects.equals(a.getAxis(), b.getAxis())&&
+                VoxelShapeHash.INSTANCE.equals(a.getDelegate(), b.getDelegate())&&
+                DiscreteVSHash.INSTANCE.equals(a.getShape(), b.getShape());
     }
 }

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

@@ -21,7 +21,7 @@ public class VoxelShapeHash implements Hash.Strategy<VoxelShape> {
         } else if (o instanceof ArrayVSAccess access) {
             return ArrayVoxelShapeHash.INSTANCE.hashCode(access);
         } else if (isCubeShape(o)) {
-            return VoxelShapePartHash.INSTANCE.hashCode(o.getShape());
+            return DiscreteVSHash.INSTANCE.hashCode(o.getShape());
         } else {
             return o.hashCode();
         }
@@ -44,7 +44,7 @@ public class VoxelShapeHash implements Hash.Strategy<VoxelShape> {
         } 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());
+            return DiscreteVSHash.INSTANCE.equals(a.getShape(), b.getShape());
         } else {
             return a.equals(b);
         }

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

@@ -112,8 +112,9 @@ public class BlockStateCacheImpl {
     }
 
     private static void replaceInternals(VoxelShape toKeep, VoxelShape toReplace) {
-        if (toKeep instanceof ArrayVoxelShape && toReplace instanceof ArrayVoxelShape) {
-            replaceInternals((ArrayVoxelShape) toKeep, (ArrayVoxelShape) toReplace);
+        if(toKeep instanceof ArrayVoxelShape keepArray&&toReplace instanceof ArrayVoxelShape replaceArray)
+        {
+            replaceInternals(keepArray, replaceArray);
         }
     }
 

+ 2 - 1
common/src/main/java/malte0811/ferritecore/impl/KeyValueConditionImpl.java

@@ -8,6 +8,7 @@ import net.minecraft.world.level.block.state.StateDefinition;
 import net.minecraft.world.level.block.state.properties.Property;
 import org.apache.commons.lang3.tuple.Pair;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -50,7 +51,7 @@ public class KeyValueConditionImpl {
                 } else {
                     List<Predicate<BlockState>> subPredicates = matchedStates.stream()
                             .map(subValue -> getBlockStatePredicate(stateContainer, property, subValue, key, value))
-                            .collect(Collectors.toList());
+                            .collect(Collectors.toCollection(ArrayList::new));
                     // This line is the only functional change, but targeting it with anything but Overwrite appears to
                     // be impossible
                     PredicateHelper.canonize(subPredicates);

+ 13 - 5
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/BlockStateBaseMixin.java

@@ -2,20 +2,28 @@ package malte0811.ferritecore.mixin.blockstatecache;
 
 import malte0811.ferritecore.impl.BlockStateCacheImpl;
 import net.minecraft.world.level.block.state.BlockBehaviour;
+import net.minecraft.world.level.block.state.BlockState;
 import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 
 @Mixin(BlockBehaviour.BlockStateBase.class)
-public class BlockStateBaseMixin {
+public abstract class BlockStateBaseMixin
+{
+    @Shadow
+    protected abstract BlockState asState();
+
     @Inject(method = "initCache", at = @At("HEAD"))
-    public void cacheStateHead(CallbackInfo ci) {
-        BlockStateCacheImpl.deduplicateCachePre((BlockBehaviour.BlockStateBase) (Object) this);
+    public void cacheStateHead(CallbackInfo ci)
+    {
+        BlockStateCacheImpl.deduplicateCachePre(asState());
     }
 
     @Inject(method = "initCache", at = @At("TAIL"))
-    public void cacheStateTail(CallbackInfo ci) {
-        BlockStateCacheImpl.deduplicateCachePost((BlockBehaviour.BlockStateBase) (Object) this);
+    public void cacheStateTail(CallbackInfo ci)
+    {
+        BlockStateCacheImpl.deduplicateCachePost(asState());
     }
 }

+ 8 - 7
common/src/main/java/malte0811/ferritecore/util/PredicateHelper.java

@@ -1,19 +1,20 @@
 package malte0811.ferritecore.util;
 
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.function.Predicate;
 import net.minecraft.client.renderer.block.model.multipart.Condition;
 import net.minecraft.world.level.block.Block;
 import net.minecraft.world.level.block.state.BlockState;
 import net.minecraft.world.level.block.state.StateDefinition;
 
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Predicate;
+
 public class PredicateHelper {
     public static List<Predicate<BlockState>> toCanonicalList(
             Iterable<? extends Condition> conditions, StateDefinition<Block, BlockState> stateContainer
     ) {
-        ArrayList<Predicate<BlockState>> list = new ArrayList<>();
+        List<Predicate<BlockState>> list = new ArrayList<>();
         for (Condition cond : conditions) {
             list.add(cond.getPredicate(stateContainer));
         }
@@ -27,8 +28,8 @@ public class PredicateHelper {
      */
     public static <T> void canonize(List<Predicate<T>> input) {
         input.sort(Comparator.comparingInt(Predicate::hashCode));
-        if (input instanceof ArrayList) {
-            ((ArrayList<Predicate<T>>) input).trimToSize();
+        if (input instanceof ArrayList<Predicate<T>> arrayList) {
+            arrayList.trimToSize();
         }
     }
 

+ 0 - 4
forge/build.gradle

@@ -52,7 +52,3 @@ remapJar {
     input.set(shadowJar.archiveFile)
     classifier "forge"
 }
-
-loom {
-    mixinConfigs += "ferritecore.forge.mixin.json"
-}

+ 0 - 16
forge/src/main/java/malte0811/ferritecore/ModMainForge.java

@@ -3,10 +3,7 @@ package malte0811.ferritecore;
 import cpw.mods.modlauncher.api.INameMappingService;
 import malte0811.ferritecore.util.Constants;
 import net.minecraftforge.fml.IExtensionPoint.DisplayTest;
-import net.minecraftforge.fml.ModLoader;
 import net.minecraftforge.fml.ModLoadingContext;
-import net.minecraftforge.fml.ModLoadingStage;
-import net.minecraftforge.fml.ModLoadingWarning;
 import net.minecraftforge.fml.common.Mod;
 import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
 import net.minecraftforge.fmllegacy.network.FMLNetworkConstants;
@@ -15,14 +12,6 @@ import net.minecraftforge.fmllegacy.network.FMLNetworkConstants;
 public class ModMainForge {
 
     public ModMainForge() {
-        if (!hasMixins()) {
-            ModLoader.get().addWarning(new ModLoadingWarning(
-                    ModLoadingContext.get().getActiveContainer().getModInfo(),
-                    ModLoadingStage.CONSTRUCT,
-                    "FerriteCore: Mixins are not available! Please install MixinBootstrap!"
-            ));
-            throw new RuntimeException("Mixins are not available! Please install MixinBootstrap!");
-        }
         Constants.blockstateCacheFieldName = ObfuscationReflectionHelper.remapName(
                 INameMappingService.Domain.FIELD, "f_60593_"
         );
@@ -30,9 +19,4 @@ public class ModMainForge {
                 DisplayTest.class, () -> new DisplayTest(() -> FMLNetworkConstants.IGNORESERVERONLY, (s, b) -> true)
         );
     }
-
-    private static boolean hasMixins() {
-        // Replaced by SelfMixin if Mixins are provided by Forge itself, MixinBootstrap or something else
-        return false;
-    }
 }

+ 0 - 17
forge/src/main/java/malte0811/ferritecore/mixin/forge/SelfMixin.java

@@ -1,17 +0,0 @@
-package malte0811.ferritecore.mixin.forge;
-
-import malte0811.ferritecore.ModMainForge;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Overwrite;
-
-@Mixin(ModMainForge.class)
-public class SelfMixin {
-    /**
-     * @reason Detect Mixins when loaded
-     * @author malte0811
-     */
-    @Overwrite(remap = false)
-    private static boolean hasMixins() {
-        return true;
-    }
-}

+ 1 - 1
forge/src/main/resources/META-INF/mods.toml

@@ -14,7 +14,7 @@ logoFile="logo.png"
 [[dependencies.ferritecore]]
     modId="forge"
     mandatory = true
-versionRange = "[37.0.44,)"
+versionRange = "[37.0.59,)"
 ordering = "NONE"
     side="BOTH"
 [[dependencies.ferritecore]]

+ 0 - 12
forge/src/main/resources/ferritecore.forge.mixin.json

@@ -1,12 +0,0 @@
-{
-  "required": true,
-  "package": "malte0811.ferritecore.mixin.forge",
-  "compatibilityLevel": "JAVA_16",
-  "client": [
-    "SelfMixin"
-  ],
-  "injectors": {
-    "defaultRequire": 1
-  },
-  "minVersion": "0.8"
-}

+ 1 - 1
gradle.properties

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