Something something more dark side

This commit is contained in:
pahimar 2013-11-20 20:17:32 -05:00
parent 6f16e3296b
commit a034a379c4
5 changed files with 87 additions and 145 deletions

View file

@ -24,7 +24,6 @@ import com.pahimar.ee3.core.helper.VersionHelper;
import com.pahimar.ee3.core.proxy.CommonProxy; import com.pahimar.ee3.core.proxy.CommonProxy;
import com.pahimar.ee3.creativetab.CreativeTabEE3; import com.pahimar.ee3.creativetab.CreativeTabEE3;
import com.pahimar.ee3.emc.EmcRegistry; import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.emc.EmcValue;
import com.pahimar.ee3.item.ModItems; import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes; import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
import com.pahimar.ee3.lib.Reference; import com.pahimar.ee3.lib.Reference;

View file

@ -53,6 +53,7 @@ public class EmcValue implements Comparable<EmcValue> {
} }
public EmcValue(int value, EmcType emcType) { public EmcValue(int value, EmcType emcType) {
this((float) value, emcType); this((float) value, emcType);
} }
@ -167,8 +168,10 @@ public class EmcValue implements Comparable<EmcValue> {
/** /**
* Deserializes an EmcValue object from the given serialized json String * Deserializes an EmcValue object from the given serialized json String
* *
* @param jsonEmcValue Json encoded String representing a EmcValue object * @param jsonEmcValue
* @return The EmcValue that was encoded as json, or null if a valid EmcValue could not be decoded from given String * Json encoded String representing a EmcValue object
* @return The EmcValue that was encoded as json, or null if a valid
* EmcValue could not be decoded from given String
*/ */
public static EmcValue createFromJson(String jsonEmcValue) { public static EmcValue createFromJson(String jsonEmcValue) {
@ -188,6 +191,7 @@ public class EmcValue implements Comparable<EmcValue> {
* @return Json serialized String of this EmcValue * @return Json serialized String of this EmcValue
*/ */
public String toJson() { public String toJson() {
return gsonSerializer.toJson(this); return gsonSerializer.toJson(this);
} }
@ -235,7 +239,8 @@ public class EmcValue implements Comparable<EmcValue> {
} }
} }
public class EmcValueJsonSerializer implements JsonDeserializer<EmcValue>, JsonSerializer<EmcValue> { private class EmcValueJsonSerializer
implements JsonDeserializer<EmcValue>, JsonSerializer<EmcValue> {
@Override @Override
public JsonElement serialize(EmcValue emcValue, Type type, JsonSerializationContext context) { public JsonElement serialize(EmcValue emcValue, Type type, JsonSerializationContext context) {

View file

@ -1,8 +1,6 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -13,22 +11,13 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.pahimar.ee3.core.helper.ItemHelper; import com.pahimar.ee3.core.helper.ItemHelper;
import com.pahimar.ee3.lib.Reference;
import com.pahimar.ee3.lib.Strings;
public class CustomWrappedStack implements Comparable<CustomWrappedStack> { public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
// Gson serializer for serializing to/deserializing from json // Gson serializer for serializing to/deserializing from json
private static final Gson gsonSerializer = (new GsonBuilder()).registerTypeAdapter(CustomWrappedStack.class, new CustomWrappedStack(null).new CustomWrappedStackJsonSerializer()).create(); private static final Gson gsonSerializer = new Gson();
private int stackSize; private int stackSize;
private final ItemStack itemStack; private final ItemStack itemStack;
@ -36,6 +25,8 @@ public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
private final EnergyStack energyStack; private final EnergyStack energyStack;
private final FluidStack fluidStack; private final FluidStack fluidStack;
private static final int ORE_DICTIONARY_NOT_FOUND = -1;
/** /**
* Creates a new CustomWrappedStack object which wraps the given input. * Creates a new CustomWrappedStack object which wraps the given input.
* Valid inputs would be ItemStacks or OreStacks. If something other than an * Valid inputs would be ItemStacks or OreStacks. If something other than an
@ -108,61 +99,6 @@ public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
energyStack = null; energyStack = null;
fluidStack = null; fluidStack = null;
} }
else if (object instanceof String) {
String objectString = (String) object;
if (objectString.startsWith(Strings.NBT_ENCODED_ATTR_ORE_NAME + ":")) {
String possibleOreName = objectString.substring(Strings.NBT_ENCODED_ATTR_ORE_NAME.length() + 1);
OreStack possibleOreStack = new OreStack(possibleOreName);
if (possibleOreStack.oreId != -1) {
itemStack = null;
oreStack = possibleOreStack;
energyStack = null;
fluidStack = null;
stackSize = possibleOreStack.stackSize;
}
else {
itemStack = null;
oreStack = null;
energyStack = null;
fluidStack = null;
stackSize = -1;
}
}
else if (objectString.startsWith(Strings.NBT_ENCODED_ATTR_ENERGY_NAME + ":")) {
String possibleEnergyName = objectString.substring(Strings.NBT_ENCODED_ATTR_ENERGY_NAME.length() + 1);
if (possibleEnergyName.length() > 0) {
itemStack = null;
oreStack = null;
energyStack = new EnergyStack(possibleEnergyName);
fluidStack = null;
stackSize = 1;
}
else {
itemStack = null;
oreStack = null;
energyStack = null;
fluidStack = null;
stackSize = -1;
}
}
else {
itemStack = null;
oreStack = null;
energyStack = null;
fluidStack = null;
stackSize = -1;
}
}
/* /*
* Or we are given an EnergyStack to wrap * Or we are given an EnergyStack to wrap
*/ */
@ -327,41 +263,25 @@ public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
public static boolean canBeWrapped(Object object) { public static boolean canBeWrapped(Object object) {
// Simple case if (object instanceof CustomWrappedStack) {
if (object instanceof CustomWrappedStack || object instanceof ItemStack || object instanceof OreStack || object instanceof EnergyStack || object instanceof FluidStack || object instanceof Item || object instanceof Block || object instanceof Fluid) { return true;
}
else if (object instanceof Item || object instanceof Block || object instanceof ItemStack) {
return true;
}
else if (object instanceof OreStack) {
return true; return true;
} }
// If it's a List, check to see if it could possibly be an OreStack
else if (object instanceof List) { else if (object instanceof List) {
if (getOreStackFromList((List<?>) object) != null) { if (getOreStackFromList((List<?>) object) != null) {
return true; return true;
} }
} }
// If it's a String, check to see if it could be the encoded name for a custom stack (OreStack, EnergyStack, etc) else if (object instanceof EnergyStack) {
// TODO Revisit this now that we aren't using NBTTagCompounds to encode objects return true;
else if (object instanceof String) { }
else if (object instanceof Fluid || object instanceof FluidStack) {
String objectString = (String) object; return true;
if (objectString.startsWith(Strings.NBT_ENCODED_ATTR_ORE_NAME + ":")) {
String possibleOreName = objectString.substring(Strings.NBT_ENCODED_ATTR_ORE_NAME.length() + 1);
List<String> oreNames = Arrays.asList(OreDictionary.getOreNames());
for (String oreName : oreNames) {
if (oreName.equalsIgnoreCase(possibleOreName)) {
return true;
}
}
}
else if (objectString.startsWith(Strings.NBT_ENCODED_ATTR_ENERGY_NAME + ":")) {
String possibleEnergyName = objectString.substring(Strings.NBT_ENCODED_ATTR_ENERGY_NAME.length() + 1);
if (possibleEnergyName.length() > 0) {
return true;
}
}
} }
return false; return false;
@ -437,7 +357,7 @@ public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
if (listElement instanceof ItemStack) { if (listElement instanceof ItemStack) {
ItemStack stack = (ItemStack) listElement; ItemStack stack = (ItemStack) listElement;
if (OreDictionary.getOreID(stack) != Reference.ORE_DICTIONARY_NOT_FOUND) { if (OreDictionary.getOreID(stack) != CustomWrappedStack.ORE_DICTIONARY_NOT_FOUND) {
return new OreStack(stack); return new OreStack(stack);
} }
} }
@ -452,8 +372,8 @@ public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
* *
* @param jsonEmcValue * @param jsonEmcValue
* Json encoded String representing a CustomWrappedStack object * Json encoded String representing a CustomWrappedStack object
* @return The EmcValue that was encoded as json, or null if a valid * @return The CustomWrappedStack that was encoded as json, or null if a
* CustomWrappedStack could not be decoded from given String * valid CustomWrappedStack could not be decoded from given String
*/ */
public static CustomWrappedStack createFromJson(String jsonCustomWrappedStack) { public static CustomWrappedStack createFromJson(String jsonCustomWrappedStack) {
@ -476,23 +396,4 @@ public class CustomWrappedStack implements Comparable<CustomWrappedStack> {
return gsonSerializer.toJson(this); return gsonSerializer.toJson(this);
} }
public class CustomWrappedStackJsonSerializer
implements JsonDeserializer<CustomWrappedStack>,
JsonSerializer<CustomWrappedStack> {
@Override
public JsonElement serialize(CustomWrappedStack customWrappedStack, Type type, JsonSerializationContext context) {
// TODO Auto-generated method stub
return null;
}
@Override
public CustomWrappedStack deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
// TODO Auto-generated method stub
return null;
}
}
} }

View file

@ -5,8 +5,14 @@ import java.util.ArrayList;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
public class OreStack implements Comparable<OreStack> { public class OreStack implements Comparable<OreStack> {
// Gson serializer for serializing to/deserializing from json
private static final Gson gsonSerializer = new Gson();
public int oreId; public int oreId;
public String oreName; public String oreName;
public int stackSize; public int stackSize;
@ -139,4 +145,35 @@ public class OreStack implements Comparable<OreStack> {
return 1; return 1;
} }
} }
/**
* Deserializes a OreStack object from the given serialized json
* String
*
* @param jsonEmcValue
* Json encoded String representing a OreStack object
* @return The OreStack that was encoded as json, or null if a valid
* OreStack could not be decoded from given String
*/
public static OreStack createFromJson(String jsonOreStack) {
try {
return (OreStack) gsonSerializer.fromJson(jsonOreStack, OreStack.class);
}
catch (JsonSyntaxException exception) {
// TODO Log something regarding the failed parse
}
return null;
}
/**
* Returns this OreStack as a json serialized String
*
* @return Json serialized String of this OreStack
*/
public String toJson() {
return gsonSerializer.toJson(this);
}
} }

View file

@ -11,10 +11,7 @@ package com.pahimar.ee3.lib;
*/ */
public class Reference { public class Reference {
/* Debug Mode On-Off */ // General Mod related constants
public static final boolean DEBUG_MODE = false;
/* General Mod related constants */
public static final String MOD_ID = "EE3"; public static final String MOD_ID = "EE3";
public static final String MOD_NAME = "Equivalent Exchange 3"; public static final String MOD_NAME = "Equivalent Exchange 3";
public static final String VERSION_NUMBER = "@VERSION@ (build @BUILD_NUMBER@)"; public static final String VERSION_NUMBER = "@VERSION@ (build @BUILD_NUMBER@)";
@ -27,6 +24,9 @@ public class Reference {
public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.core.proxy.ClientProxy"; public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.core.proxy.ClientProxy";
public static final int VERSION_CHECK_ATTEMPTS = 3; public static final int VERSION_CHECK_ATTEMPTS = 3;
public static final int ORE_DICTIONARY_NOT_FOUND = -1; // Comparator stuff
public static final int SMALLER_THAN = -1;
public static final int EQUAL_TO = 0;
public static final int LARGER_THAN = 1;
} }