More API related shenanigans, MUCH more to come (provide comments on your API related needs to pahimar@gmail.com)

This commit is contained in:
Pahimar 2014-07-07 15:31:10 -04:00
parent a1dc2d2130
commit 32bbca53cb
27 changed files with 230 additions and 160 deletions

View file

@ -1,6 +1,7 @@
package com.pahimar.ee3;
import com.pahimar.ee3.configuration.ConfigurationHandler;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.handler.CraftingHandler;
import com.pahimar.ee3.handler.FuelHandler;
import com.pahimar.ee3.handler.GuiHandler;
@ -11,6 +12,7 @@ import com.pahimar.ee3.network.PacketHandler;
import com.pahimar.ee3.proxy.IProxy;
import com.pahimar.ee3.reference.Messages;
import com.pahimar.ee3.reference.Reference;
import com.pahimar.ee3.skill.SkillRegistry;
import com.pahimar.ee3.util.LogHelper;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
@ -100,4 +102,14 @@ public class EquivalentExchange3
{
}
public EnergyValueRegistry getEnergyValueRegistry()
{
return EnergyValueRegistry.getInstance();
}
public SkillRegistry getSkillRegistry()
{
return SkillRegistry.getInstance();
}
}

View file

@ -0,0 +1,62 @@
package com.pahimar.ee3.api;
import com.pahimar.ee3.EquivalentExchange3;
import cpw.mods.fml.common.Mod;
public class EnergyValueRegistryProxy
{
@Mod.Instance("EE3")
private static Object ee3Mod;
public static void addValue(IEnergyValue energyValue)
{
init();
// NOOP if EquivalentExchange3 is not present
if (ee3Mod == null)
{
return;
}
// TODO
}
private static void init()
{
if (ee3Mod != null)
{
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
}
}
public static void getValue(Object object)
{
init();
// NOOP if EquivalentExchange3 is not present
if (ee3Mod == null)
{
return;
}
EE3Wrapper.ee3mod.getEnergyValueRegistry().getEnergyValue(object);
}
public static void getValue(Object object, boolean strict)
{
init();
// NOOP if EquivalentExchange3 is not present
if (ee3Mod == null)
{
return;
}
EE3Wrapper.ee3mod.getEnergyValueRegistry().getEnergyValue(object, strict);
}
private static class EE3Wrapper
{
private static EquivalentExchange3 ee3mod;
}
}

View file

@ -0,0 +1,5 @@
package com.pahimar.ee3.api;
public interface IEnergyValue
{
}

View file

@ -0,0 +1,8 @@
package com.pahimar.ee3.api;
import net.minecraft.item.ItemStack;
public interface IEnergyValueProvider
{
public abstract IEnergyValue getEnergyValue(ItemStack itemStack);
}

View file

@ -0,0 +1,80 @@
package com.pahimar.ee3.api;
import com.pahimar.ee3.EquivalentExchange3;
import cpw.mods.fml.common.Mod;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class SkillRegistryProxy
{
@Mod.Instance("EE3")
private static Object ee3Mod;
public static void addSkill(Item item)
{
addSkill(new ItemStack(item));
}
public static void addSkill(ItemStack itemStack)
{
addSkill(itemStack, true, true);
}
public static void addSkill(ItemStack itemStack, boolean isLearnable, boolean isRecovereable)
{
init();
// NOOP if EquivalentExchange3 is not present
if (ee3Mod == null)
{
return;
}
EE3Wrapper.ee3mod.getSkillRegistry().addSkill(itemStack, isLearnable, isRecovereable);
}
private static void init()
{
if (ee3Mod != null)
{
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
}
}
public static void addSkill(Block block)
{
addSkill(new ItemStack(block));
}
public static void isLearnable(ItemStack itemStack)
{
init();
// NOOP if EquivalentExchange3 is not present
if (ee3Mod == null)
{
return;
}
EE3Wrapper.ee3mod.getSkillRegistry().isLearnable(itemStack);
}
public static void isRecoverable(ItemStack itemStack)
{
init();
// NOOP if EquivalentExchange3 is not present
if (ee3Mod == null)
{
return;
}
EE3Wrapper.ee3mod.getSkillRegistry().isRecoverable(itemStack);
}
private static class EE3Wrapper
{
private static EquivalentExchange3 ee3mod;
}
}

View file

@ -1,8 +0,0 @@
package com.pahimar.ee3.api.exchange;
import net.minecraft.item.ItemStack;
public interface IEnergyValueProvider
{
public abstract EnergyValue getEnergyValue(ItemStack itemStack);
}

View file

@ -1,8 +1,8 @@
package com.pahimar.ee3.client.handler;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.api.exchange.EnergyValue;
import com.pahimar.ee3.api.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.EnergyValue;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.WrappedStack;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

View file

@ -1,20 +1,17 @@
package com.pahimar.ee3.api.exchange;
package com.pahimar.ee3.exchange;
public class EnergyComponent implements Comparable<EnergyComponent>
{
public final EnergyType type;
public final int weight;
public EnergyComponent(EnergyType type)
{
this(type, 1);
}
public EnergyComponent(EnergyType type, int weight)
{
this.type = type;
if (weight > 0)
@ -30,7 +27,6 @@ public class EnergyComponent implements Comparable<EnergyComponent>
@Override
public boolean equals(Object object)
{
if (!(object instanceof EnergyComponent))
{
return false;
@ -50,7 +46,6 @@ public class EnergyComponent implements Comparable<EnergyComponent>
@Override
public int compareTo(EnergyComponent energyComponent)
{
if (energyComponent != null)
{
if (this.type == energyComponent.type)

View file

@ -1,4 +1,4 @@
package com.pahimar.ee3.api.exchange;
package com.pahimar.ee3.exchange;
public enum EnergyType
{

View file

@ -1,19 +1,13 @@
package com.pahimar.ee3.api.exchange;
package com.pahimar.ee3.exchange;
import com.google.gson.*;
import com.pahimar.ee3.util.LogHelper;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<EnergyValue>, JsonSerializer<EnergyValue>
public class EnergyValue implements Comparable<EnergyValue>
{
// Gson serializer for serializing to/deserializing from json
private static final Gson gsonSerializer = (new GsonBuilder()).registerTypeAdapter(EnergyValue.class, new EnergyValue()).create();
private static final int PRECISION = 4;
public final float[] components;
@ -140,32 +134,6 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
this((float) value, componentList);
}
/**
* Deserializes an EnergyValue object from the given serialized json String
*
* @param jsonEnergyValue Json encoded String representing a EnergyValue object
* @return The EnergyValue that was encoded as json, or null if a valid EnergyValue could not be decoded from given
* String
*/
@SuppressWarnings("unused")
public static EnergyValue createFromJson(String jsonEnergyValue)
{
try
{
return gsonSerializer.fromJson(jsonEnergyValue, EnergyValue.class);
}
catch (JsonSyntaxException exception)
{
LogHelper.error(exception.getMessage());
}
catch (JsonParseException exception)
{
LogHelper.error(exception.getMessage());
}
return null;
}
@Override
public int hashCode()
{
@ -252,59 +220,4 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
throw new ArrayIndexOutOfBoundsException();
}
}
/**
* Returns this EnergyValue as a json serialized String
*
* @return Json serialized String of this EnergyValue
*/
public String toJson()
{
return gsonSerializer.toJson(this);
}
@Override
public JsonElement serialize(EnergyValue exchangeEnergyValue, Type type, JsonSerializationContext context)
{
JsonObject jsonEnergyValue = new JsonObject();
for (EnergyType energyType : EnergyType.TYPES)
{
jsonEnergyValue.addProperty(energyType.toString(), exchangeEnergyValue.components[energyType.ordinal()]);
}
return jsonEnergyValue;
}
@Override
public EnergyValue deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException
{
float[] energyValueComponents = new float[EnergyType.TYPES.length];
JsonObject jsonEnergyValue = (JsonObject) jsonElement;
for (EnergyType energyType : EnergyType.TYPES)
{
if ((jsonEnergyValue.get(energyType.toString()) != null) && (jsonEnergyValue.get(energyType.toString()).isJsonPrimitive()))
{
try
{
energyValueComponents[energyType.ordinal()] = jsonEnergyValue.get(energyType.toString()).getAsFloat();
}
catch (UnsupportedOperationException exception)
{
LogHelper.error(exception.getMessage());
}
}
}
EnergyValue exchangeEnergyValue = new EnergyValue(energyValueComponents);
if (exchangeEnergyValue.getValue() > 0f)
{
return exchangeEnergyValue;
}
return null;
}
}

View file

@ -1,10 +1,8 @@
package com.pahimar.ee3.api.exchange;
package com.pahimar.ee3.exchange;
import com.google.common.collect.ImmutableSortedMap;
import com.pahimar.ee3.api.core.OreStack;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.api.recipe.RecipeRegistry;
import com.pahimar.ee3.init.EnergyValues;
import com.pahimar.ee3.recipe.RecipeRegistry;
import com.pahimar.ee3.util.EnergyValueHelper;
import com.pahimar.ee3.util.LogHelper;
import net.minecraft.item.Item;

View file

@ -1,4 +1,4 @@
package com.pahimar.ee3.api.core;
package com.pahimar.ee3.exchange;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

View file

@ -1,4 +1,4 @@
package com.pahimar.ee3.api.core;
package com.pahimar.ee3.exchange;
import com.pahimar.ee3.util.FluidHelper;
import com.pahimar.ee3.util.ItemHelper;

View file

@ -1,8 +1,8 @@
package com.pahimar.ee3.init;
import com.pahimar.ee3.api.core.OreStack;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.api.exchange.EnergyValue;
import com.pahimar.ee3.exchange.EnergyValue;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.exchange.WrappedStack;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;

View file

@ -1,6 +1,6 @@
package com.pahimar.ee3.init;
import com.pahimar.ee3.api.recipe.RecipesAludel;
import com.pahimar.ee3.recipe.RecipesAludel;
import com.pahimar.ee3.util.CraftingHelper;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.init.Blocks;

View file

@ -1,7 +1,7 @@
package com.pahimar.ee3.api.recipe;
package com.pahimar.ee3.item.crafting;
import com.pahimar.ee3.api.core.OreStack;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.exchange.WrappedStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

View file

@ -1,11 +1,9 @@
package com.pahimar.ee3.api.recipe;
package com.pahimar.ee3.recipe;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.recipe.RecipesFluidContainers;
import com.pahimar.ee3.recipe.RecipesPotions;
import com.pahimar.ee3.recipe.RecipesVanilla;
import com.pahimar.ee3.exchange.WrappedStack;
import com.pahimar.ee3.item.crafting.RecipeAludel;
import com.pahimar.ee3.util.LogHelper;
import java.util.Collection;

View file

@ -1,6 +1,7 @@
package com.pahimar.ee3.api.recipe;
package com.pahimar.ee3.recipe;
import com.pahimar.ee3.api.core.OreStack;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.item.crafting.RecipeAludel;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;

View file

@ -2,7 +2,7 @@ package com.pahimar.ee3.recipe;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.exchange.WrappedStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;

View file

@ -2,7 +2,7 @@ package com.pahimar.ee3.recipe;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.exchange.WrappedStack;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;

View file

@ -2,7 +2,7 @@ package com.pahimar.ee3.recipe;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.exchange.WrappedStack;
import com.pahimar.ee3.util.RecipeHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;

View file

@ -1,8 +1,6 @@
package com.pahimar.ee3.skill;
import com.pahimar.ee3.init.Skills;
import com.pahimar.ee3.util.ItemHelper;
import com.pahimar.ee3.util.LogHelper;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -33,45 +31,53 @@ public class SkillRegistry
private void init()
{
skillMap = new TreeMap<ItemStack, Skill>(ItemHelper.comparator);
Skills.addDefaultSkills();
}
public boolean addSkill(Item item)
public void addSkill(Item item)
{
return addSkill(new ItemStack(item));
addSkill(new ItemStack(item));
}
public boolean addSkill(Block block)
public void addSkill(ItemStack itemStack)
{
return addSkill(new ItemStack(block));
addSkill(itemStack, true, true);
}
public boolean addSkill(ItemStack itemStack)
public void addSkill(ItemStack itemStack, boolean learnable, boolean recoverable)
{
return addSkill(itemStack, true, true);
addSkill(itemStack, new Skill(learnable, recoverable));
}
public boolean addSkill(ItemStack itemStack, boolean learnable, boolean recoverable)
{
return addSkill(itemStack, new Skill(learnable, recoverable));
}
public boolean addSkill(ItemStack itemStack, Skill skill)
private void addSkill(ItemStack itemStack, Skill skill)
{
if (!skillMap.containsKey(itemStack))
{
skillMap.put(itemStack, skill);
return true;
}
}
public void addSkill(Block block)
{
addSkill(new ItemStack(block));
}
public boolean isLearnable(ItemStack itemStack)
{
if (skillMap.containsKey(itemStack))
{
return skillMap.get(itemStack).isLearnable();
}
return false;
}
public void dumpSkillSet()
public boolean isRecoverable(ItemStack itemStack)
{
for (ItemStack itemStack : skillMap.keySet())
if (skillMap.containsKey(itemStack))
{
LogHelper.info(String.format("%s: %s", ItemHelper.toString(itemStack), skillMap.get(itemStack)));
return skillMap.get(itemStack).isRecoverable();
}
return false;
}
}

View file

@ -1,6 +1,6 @@
package com.pahimar.ee3.thread;
import com.pahimar.ee3.api.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.util.LogHelper;
public class DynamicEnergyValueInitThread implements Runnable

View file

@ -1,10 +1,10 @@
package com.pahimar.ee3.tileentity;
import com.pahimar.ee3.api.recipe.RecipeAludel;
import com.pahimar.ee3.api.recipe.RecipesAludel;
import com.pahimar.ee3.item.ItemAlchemicalDust;
import com.pahimar.ee3.item.crafting.RecipeAludel;
import com.pahimar.ee3.network.PacketHandler;
import com.pahimar.ee3.network.message.MessageTileEntityAludel;
import com.pahimar.ee3.recipe.RecipesAludel;
import com.pahimar.ee3.reference.Names;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;

View file

@ -1,7 +1,7 @@
package com.pahimar.ee3.util;
import com.pahimar.ee3.api.exchange.EnergyValue;
import com.pahimar.ee3.api.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.EnergyValue;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.init.ModItems;
import com.pahimar.ee3.item.ItemAlchemicalDust;
import net.minecraft.item.ItemStack;

View file

@ -1,9 +1,9 @@
package com.pahimar.ee3.util;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.api.exchange.EnergyType;
import com.pahimar.ee3.api.exchange.EnergyValue;
import com.pahimar.ee3.api.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.EnergyType;
import com.pahimar.ee3.exchange.EnergyValue;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.WrappedStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;

View file

@ -1,7 +1,7 @@
package com.pahimar.ee3.util;
import com.pahimar.ee3.api.core.OreStack;
import com.pahimar.ee3.api.core.WrappedStack;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.exchange.WrappedStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;