浏览代码

Autoformat

malte0811 3 年之前
父节点
当前提交
9f4da12379

+ 0 - 2
build.gradle

@@ -1,5 +1,3 @@
-import java.util.stream.Collectors
-
 plugins {
     id "architectury-plugin" version "3.4-SNAPSHOT"
     id "dev.architectury.loom" version "0.10.0-SNAPSHOT" apply false

+ 7 - 17
common/src/main/java/malte0811/ferritecore/fastmap/PropertyIndexer.java

@@ -31,28 +31,18 @@ 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 boolProp)
-                {
+                if (propInner instanceof BooleanProperty boolProp) {
                     result = new BoolIndexer(boolProp);
-                }
-                else if(propInner instanceof IntegerProperty intProp)
-                {
+                } 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)
-                {
+                } 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())
-                {
+                if (result == null || !result.isValid()) {
                     return new GenericIndexer<>(propInner);
-                }
-                else
-                {
+                } else {
                     return result;
                 }
             });

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

@@ -21,8 +21,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
 
     @Override
     public boolean contains(@Nullable Object rowKey, @Nullable Object columnKey) {
-        if(!(columnKey instanceof Comparable<?>)||!(rowKey instanceof Property<?> rowProperty))
-        {
+        if (!(columnKey instanceof Comparable<?>) || !(rowKey instanceof Property<?> rowProperty)) {
             return false;
         }
         Comparable<?> valueInState = owner.getStateMap().getValue(owner.getStateIndex(), rowProperty);
@@ -37,14 +36,11 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
 
     @Override
     public boolean containsRow(@Nullable Object rowKey) {
-        if(!(rowKey instanceof Property<?> rowProperty))
-        {
+        if (!(rowKey instanceof Property<?> rowProperty)) {
             return false;
-        }
-        else
-        {
+        } else {
             // Property is not in state
-            return owner.getStateMap().getValue(owner.getStateIndex(), rowProperty)!=null;
+            return owner.getStateMap().getValue(owner.getStateIndex(), rowProperty) != null;
         }
     }
 
@@ -91,8 +87,7 @@ public class FastmapNeighborTable<S> extends NeighborTableBase<S> {
 
     @Override
     public S get(@Nullable Object rowKey, @Nullable Object columnKey) {
-        if(!(rowKey instanceof Property<?> rowProperty))
-        {
+        if (!(rowKey instanceof Property<?> rowProperty)) {
             return null;
         }
         return owner.getStateMap().withUnsafe(owner.getStateIndex(), rowProperty, columnKey);

+ 5 - 5
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())
-                +DiscreteVSHash.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())&&
+        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());
     }
 }

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

@@ -8,21 +8,18 @@ import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
 
 import java.util.Objects;
 
-public class DiscreteVSHash implements Hash.Strategy<DiscreteVoxelShape>
-{
+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();

+ 4 - 4
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+DiscreteVSHash.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())&&
+        return Objects.equals(a.getAxis(), b.getAxis()) &&
+                VoxelShapeHash.INSTANCE.equals(a.getDelegate(), b.getDelegate()) &&
                 DiscreteVSHash.INSTANCE.equals(a.getShape(), b.getShape());
     }
 }

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

@@ -42,11 +42,11 @@ public class BlockStateCacheImpl {
                 } catch (Throwable throwable) {
                     throw new RuntimeException(throwable);
                 }
-                    };
-                } catch (NoSuchFieldException | IllegalAccessException e) {
-                    throw new RuntimeException(e);
-                }
-            });
+            };
+        } catch (NoSuchFieldException | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    });
     // Is set to the previous cache used by a state before updating the cache. If the new cache has shapes equivalent to
     // the ones in the old cache, we don't need to go through the map since the old one already had deduplicated shapes
     private static final ThreadLocal<BlockStateCacheAccess> LAST_CACHE = new ThreadLocal<>();
@@ -112,8 +112,7 @@ public class BlockStateCacheImpl {
     }
 
     private static void replaceInternals(VoxelShape toKeep, VoxelShape toReplace) {
-        if(toKeep instanceof ArrayVoxelShape keepArray&&toReplace instanceof ArrayVoxelShape replaceArray)
-        {
+        if (toKeep instanceof ArrayVoxelShape keepArray && toReplace instanceof ArrayVoxelShape replaceArray) {
             replaceInternals(keepArray, replaceArray);
         }
     }

+ 1 - 0
common/src/main/java/malte0811/ferritecore/impl/StateHolderImpl.java

@@ -7,6 +7,7 @@ import malte0811.ferritecore.fastmap.table.CrashNeighborTable;
 import malte0811.ferritecore.fastmap.table.FastmapNeighborTable;
 import malte0811.ferritecore.mixin.config.FerriteConfig;
 import net.minecraft.world.level.block.state.properties.Property;
+
 import java.util.Map;
 
 public class StateHolderImpl {

+ 3 - 6
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/BlockStateBaseMixin.java

@@ -10,20 +10,17 @@ import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
 
 @Mixin(BlockBehaviour.BlockStateBase.class)
-public abstract class BlockStateBaseMixin
-{
+public abstract class BlockStateBaseMixin {
     @Shadow
     protected abstract BlockState asState();
 
     @Inject(method = "initCache", at = @At("HEAD"))
-    public void cacheStateHead(CallbackInfo ci)
-    {
+    public void cacheStateHead(CallbackInfo ci) {
         BlockStateCacheImpl.deduplicateCachePre(asState());
     }
 
     @Inject(method = "initCache", at = @At("TAIL"))
-    public void cacheStateTail(CallbackInfo ci)
-    {
+    public void cacheStateTail(CallbackInfo ci) {
         BlockStateCacheImpl.deduplicateCachePost(asState());
     }
 }

+ 2 - 2
common/src/main/java/malte0811/ferritecore/mixin/config/FerriteMixinConfig.java

@@ -59,13 +59,13 @@ public abstract class FerriteMixinConfig implements IMixinConfigPlugin {
     }
 
     @Override
-    public String getRefMapperConfig() { return null; }
+    public String getRefMapperConfig() {return null;}
 
     @Override
     public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}
 
     @Override
-    public List<String> getMixins() { return null; }
+    public List<String> getMixins() {return null;}
 
     @Override
     public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

+ 3 - 3
fabric/src/main/resources/fabric.mod.json

@@ -9,9 +9,9 @@
     "malte0811"
   ],
   "contact": {
-      "issues": "https://github.com/malte0811/FerriteCore/issues",
-      "source": "https://github.com/malte0811/FerriteCore",
-      "homepage": "https://www.curseforge.com/minecraft/mc-mods/ferritecore-fabric"
+    "issues": "https://github.com/malte0811/FerriteCore/issues",
+    "source": "https://github.com/malte0811/FerriteCore",
+    "homepage": "https://www.curseforge.com/minecraft/mc-mods/ferritecore-fabric"
   },
   "license": "MIT",
   "environment": "*",

+ 1 - 1
forge/build.gradle

@@ -24,7 +24,7 @@ loom {
                 "dedupbakedquad",
                 "chunknbt",
         ].stream()
-                .<String>map({s -> "ferritecore."+s+".mixin.json"})
+                .<String> map({ s -> "ferritecore." + s + ".mixin.json" })
                 .collect(Collectors.toList())
         mixinConfigs.addAll(fcMixinConfigs)
     }

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

@@ -1,25 +1,25 @@
-modLoader="javafml"
-loaderVersion="[28,)"
+modLoader = "javafml"
+loaderVersion = "[28,)"
 
-license="MIT"
+license = "MIT"
 [[mods]]
 modId = "ferritecore"
 version = "${version}"
 displayName = "Ferrite Core"
-authors="malte0811"
-description='''
+authors = "malte0811"
+description = '''
 Reduces memory usage.
 '''
-logoFile="logo.png"
+logoFile = "logo.png"
 [[dependencies.ferritecore]]
-    modId="forge"
-    mandatory = true
+modId = "forge"
+mandatory = true
 versionRange = "[37.0.59,)"
 ordering = "NONE"
-    side="BOTH"
+side = "BOTH"
 [[dependencies.ferritecore]]
-    modId="minecraft"
+modId = "minecraft"
 mandatory = true
 versionRange = "[1.17.1,)"
 ordering = "NONE"
-    side="BOTH"
+side = "BOTH"

+ 4 - 4
forge/src/main/resources/pack.mcmeta

@@ -1,6 +1,6 @@
 {
-    "pack": {
-        "description": "ferritecore resources",
-        "pack_format": 4
-    }
+  "pack": {
+    "description": "ferritecore resources",
+    "pack_format": 4
+  }
 }

+ 0 - 4
gradle.properties

@@ -1,12 +1,8 @@
 org.gradle.jvmargs=-Xmx2048M
 org.gradle.daemon=false
-
 minecraft_version=1.17.1
-
 archives_base_name=ferritecore
 mod_version=3.0.3
 maven_group=malte0811.ferritecore
-
 fabric_loader_version=0.11.3
-
 forge_version=37.0.59

+ 7 - 3
summary.md

@@ -19,18 +19,20 @@ if(!opt.isPresent()){
 }
 ```
 
-The created lambda is kept around for a long time, and there are a few million of them. In
-total the shallow size (i.e. the equivalent to `sizeof` in C/C++) of the captured
+The created lambda is kept around for a long time, and there are a few million of them. In total the shallow size (i.e.
+the equivalent to `sizeof` in C/C++) of the captured
 `Optional`s is about 100 MB. By replacing the `else`-branch with
+
 ```java
 T unwrapped = opt.get();
 return () -> doThing(unwrapped);
 ```
+
 the `Optional`s can be GCd right away.
 
 Saved memory: 100 MB  
 CPU impact: zero or negative (one less pointer to follow)  
-Side: client  
+Side: client
 
 ### 2. BlockState neighbors
 
@@ -50,6 +52,7 @@ Side: both
 Mixin subpackage: `fastmap`
 
 ### 3. BlockState property storage
+
 Each blockstate stores its properties as an `ImmutableMap<Property<?>, Comparable<?>>`, which takes around 170 MB in
 total. Replacing this `ImmutableMap` by a custom implementation based on the `FastMap` from the previous point (loaded
 with some classloader trickery) removes most of that memory usage.
@@ -97,6 +100,7 @@ Note: The CPU impact of the current Mixin implementation is positive for both pa
 first part would require changing what constructor the constructor in question redirects to.
 
 ### 6. Multipart model instances
+
 By default every blockstate using a multipart model gets its own instance of that multipart model. Since multipart
 models are generally used for blocks with a lot of states this means a lot of instances, and a lot of wasted memory. The
 only input data for a multipart model is a `List<Pair<Predicate<BlockState>, IBakedModel>>`. The predicate is already