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 434650a7d8
8 changed files with 43 additions and 80 deletions

View file

@ -1,6 +1,6 @@
#
#Tue Dec 17 19:56:56 EST 2013
#Sat Dec 21 18:48:29 EST 2013
minecraft_version=1.6.4
forge_version=9.11.1.964
build_number=31
mod_version=0.0
build_number=30

View file

@ -6,6 +6,7 @@ import com.pahimar.ee3.command.CommandHandler;
import com.pahimar.ee3.configuration.ConfigurationHandler;
import com.pahimar.ee3.creativetab.CreativeTabEE3;
import com.pahimar.ee3.handler.*;
import com.pahimar.ee3.helper.DebugHelper;
import com.pahimar.ee3.helper.FluidHelper;
import com.pahimar.ee3.helper.LogHelper;
import com.pahimar.ee3.helper.VersionHelper;
@ -163,6 +164,7 @@ public class EquivalentExchange3
public void postInit(FMLPostInitializationEvent event)
{
// NOOP
DebugHelper.printEmcValueToStackMappings();
}
@EventHandler

View file

@ -23,15 +23,12 @@ public class GuiPortableTransmutation extends GuiContainer
public GuiPortableTransmutation(Container par1Container)
{
super(par1Container);
// TODO Auto-generated constructor stub
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Textures.GUI_PORTABLE_TRANSMUTATION);
int var5 = (width - xSize) / 2;
@ -42,7 +39,6 @@ public class GuiPortableTransmutation extends GuiContainer
@Override
public void onGuiClosed()
{
super.onGuiClosed();
if (mc.thePlayer != null)

View file

@ -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()
@ -140,9 +143,7 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
{
StringBuilder stringBuilder = new StringBuilder();
// TODO Intelligible output
stringBuilder.append("[");
for (EmcType emcType : EmcType.TYPES)
{
if (components[emcType.ordinal()] > 0)
@ -150,7 +151,6 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
stringBuilder.append(String.format(" %s:%s ", emcType, components[emcType.ordinal()]));
}
}
stringBuilder.append("]");
return stringBuilder.toString();
@ -303,8 +303,7 @@ public class EmcValue implements Comparable<EmcValue>, JsonDeserializer<EmcValue
}
catch (UnsupportedOperationException exception)
{
// TODO Better logging/handling of the exception
exception.printStackTrace(System.err);
LogHelper.severe(exception.getMessage());
}
}
}

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))));
// 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))));

View file

@ -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)));
}
}
}

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 EmcValue[] DEFAULT_EMC_VALUES = {
new EmcValue(0.1f),
new EmcValue(1),
new EmcValue(256),
new EmcValue(2048),
new EmcValue(8192),

View file

@ -3,6 +3,7 @@ package com.pahimar.ee3.recipe;
import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.emc.EmcValue;
import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.lib.Compare;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
@ -34,66 +35,20 @@ public class CalcinationManager
List<ItemStack> calcinationResults = new ArrayList<ItemStack>();
EmcValue emcValue = EmcRegistry.getInstance().getEmcValue(itemStack);
EmcValue ashEmcValue = EmcRegistry.getInstance().getEmcValue(ASH_DUST_STACK);
EmcValue miniumEmcValue = EmcRegistry.getInstance().getEmcValue(MINIUM_DUST_STACK);
EmcValue verdantEmcValue = EmcRegistry.getInstance().getEmcValue(VERDANT_DUST_STACK);
EmcValue azureEmcValue = EmcRegistry.getInstance().getEmcValue(AZURE_DUST_STACK);
EmcValue amarathineEmcValue = EmcRegistry.getInstance().getEmcValue(AMARANTHINE_DUST_STACK);
EmcValue iridescentEmcValue = EmcRegistry.getInstance().getEmcValue(IRIDESCENT_DUST_STACK);
if (emcValue != null)
{
// // ASH
// if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(ASH_DUST_STACK).getValue()) == Compare.LESSER_THAN)
// {
//
// }
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(ASH_DUST_STACK).getValue()) == Compare.EQUALS)
// {
//
// }
// // MINIUM
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(MINIUM_DUST_STACK).getValue()) == Compare.LESSER_THAN)
// {
//
// }
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(MINIUM_DUST_STACK).getValue()) == Compare.EQUALS)
// {
//
// }
// // VERDANT
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(VERDANT_DUST_STACK).getValue()) == Compare.LESSER_THAN)
// {
//
// }
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(VERDANT_DUST_STACK).getValue()) == Compare.EQUALS)
// {
//
// }
// // AZURE
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(AZURE_DUST_STACK).getValue()) == Compare.LESSER_THAN)
// {
//
// }
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(AZURE_DUST_STACK).getValue()) == Compare.EQUALS)
// {
//
// }
// // AMARATHINE
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(AMARANTHINE_DUST_STACK).getValue()) == Compare.LESSER_THAN)
// {
//
// }
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(AMARANTHINE_DUST_STACK).getValue()) == Compare.EQUALS)
// {
//
// }
// // IRIDESCENT
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(IRIDESCENT_DUST_STACK).getValue()) == Compare.LESSER_THAN)
// {
//
// }
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(IRIDESCENT_DUST_STACK).getValue()) == Compare.LESSER_THAN)
// {
//
// }
// else if (Float.compare(emcValue.getValue(), EmcRegistry.getEmcValue(IRIDESCENT_DUST_STACK).getValue()) == Compare.GREATER_THAN)
// {
//
// }
if (Float.compare(emcValue.getValue(), ashEmcValue.getValue()) <= Compare.EQUALS)
{
}
else if
}
else
{