Forcing EmcValues to have (at most) 4 points of precision
This commit is contained in:
parent
2ca30f4845
commit
a6486df7fa
4 changed files with 25 additions and 11 deletions
|
@ -5,6 +5,7 @@ import com.pahimar.ee3.helper.LogHelper;
|
|||
import com.pahimar.ee3.lib.Compare;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -21,7 +22,7 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
|
|||
{
|
||||
// Gson serializer for serializing to/deserializing from json
|
||||
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;
|
||||
|
||||
|
@ -59,11 +60,12 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
|
|||
{
|
||||
if (components.length == EmcType.TYPES.length)
|
||||
{
|
||||
this.components = new float[EmcType.TYPES.length];
|
||||
for (int i = 0; i < components.length; i++)
|
||||
// this.components = components;
|
||||
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;
|
||||
this.components[i] = components[i];
|
||||
BigDecimal bigComponent = BigDecimal.valueOf(components[i]).setScale(PRECISION, BigDecimal.ROUND_HALF_DOWN);
|
||||
this.components[i] = bigComponent.floatValue();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -108,10 +110,11 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
|
|||
this.components[EmcType.DEFAULT.ordinal()] = value;
|
||||
}
|
||||
|
||||
// for (int i = 0; i < this.components.length; i++)
|
||||
// {
|
||||
// this.components[i] = (float) Math.round(this.components[i]) * PRECISION / PRECISION;
|
||||
// }
|
||||
for (int i = 0; i < this.components.length; i++)
|
||||
{
|
||||
BigDecimal bigComponent = BigDecimal.valueOf(this.components[i]).setScale(PRECISION, BigDecimal.ROUND_HALF_DOWN);
|
||||
this.components[i] = bigComponent.floatValue();
|
||||
}
|
||||
}
|
||||
|
||||
public float getValue()
|
||||
|
|
|
@ -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))));
|
||||
|
||||
// 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.getFluid("milk")), new EmcValue(64, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 3), new EmcComponent(EmcType.AMORPHOUS, 1))));
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.pahimar.ee3.helper;
|
|||
import com.pahimar.ee3.api.OreStack;
|
||||
import com.pahimar.ee3.api.WrappedStack;
|
||||
import com.pahimar.ee3.emc.EmcRegistry;
|
||||
import com.pahimar.ee3.emc.EmcValue;
|
||||
import com.pahimar.ee3.item.crafting.RecipeRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -94,9 +95,19 @@ public class DebugHelper
|
|||
|
||||
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())
|
||||
{
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 EmcValue[] DEFAULT_EMC_VALUES = {
|
||||
new EmcValue(0.1f),
|
||||
new EmcValue(1),
|
||||
new EmcValue(256),
|
||||
new EmcValue(2048),
|
||||
new EmcValue(8192),
|
||||
|
|
Loading…
Reference in a new issue