Forcing EmcValues to have (at most) 4 points of precision

This commit is contained in:
pahimar 2013-12-21 18:47:55 -05:00
parent 2ca30f4845
commit a6486df7fa
4 changed files with 25 additions and 11 deletions

View file

@ -5,6 +5,7 @@ import com.pahimar.ee3.helper.LogHelper;
import com.pahimar.ee3.lib.Compare; import com.pahimar.ee3.lib.Compare;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -21,7 +22,7 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
{ {
// Gson serializer for serializing to/deserializing from json // Gson serializer for serializing to/deserializing from json
private static final Gson gsonSerializer = (new GsonBuilder()).registerTypeAdapter(EmcValue.class, new EmcValue()).create(); private static final Gson gsonSerializer = (new GsonBuilder()).registerTypeAdapter(EmcValue.class, new EmcValue()).create();
private static final int PRECISION = 100; private static final int PRECISION = 4;
public final float[] components; public final float[] components;
@ -59,11 +60,12 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
{ {
if (components.length == EmcType.TYPES.length) if (components.length == EmcType.TYPES.length)
{ {
this.components = new float[EmcType.TYPES.length]; // this.components = components;
for (int i = 0; i < components.length; i++) this.components = new float[components.length];
for (int i = 0; i < this.components.length; i++)
{ {
//this.components[i] = (float) Math.round(components[i]) * PRECISION / PRECISION; BigDecimal bigComponent = BigDecimal.valueOf(components[i]).setScale(PRECISION, BigDecimal.ROUND_HALF_DOWN);
this.components[i] = components[i]; this.components[i] = bigComponent.floatValue();
} }
} }
else else
@ -108,10 +110,11 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
this.components[EmcType.DEFAULT.ordinal()] = value; this.components[EmcType.DEFAULT.ordinal()] = value;
} }
// for (int i = 0; i < this.components.length; i++) for (int i = 0; i < this.components.length; i++)
// { {
// this.components[i] = (float) Math.round(this.components[i]) * PRECISION / PRECISION; BigDecimal bigComponent = BigDecimal.valueOf(this.components[i]).setScale(PRECISION, BigDecimal.ROUND_HALF_DOWN);
// } this.components[i] = bigComponent.floatValue();
}
} }
public float getValue() public float getValue()

View file

@ -60,7 +60,7 @@ public class EmcValuesDefault
valueMap.put(new WrappedStack(new OreStack(new ItemStack(Block.sapling))), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.ESSENTIA, 1)))); valueMap.put(new WrappedStack(new OreStack(new ItemStack(Block.sapling))), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.ESSENTIA, 1))));
// Fluids // Fluids
valueMap.put(new WrappedStack(FluidRegistry.WATER), new EmcValue(0.1f, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 1), new EmcComponent(EmcType.AMORPHOUS, 1)))); valueMap.put(new WrappedStack(FluidRegistry.WATER), new EmcValue(1f, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 1), new EmcComponent(EmcType.AMORPHOUS, 1))));
valueMap.put(new WrappedStack(FluidRegistry.LAVA), new EmcValue(64, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.AMORPHOUS, 1)))); valueMap.put(new WrappedStack(FluidRegistry.LAVA), new EmcValue(64, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.AMORPHOUS, 1))));
valueMap.put(new WrappedStack(FluidRegistry.getFluid("milk")), new EmcValue(64, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 3), new EmcComponent(EmcType.AMORPHOUS, 1)))); valueMap.put(new WrappedStack(FluidRegistry.getFluid("milk")), new EmcValue(64, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 3), new EmcComponent(EmcType.AMORPHOUS, 1))));

View file

@ -3,6 +3,7 @@ package com.pahimar.ee3.helper;
import com.pahimar.ee3.api.OreStack; import com.pahimar.ee3.api.OreStack;
import com.pahimar.ee3.api.WrappedStack; import com.pahimar.ee3.api.WrappedStack;
import com.pahimar.ee3.emc.EmcRegistry; import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.emc.EmcValue;
import com.pahimar.ee3.item.crafting.RecipeRegistry; import com.pahimar.ee3.item.crafting.RecipeRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -94,9 +95,19 @@ public class DebugHelper
public static void printStackToEmcValueMappings() public static void printStackToEmcValueMappings()
{ {
LogHelper.debug(String.format("There are %s entries in the Stack to EmcValue map", EmcRegistry.getInstance().getStackToEmcValueMap().keySet().size()));
for (WrappedStack wrappedStack : EmcRegistry.getInstance().getStackToEmcValueMap().keySet()) for (WrappedStack wrappedStack : EmcRegistry.getInstance().getStackToEmcValueMap().keySet())
{ {
LogHelper.debug(String.format("EmcValue for stack '%s': %s", wrappedStack, EmcRegistry.getInstance().getStackToEmcValueMap().get(wrappedStack))); LogHelper.debug(String.format("EmcValue for stack '%s': %s", wrappedStack, EmcRegistry.getInstance().getStackToEmcValueMap().get(wrappedStack)));
} }
} }
public static void printEmcValueToStackMappings()
{
LogHelper.debug(String.format("There are %s entries in the EmcValue to Stack map", EmcRegistry.getInstance().getEmcValueToStackMap().keySet().size()));
for (EmcValue emcValue : EmcRegistry.getInstance().getEmcValueToStackMap().keySet())
{
LogHelper.debug(String.format("Stacks(s) for EmcValue '%s': %s", emcValue, EmcRegistry.getInstance().getEmcValueToStackMap().get(emcValue)));
}
}
} }

View file

@ -26,7 +26,7 @@ public class ItemAlchemicalDust extends ItemEE
{ {
public static final String[] ALCHEMICAL_DUST_NAMES = {"Ash", "Minium", "Verdant", "Azure", "Amaranthine", "Iridescent"}; public static final String[] ALCHEMICAL_DUST_NAMES = {"Ash", "Minium", "Verdant", "Azure", "Amaranthine", "Iridescent"};
public static final EmcValue[] DEFAULT_EMC_VALUES = { public static final EmcValue[] DEFAULT_EMC_VALUES = {
new EmcValue(0.1f), new EmcValue(1),
new EmcValue(256), new EmcValue(256),
new EmcValue(2048), new EmcValue(2048),
new EmcValue(8192), new EmcValue(8192),