In an effort to reduce complexity, switch from multiple different energy values types to a single one
This commit is contained in:
parent
845e9b02eb
commit
2acc33b2b7
4 changed files with 65 additions and 85 deletions
|
@ -11,11 +11,10 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
{
|
{
|
||||||
private static final Gson jsonSerializer = (new GsonBuilder()).registerTypeAdapter(EnergyValue.class, new EnergyValue()).create();
|
private static final Gson jsonSerializer = (new GsonBuilder()).registerTypeAdapter(EnergyValue.class, new EnergyValue()).create();
|
||||||
private float energyValue;
|
private float energyValue;
|
||||||
private final EnergyType energyType;
|
|
||||||
|
|
||||||
public EnergyValue()
|
public EnergyValue()
|
||||||
{
|
{
|
||||||
this(0f, EnergyType.UNKNOWN);
|
this(0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnergyValue(int energyValue)
|
public EnergyValue(int energyValue)
|
||||||
|
@ -29,19 +28,8 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnergyValue(float energyValue)
|
public EnergyValue(float energyValue)
|
||||||
{
|
|
||||||
this(energyValue, EnergyType.DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnergyValue(float energyValue, EnergyType energyType)
|
|
||||||
{
|
{
|
||||||
this.energyValue = energyValue;
|
this.energyValue = energyValue;
|
||||||
this.energyType = energyType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EnergyValue(int energyValue, EnergyType energyType)
|
|
||||||
{
|
|
||||||
this((float) energyValue, energyType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,7 +41,7 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format(" %s@%s ", energyValue, energyType);
|
return String.format("%s", energyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -61,14 +49,7 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
{
|
{
|
||||||
if (energyValue != null)
|
if (energyValue != null)
|
||||||
{
|
{
|
||||||
if (this.energyType == energyValue.getEnergyType())
|
return Float.compare(this.energyValue, energyValue.getEnergyValue());
|
||||||
{
|
|
||||||
return Float.compare(this.energyValue, energyValue.getEnergyValue());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return (this.energyType.ordinal() - energyValue.getEnergyType().ordinal());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -76,27 +57,48 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnergyType getEnergyType()
|
|
||||||
{
|
|
||||||
return this.energyType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getEnergyValue()
|
public float getEnergyValue()
|
||||||
{
|
{
|
||||||
return this.energyValue;
|
return this.energyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(int energyValue)
|
||||||
|
{
|
||||||
|
this.add((float) energyValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(float energyValue)
|
||||||
|
{
|
||||||
|
if (energyValue >= 0f)
|
||||||
|
{
|
||||||
|
this.energyValue += energyValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void add(EnergyValue energyValue)
|
public void add(EnergyValue energyValue)
|
||||||
{
|
{
|
||||||
if (energyValue != null && this.energyType == energyValue.energyType && energyValue.energyValue > 0f)
|
if (energyValue != null && energyValue.energyValue >= 0f)
|
||||||
{
|
{
|
||||||
this.energyValue += energyValue.energyValue;
|
this.energyValue += energyValue.energyValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void subtract(int energyValue)
|
||||||
|
{
|
||||||
|
this.subtract((float) energyValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subtract(float energyValue)
|
||||||
|
{
|
||||||
|
if (this.energyValue - energyValue >= 0f)
|
||||||
|
{
|
||||||
|
this.energyValue -= energyValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void subtract(EnergyValue energyValue)
|
public void subtract(EnergyValue energyValue)
|
||||||
{
|
{
|
||||||
if (energyValue != null && this.energyType == energyValue.energyType && (this.energyValue - energyValue.energyValue) >= 0f)
|
if (energyValue != null && (this.energyValue - energyValue.energyValue) >= 0f)
|
||||||
{
|
{
|
||||||
this.energyValue -= energyValue.energyValue;
|
this.energyValue -= energyValue.energyValue;
|
||||||
}
|
}
|
||||||
|
@ -110,10 +112,17 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound)
|
public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound)
|
||||||
{
|
{
|
||||||
nbtTagCompound.setFloat("energyValue", energyValue);
|
nbtTagCompound.setFloat("energyValue", energyValue);
|
||||||
nbtTagCompound.setInteger("energyType", energyType.ordinal());
|
|
||||||
return nbtTagCompound;
|
return nbtTagCompound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
||||||
|
{
|
||||||
|
if (nbtTagCompound.hasKey("energyValue"))
|
||||||
|
{
|
||||||
|
this.energyValue = nbtTagCompound.getFloat("energyValue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static NBTTagCompound writeEnergyValueToNBT(EnergyValue energyValue)
|
public static NBTTagCompound writeEnergyValueToNBT(EnergyValue energyValue)
|
||||||
{
|
{
|
||||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||||
|
@ -123,12 +132,11 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
|
|
||||||
public static EnergyValue loadEnergyValueFromNBT(NBTTagCompound nbtTagCompound)
|
public static EnergyValue loadEnergyValueFromNBT(NBTTagCompound nbtTagCompound)
|
||||||
{
|
{
|
||||||
if (nbtTagCompound.hasKey("energyValue") && nbtTagCompound.hasKey("energyType"))
|
if (nbtTagCompound.hasKey("energyValue"))
|
||||||
{
|
{
|
||||||
float energyValue = nbtTagCompound.getFloat("energyValue");
|
float energyValue = nbtTagCompound.getFloat("energyValue");
|
||||||
EnergyType energyType = EnergyType.getEnergyTypeFromOrdinal(nbtTagCompound.getInteger("energyType"));
|
|
||||||
|
|
||||||
return new EnergyValue(energyValue, energyType);
|
return new EnergyValue(energyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -189,14 +197,13 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
{
|
{
|
||||||
JsonObject jsonEnergyValue = (JsonObject) jsonElement;
|
JsonObject jsonEnergyValue = (JsonObject) jsonElement;
|
||||||
|
|
||||||
if (jsonEnergyValue.get("type") != null && jsonEnergyValue.get("type").isJsonPrimitive() && jsonEnergyValue.get("value") != null && jsonEnergyValue.get("value").isJsonPrimitive())
|
if (jsonEnergyValue.get("value") != null && jsonEnergyValue.get("value").isJsonPrimitive())
|
||||||
{
|
{
|
||||||
EnergyType energyType = EnergyType.getEnergyTypeFromOrdinal(jsonEnergyValue.get("type").getAsInt());
|
|
||||||
float energyValue = jsonEnergyValue.get("value").getAsFloat();
|
float energyValue = jsonEnergyValue.get("value").getAsFloat();
|
||||||
|
|
||||||
if (Float.compare(energyValue, 0f) > 0)
|
if (Float.compare(energyValue, 0f) >= 0)
|
||||||
{
|
{
|
||||||
return new EnergyValue(energyValue, energyType);
|
return new EnergyValue(energyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,52 +230,8 @@ public final class EnergyValue implements Comparable<EnergyValue>, JsonDeseriali
|
||||||
{
|
{
|
||||||
JsonObject jsonEnergyValue = new JsonObject();
|
JsonObject jsonEnergyValue = new JsonObject();
|
||||||
|
|
||||||
jsonEnergyValue.addProperty("type", energyValueObject.energyType.ordinal());
|
|
||||||
jsonEnergyValue.addProperty("value", energyValueObject.energyValue);
|
jsonEnergyValue.addProperty("value", energyValueObject.energyValue);
|
||||||
|
|
||||||
return jsonEnergyValue;
|
return jsonEnergyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum EnergyType
|
|
||||||
{
|
|
||||||
UNKNOWN, CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI;
|
|
||||||
|
|
||||||
public static final EnergyType DEFAULT = EnergyType.CORPOREAL;
|
|
||||||
|
|
||||||
public static EnergyType getEnergyTypeFromOrdinal(int ordinal)
|
|
||||||
{
|
|
||||||
if (ordinal == CORPOREAL.ordinal())
|
|
||||||
{
|
|
||||||
return CORPOREAL;
|
|
||||||
}
|
|
||||||
else if (ordinal == KINETIC.ordinal())
|
|
||||||
{
|
|
||||||
return KINETIC;
|
|
||||||
}
|
|
||||||
else if (ordinal == TEMPORAL.ordinal())
|
|
||||||
{
|
|
||||||
return TEMPORAL;
|
|
||||||
}
|
|
||||||
else if (ordinal == ESSENTIA.ordinal())
|
|
||||||
{
|
|
||||||
return ESSENTIA;
|
|
||||||
}
|
|
||||||
else if (ordinal == AMORPHOUS.ordinal())
|
|
||||||
{
|
|
||||||
return AMORPHOUS;
|
|
||||||
}
|
|
||||||
else if (ordinal == VOID.ordinal())
|
|
||||||
{
|
|
||||||
return VOID;
|
|
||||||
}
|
|
||||||
else if (ordinal == OMNI.ordinal())
|
|
||||||
{
|
|
||||||
return OMNI;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return UNKNOWN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import codechicken.nei.PositionedStack;
|
||||||
import codechicken.nei.recipe.FurnaceRecipeHandler;
|
import codechicken.nei.recipe.FurnaceRecipeHandler;
|
||||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||||
import com.pahimar.ee3.api.EnergyValue;
|
import com.pahimar.ee3.api.EnergyValue;
|
||||||
import com.pahimar.ee3.api.EnergyValue.EnergyType;
|
|
||||||
import com.pahimar.ee3.api.EnergyValueRegistryProxy;
|
import com.pahimar.ee3.api.EnergyValueRegistryProxy;
|
||||||
import com.pahimar.ee3.client.gui.inventory.GuiCalcinator;
|
import com.pahimar.ee3.client.gui.inventory.GuiCalcinator;
|
||||||
import com.pahimar.ee3.item.ItemAlchemicalDust;
|
import com.pahimar.ee3.item.ItemAlchemicalDust;
|
||||||
|
@ -45,7 +44,7 @@ public class CalcinationHandler extends TemplateRecipeHandler
|
||||||
inputs = new ArrayList<PositionedStack>();
|
inputs = new ArrayList<PositionedStack>();
|
||||||
|
|
||||||
minEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputDust);
|
minEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputDust);
|
||||||
maxEnergyValue = (outputDust.getItemDamage() < (ItemAlchemicalDust.getAlchemicalDusts().size() - 1) ? EnergyValueRegistryProxy.getEnergyValue(ItemAlchemicalDust.getAlchemicalDusts().get(outputDust.getItemDamage() + 1)) : new EnergyValue(Float.MAX_VALUE, EnergyType.CORPOREAL));
|
maxEnergyValue = (outputDust.getItemDamage() < (ItemAlchemicalDust.getAlchemicalDusts().size() - 1) ? EnergyValueRegistryProxy.getEnergyValue(ItemAlchemicalDust.getAlchemicalDusts().get(outputDust.getItemDamage() + 1)) : new EnergyValue(Float.MAX_VALUE));
|
||||||
|
|
||||||
for (Object obj : EnergyValueRegistryProxy.getStacksInRange(minEnergyValue, maxEnergyValue))
|
for (Object obj : EnergyValueRegistryProxy.getStacksInRange(minEnergyValue, maxEnergyValue))
|
||||||
{
|
{
|
||||||
|
@ -64,7 +63,7 @@ public class CalcinationHandler extends TemplateRecipeHandler
|
||||||
output = new PositionedStack(outputDust, 101, 19);
|
output = new PositionedStack(outputDust, 101, 19);
|
||||||
|
|
||||||
minEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputDust);
|
minEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputDust);
|
||||||
maxEnergyValue = (outputDust.getItemDamage() < (ItemAlchemicalDust.getAlchemicalDusts().size() - 1) ? EnergyValueRegistryProxy.getEnergyValue(ItemAlchemicalDust.getAlchemicalDusts().get(outputDust.getItemDamage() + 1)) : new EnergyValue(Float.MAX_VALUE, EnergyType.CORPOREAL));
|
maxEnergyValue = (outputDust.getItemDamage() < (ItemAlchemicalDust.getAlchemicalDusts().size() - 1) ? EnergyValueRegistryProxy.getEnergyValue(ItemAlchemicalDust.getAlchemicalDusts().get(outputDust.getItemDamage() + 1)) : new EnergyValue(Float.MAX_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.pahimar.ee3.exchange.WrappedStack;
|
import com.pahimar.ee3.exchange.WrappedStack;
|
||||||
|
import com.pahimar.ee3.util.LogHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -78,4 +79,21 @@ public class RecipeRegistry
|
||||||
|
|
||||||
return immutableRecipeMap;
|
return immutableRecipeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dumpRecipeRegistryToLog()
|
||||||
|
{
|
||||||
|
for (WrappedStack wrappedStack : recipeMap.keySet())
|
||||||
|
{
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append(String.format("Output: %s, Inputs: ", wrappedStack.toString()));
|
||||||
|
for (List<WrappedStack> listStacks : recipeMap.get(wrappedStack))
|
||||||
|
{
|
||||||
|
for (WrappedStack listStack : listStacks)
|
||||||
|
{
|
||||||
|
stringBuilder.append(listStack.toString() + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogHelper.info(stringBuilder.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -109,7 +109,7 @@ public class EnergyValueHelper
|
||||||
{
|
{
|
||||||
if ((Float.compare(factor, 0f) != 0) && (energyValue != null))
|
if ((Float.compare(factor, 0f) != 0) && (energyValue != null))
|
||||||
{
|
{
|
||||||
return new EnergyValue(energyValue.getEnergyValue() * 1f / factor, energyValue.getEnergyType());
|
return new EnergyValue(energyValue.getEnergyValue() * 1f / factor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue