Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Jan 28, 2017
1 parent 03f4b64 commit eae4ad6
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 62 deletions.
5 changes: 0 additions & 5 deletions src/main/java/pl/asie/foamfix/ProxyCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.BiMap;
import net.minecraft.launchwrapper.LaunchClassLoader;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry;
import net.minecraftforge.fml.common.registry.PersistentRegistryManager;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import pl.asie.foamfix.shared.FoamFixConfig;
import pl.asie.foamfix.shared.FoamFixShared;
import pl.asie.foamfix.common.PretendPackageMap;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.BitSet;
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/pl/asie/foamfix/client/Deduplicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@
import java.lang.reflect.Modifier;
import java.util.*;

@SuppressWarnings("deprecation")
public class Deduplicator {
private static final Set<Class> BLACKLIST_CLASS = new TCustomHashSet<Class>(HashingStrategies.IDENTITY);
private static final Set<Class> TRIM_ARRAYS_CLASSES = new TCustomHashSet<Class>(HashingStrategies.IDENTITY);
private static final Set<Class> BLACKLIST_CLASS = new TCustomHashSet<>(HashingStrategies.IDENTITY);
private static final Set<Class> TRIM_ARRAYS_CLASSES = new TCustomHashSet<>(HashingStrategies.IDENTITY);
private static final Map<Class, Set<MethodHandle[]>> CLASS_FIELDS = new IdentityHashMap<>();
private static final Map<Class, MethodHandle> COLLECTION_CONSTRUCTORS = new IdentityHashMap<>();

Expand All @@ -78,12 +79,12 @@ public class Deduplicator {
public int successfuls = 0;
public int maxRecursion = 0;

private IDeduplicatingStorage<float[]> FLOATA_STORAGE = new DeduplicatingStorageTrove<float[]>(HashingStrategies.FLOAT_ARRAY);
private IDeduplicatingStorage<float[][]> FLOATAA_STORAGE = new DeduplicatingStorageTrove<float[][]>(HashingStrategies.FLOAT_ARRAY_ARRAY);
private IDeduplicatingStorage OBJECT_STORAGE = new DeduplicatingStorageTrove(HashingStrategies.GENERIC);
private IDeduplicatingStorage<ItemCameraTransforms> ICT_STORAGE = new DeduplicatingStorageTrove<>(HashingStrategies.ITEM_CAMERA_TRANSFORMS);
private IDeduplicatingStorage<ItemTransformVec3f> IT3_STORAGE = new DeduplicatingStorageTrove<>(HashingStrategies.ITEM_TRANSFORM_VEC3F);
private Set<Object> deduplicatedObjects = new TCustomHashSet<Object>(HashingStrategies.IDENTITY);
private final IDeduplicatingStorage<float[]> FLOATA_STORAGE = new DeduplicatingStorageTrove<>(HashingStrategies.FLOAT_ARRAY);
private final IDeduplicatingStorage<float[][]> FLOATAA_STORAGE = new DeduplicatingStorageTrove<>(HashingStrategies.FLOAT_ARRAY_ARRAY);
private final IDeduplicatingStorage OBJECT_STORAGE = new DeduplicatingStorageTrove(HashingStrategies.GENERIC);
private final IDeduplicatingStorage<ItemCameraTransforms> ICT_STORAGE = new DeduplicatingStorageTrove<>(HashingStrategies.ITEM_CAMERA_TRANSFORMS);
// private final IDeduplicatingStorage<ItemTransformVec3f> IT3_STORAGE = new DeduplicatingStorageTrove<>(HashingStrategies.ITEM_TRANSFORM_VEC3F);
private final Set<Object> deduplicatedObjects = new TCustomHashSet<>(HashingStrategies.IDENTITY);

public Deduplicator() {
}
Expand Down Expand Up @@ -295,13 +296,12 @@ public Object deduplicateObject(Object o, int recursion) {
}
}

MethodHandle constructor = COLLECTION_CONSTRUCTORS.get(o);
MethodHandle constructor = COLLECTION_CONSTRUCTORS.get(c);
if (constructor != null) {
try {
Collection nc = (Collection) constructor.invoke();
Iterator i = ((Collection) o).iterator();
while (i.hasNext()) {
nc.add(deduplicateObject(i.next(), recursion + 1));
for (Object o1 : ((Collection) o)) {
nc.add(deduplicateObject(o1, recursion + 1));
}
return nc;
} catch (Throwable t) {
Expand All @@ -310,9 +310,8 @@ public Object deduplicateObject(Object o, int recursion) {
}

// fallback
Iterator i = ((Collection) o).iterator();
while (i.hasNext()) {
deduplicateObject(i.next(), recursion + 1);
for (Object o1 : ((Collection) o)) {
deduplicateObject(o1, recursion + 1);
}
} else if (c.isArray()) {
for (int i = 0; i < Array.getLength(o); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.ProgressManager;
import pl.asie.foamfix.FoamFix;
import net.minecraft.client.renderer.block.model.IBakedModel;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pl/asie/foamfix/common/FoamyBlockState.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class FoamyBlockState extends BlockStateContainer.StateImplementation {
protected final PropertyValueMapper owner;
protected ImmutableMap < IProperty<?>, Comparable<? >> properties;
protected final ImmutableMap<IProperty<?>, Comparable<?>> properties;
protected int value;

public FoamyBlockState(PropertyValueMapper owner, Block blockIn, ImmutableMap < IProperty<?>, Comparable<? >> propertiesIn) {
Expand All @@ -21,7 +21,7 @@ public FoamyBlockState(PropertyValueMapper owner, Block blockIn, ImmutableMap <

@Override
public <T extends Comparable<T>, V extends T> IBlockState withProperty(IProperty<T> property, V value) {
Comparable<?> comparable = (Comparable)this.properties.get(property);
Comparable<?> comparable = this.properties.get(property);

if (comparable == null) {
throw new IllegalArgumentException("Cannot set property " + property + " as it does not exist in " + this.getBlock().getBlockState());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public <V> IExtendedBlockState withProperty(IUnlistedProperty<V> property, V val
{
throw new IllegalArgumentException("Cannot set unlisted property " + property + " to " + value + " on block " + Block.REGISTRY.getNameForObject(getBlock()) + ", it is not an allowed value");
}
Map<IUnlistedProperty<?>, Optional<?>> newMap = new HashMap<IUnlistedProperty<?>, Optional<?>>(unlistedProperties);
Map<IUnlistedProperty<?>, Optional<?>> newMap = new HashMap<>(unlistedProperties);
newMap.put(property, Optional.fromNullable(value));
if(Iterables.all(newMap.values(), Predicates.<Optional<?>>equalTo(Optional.absent())))
{ // no dynamic properties, lookup normal state
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/pl/asie/foamfix/common/PropertyValueMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class Entry {
private final int bitSize;
private final int bits;

public Entry(IProperty property) {
private Entry(IProperty property) {
this.property = property;
this.values = new TObjectIntHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1);
this.bitSize = MathHelper.roundUpToPowerOfTwo(property.getAllowedValues().size());
Expand Down Expand Up @@ -65,26 +65,19 @@ public int hashCode() {
}

private static final Map<IProperty, Entry> entryMap = new IdentityHashMap<>();
private static final Map<Object, PropertyValueMapper> mapperMap = new IdentityHashMap<>();
private static final Map<BlockStateContainer, PropertyValueMapper> mapperMap = new IdentityHashMap<>();

private final Entry[] entryList;
private final TObjectIntMap<IProperty> entryPositionMap;
private final IProperty[] propertyMap;
private final IBlockState[] stateMap;

public PropertyValueMapper(BlockStateContainer container) {
Collection<IProperty<?>> properties = container.getProperties();

this.propertyMap = new IProperty[properties.size()];
int i = 0;
for (IProperty<?> property : properties) {
propertyMap[i++] = property;
}

entryList = new Entry[properties.size()];
List<IProperty<?>> propertiesSortedFitness = new ArrayList<>(properties);
Collections.sort(propertiesSortedFitness, COMPARATOR_BIT_FITNESS);
i = 0;
int i = 0;
for (IProperty p : propertiesSortedFitness) {
entryList[i++] = getPropertyEntry(p);
}
Expand All @@ -105,10 +98,10 @@ public PropertyValueMapper(BlockStateContainer container) {
}
}

public static PropertyValueMapper getOrCreate(Object owner) {
public static PropertyValueMapper getOrCreate(BlockStateContainer owner) {
PropertyValueMapper e = mapperMap.get(owner);
if (e == null) {
e = new PropertyValueMapper((BlockStateContainer) owner);
e = new PropertyValueMapper(owner);
mapperMap.put(owner, e);
}
return e;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/pl/asie/foamfix/coremod/BlockPosPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
package pl.asie.foamfix.coremod;

import net.minecraftforge.fml.common.discovery.ASMDataTable;
import org.objectweb.asm.*;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/pl/asie/foamfix/coremod/FoamFixCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
package pl.asie.foamfix.coremod;

import java.io.File;
import java.util.ArrayList;
import java.util.Map;
import net.minecraftforge.fml.common.ModMetadata;

import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import net.minecraftforge.fml.common.DummyModContainer;
import pl.asie.foamfix.shared.FoamFixShared;

@IFMLLoadingPlugin.Name("Do not report to Forge! Remove FoamFixAPI (or replace with FoamFixAPI-Lawful) and try again.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.ModMetadata;

import java.util.ArrayList;
import java.util.List;

public class FoamFixCoreContainer extends DummyModContainer {
Expand All @@ -31,7 +30,7 @@ public List<String> getOwnedPackages() {
md.modId = "foamfixcore";
md.name = "FoamFixCore";
md.description = "I'm actually just an optional part of FoamFix, available exclusively as part of the Anarchy version!";
(md.authorList = new ArrayList()).add("asie");
md.authorList = ImmutableList.of("asie");
md.version = "7.7.4";
}
}
2 changes: 0 additions & 2 deletions src/main/java/pl/asie/foamfix/shared/FoamFixConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
*/
package pl.asie.foamfix.shared;

import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
import net.minecraftforge.fml.common.versioning.VersionParser;
import net.minecraftforge.fml.common.versioning.VersionRange;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pl/asie/foamfix/shared/FoamFixShared.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package pl.asie.foamfix.shared;

public class FoamFixShared {
public static FoamFixConfig config = new FoamFixConfig();
public static final FoamFixConfig config = new FoamFixConfig();
public static boolean enabled = false;
public static int ramSaved = 0;
}
2 changes: 0 additions & 2 deletions src/main/java/pl/asie/foamfix/util/FoamUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
import com.google.common.collect.Sets;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ItemLayerModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import pl.asie.foamfix.FoamFix;

import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map;

public final class FoamUtils {
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/pl/asie/foamfix/util/HashingStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import gnu.trove.strategy.IdentityHashingStrategy;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
import net.minecraftforge.common.model.TRSRTransformation;

import javax.vecmath.Vector3f;
import java.util.Arrays;
import java.util.Objects;

Expand Down Expand Up @@ -62,16 +60,18 @@ public int computeHashCode(ItemCameraTransforms object) {

@Override
public boolean equals(ItemCameraTransforms o1, ItemCameraTransforms o2) {
if (o1 == null) return o1 == o2;

return Objects.equals(o1.firstperson_left, o2.firstperson_left)
&& Objects.equals(o1.firstperson_right, o2.firstperson_right)
&& Objects.equals(o1.fixed, o2.fixed)
&& Objects.equals(o1.ground, o2.ground)
&& Objects.equals(o1.gui, o2.gui)
&& Objects.equals(o1.head, o2.head)
&& Objects.equals(o1.thirdperson_left, o2.thirdperson_left)
&& Objects.equals(o1.thirdperson_right, o2.thirdperson_right);
if (o1 == null) {
return o2 == null;
} else {
return Objects.equals(o1.firstperson_left, o2.firstperson_left)
&& Objects.equals(o1.firstperson_right, o2.firstperson_right)
&& Objects.equals(o1.fixed, o2.fixed)
&& Objects.equals(o1.ground, o2.ground)
&& Objects.equals(o1.gui, o2.gui)
&& Objects.equals(o1.head, o2.head)
&& Objects.equals(o1.thirdperson_left, o2.thirdperson_left)
&& Objects.equals(o1.thirdperson_right, o2.thirdperson_right);
}
}
}

Expand Down Expand Up @@ -143,16 +143,16 @@ private static final class FloatArrayArray implements HashingStrategy<float[][]>
@Override
public int computeHashCode(float[][] object) {
int hash = 1;
for (int i = 0; i < object.length; i++) {
hash = hash * 31 + Arrays.hashCode(object[i]);
for (float[] anObject : object) {
hash = hash * 31 + Arrays.hashCode(anObject);
}
return hash;
}

@Override
public boolean equals(float[][] o1, float[][] o2) {
if (o1 == null) {
return o1 == o2;
return o2 == null;
} else {
if (o1.length != o2.length)
return false;
Expand Down

0 comments on commit eae4ad6

Please sign in to comment.