Removed unused portions of Mekanism API.

This commit is contained in:
CrazyPants committed 2014-08-29 16:57:42 +08:00
1 parent 0d314b380d
commit 496ce2ed8d
27 files changed
-1668

No files matched your search

@@ -1,28 +0,0 @@
package mekanism.api;
import mekanism.api.gas.Gas;
import net.minecraft.item.ItemStack;
public class AdvancedInput
{
public ItemStack itemStack;
public Gas gasType;
public AdvancedInput(ItemStack item, Gas gas)
{
itemStack = item;
gasType = gas;
}
public boolean isValid()
{
return itemStack != null && gasType != null;
}
public boolean matches(AdvancedInput input)
{
return StackUtils.equalsWildcard(itemStack, input.itemStack) && input.itemStack.stackSize >= itemStack.stackSize;
}
}
-38
View File
@@ -1,38 +0,0 @@
package mekanism.api;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
public class BlockInfo
{
public Block block;
public int meta;
public BlockInfo(Block b, int j)
{
block = b;
meta = j;
}
public static BlockInfo get(ItemStack stack)
{
return new BlockInfo(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage());
}
@Override
public boolean equals(Object obj)
{
return obj instanceof BlockInfo &&
((BlockInfo)obj).block == block &&
((BlockInfo)obj).meta == meta;
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + block.getUnlocalizedName().hashCode();
code = 31 * code + meta;
return code;
}
}
@@ -1,48 +0,0 @@
package mekanism.api;
import java.util.Random;
import net.minecraft.item.ItemStack;
public class ChanceOutput
{
private static Random rand = new Random();
public ItemStack primaryOutput;
public ItemStack secondaryOutput;
public double secondaryChance;
public ChanceOutput(ItemStack primary, ItemStack secondary, double chance)
{
primaryOutput = primary;
secondaryOutput = secondary;
secondaryChance = chance;
}
public ChanceOutput(ItemStack primary)
{
primaryOutput = primary;
}
public boolean checkSecondary()
{
return rand.nextDouble() <= secondaryChance;
}
public boolean hasPrimary()
{
return primaryOutput != null;
}
public boolean hasSecondary()
{
return secondaryOutput != null;
}
public ChanceOutput copy()
{
return new ChanceOutput(StackUtils.copy(primaryOutput), StackUtils.copy(secondaryOutput), secondaryChance);
}
}
@@ -1,116 +0,0 @@
package mekanism.api;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
/**
* An input of gasses for recipe use.
* @author aidancbrady
*
*/
public class ChemicalPair
{
/** The left gas of this chemical input */
public GasStack leftGas;
/** The right gas of this chemical input */
public GasStack rightGas;
/**
* Creates a chemical input with two defined gasses.
* @param left - left gas
* @param right - right gas
*/
public ChemicalPair(GasStack left, GasStack right)
{
leftGas = left;
rightGas = right;
}
/**
* If this is a valid ChemicalPair
* @return
*/
public boolean isValid()
{
return leftGas != null && rightGas != null;
}
/**
* Whether or not the defined input contains the same gasses and at least the required amount of the defined gasses as this input.
* @param input - input to check
* @return if the input meets this input's requirements
*/
public boolean meetsInput(ChemicalPair input)
{
return meets(input) || meets(input.swap());
}
/**
* Swaps the right gas and left gas of this input.
* @return a swapped ChemicalInput
*/
public ChemicalPair swap()
{
return new ChemicalPair(rightGas, leftGas);
}
/**
* Draws the needed amount of gas from each tank.
* @param leftTank - left tank to draw from
* @param rightTank - right tank to draw from
*/
public void draw(GasTank leftTank, GasTank rightTank)
{
if(meets(new ChemicalPair(leftTank.getGas(), rightTank.getGas())))
{
leftTank.draw(leftGas.amount, true);
rightTank.draw(rightGas.amount, true);
}
else if(meets(new ChemicalPair(rightTank.getGas(), leftTank.getGas())))
{
leftTank.draw(rightGas.amount, true);
rightTank.draw(leftGas.amount, true);
}
}
/**
* Whether or not one of this ChemicalInput's GasStack entry's gas type is equal to the gas type of the given gas.
* @param stack - stack to check
* @return if the stack's gas type is contained in this ChemicalInput
*/
public boolean containsType(GasStack stack)
{
if(stack == null || stack.amount == 0)
{
return false;
}
return stack.isGasEqual(leftGas) || stack.isGasEqual(rightGas);
}
/**
* Actual implementation of meetsInput(), performs the checks.
* @param input - input to check
* @return if the input meets this input's requirements
*/
private boolean meets(ChemicalPair input)
{
if(input == null || !input.isValid())
{
return false;
}
if(input.leftGas.getGas() != leftGas.getGas() || input.rightGas.getGas() != rightGas.getGas())
{
return false;
}
return input.leftGas.amount >= leftGas.amount && input.rightGas.amount >= rightGas.amount;
}
public ChemicalPair copy()
{
return new ChemicalPair(leftGas.copy(), rightGas.copy());
}
}
-112
View File
@@ -1,112 +0,0 @@
package mekanism.api;
import net.minecraft.util.StatCollector;
/**
* Simple color enum for adding colors to in-game GUI strings of text.
* @author AidanBrady
*
*/
public enum EnumColor
{
BLACK("\u00a70", "black", "Black", new int[] {0, 0, 0}, 0),
DARK_BLUE("\u00a71", "darkBlue", "Blue", new int[] {0, 0, 170}, 4),
DARK_GREEN("\u00a72", "darkGreen", "Green", new int[] {0, 170, 0}, 2),
DARK_AQUA("\u00a73", "darkAqua", "Cyan", new int[] {0, 170, 170}, 6),
DARK_RED("\u00a74", "darkRed", null, new int[] {170, 0, 0}, -1),
PURPLE("\u00a75", "purple", "Purple", new int[] {170, 0, 170}, 5),
ORANGE("\u00a76", "orange", "Orange", new int[] {255, 170, 0}, 14),
GREY("\u00a77", "grey", "LightGray", new int[] {170, 170, 170}, 7),
DARK_GREY("\u00a78", "darkGrey", "Gray", new int[] {85, 85, 85}, 8),
INDIGO("\u00a79", "indigo", "LightBlue", new int[] {85, 85, 255}, 12),
BRIGHT_GREEN("\u00a7a", "brightGreen", "Lime", new int[] {85, 255, 85}, 10),
AQUA("\u00a7b", "aqua", null, new int[] {85, 255, 255}, -1),
RED("\u00a7c", "red", "Red", new int[] {255, 0, 0}, 1),
PINK("\u00a7d", "pink", "Magenta", new int[] {255, 85, 255}, 13),
YELLOW("\u00a7e", "yellow", "Yellow", new int[] {255, 255, 85}, 11),
WHITE("\u00a7f", "white", "White", new int[] {255, 255, 255}, 15),
//Extras for dye-completeness
BROWN("\u00a76", "brown", "Brown", new int[] {150, 75, 0}, 3),
BRIGHT_PINK("\u00a7d", "brightPink", "Pink", new int[] {255, 192, 203}, 9);
public static EnumColor[] DYES = new EnumColor[] {BLACK, RED, DARK_GREEN, BROWN, DARK_BLUE, PURPLE, DARK_AQUA, GREY, DARK_GREY, BRIGHT_PINK, BRIGHT_GREEN, YELLOW, INDIGO, PINK, ORANGE, WHITE};
/** The color code that will be displayed */
public final String code;
public final int[] rgbCode;
public final int mcMeta;
/** A friendly name of the color. */
public String unlocalizedName;
public String dyeName;
private EnumColor(String s, String n, String dye, int[] rgb, int meta)
{
code = s;
unlocalizedName = n;
dyeName = dye;
rgbCode = rgb;
mcMeta = meta;
}
/**
* Gets the localized name of this color by translating the unlocalized name.
* @return localized name
*/
public String getLocalizedName()
{
return StatCollector.translateToLocal("color." + unlocalizedName);
}
public String getDyeName()
{
return StatCollector.translateToLocal("dye." + unlocalizedName);
}
public String getOreDictName()
{
return dyeName;
}
/**
* Gets the name of this color with it's color prefix code.
* @return the color's name and color prefix
*/
public String getName()
{
return code + getLocalizedName();
}
public String getDyedName()
{
return code + getDyeName();
}
/**
* Gets the 0-1 of this color's RGB value by dividing by 255 (used for OpenGL coloring).
* @param index - R:0, G:1, B:2
* @return the color value
*/
public float getColor(int index)
{
return (float)rgbCode[index]/255F;
}
/**
* Gets the value of this color mapped to MC in-game item colors present in dyes and wool.
* @return mc meta value
*/
public int getMetaValue()
{
return mcMeta;
}
@Override
public String toString()
{
return code;
}
}
@@ -1,27 +0,0 @@
package mekanism.api;
import net.minecraft.entity.player.EntityPlayer;
/**
* Implement this in your TileEntity class if your block can be modified by a Configurator.
* @author aidancbrady
*
*/
public interface IConfigurable
{
/**
* Called when a player shift-right clicks this block with a Configurator.
* @param player - the player who clicked the block
* @param side - the side the block was clicked on
* @return whether or not an action was performed
*/
public boolean onSneakRightClick(EntityPlayer player, int side);
/**
* Called when a player right clicks this block with a Configurator.
* @param player - the player who clicked the block
* @param side - the side the block was clicked on
* @return whether or not an action was performed
*/
public boolean onRightClick(EntityPlayer player, int side);
}
@@ -1,31 +0,0 @@
package mekanism.api;
import net.minecraft.nbt.NBTTagCompound;
/**
* Implement this in your TileEntity class if you wish for Mekanism filters to be able to store any of their
* information.
* @author aidancbrady
*
*/
public interface IFilterAccess
{
/**
* Collects the TileEntity's filter card data into the parameterized NBTTagCompound.
* @param nbtTags - the NBTTagCompound of the filter card ItemStack
* @return the NBTTagCompound that now contains the TileEntity's filter card data
*/
public NBTTagCompound getFilterData(NBTTagCompound nbtTags);
/**
* Retrieves the TileEntity's data contained in the filter card based on the given NBTTagCompopund.
* @param nbtTags - the NBTTagCompound of the filter card ItemStack
*/
public void setFilterData(NBTTagCompound nbtTags);
/**
* A String name of this TileEntity that will be displayed as the type of data on the filter card.
* @return the String name of this TileEntity
*/
public String getDataType();
}
@@ -1,11 +0,0 @@
package mekanism.api;
/**
* Implement this class in a TileEntity if you wish for it to be able to heat up a Salination Plant.
* @author aidancbrady
*
*/
public interface ISalinationSolar
{
public boolean seesSun();
}
-38
View File
@@ -1,38 +0,0 @@
package mekanism.api;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ItemInfo
{
public Item item;
public int meta;
public ItemInfo(Item i, int j)
{
item = i;
meta = j;
}
public static ItemInfo get(ItemStack stack)
{
return new ItemInfo(stack.getItem(), stack.getItemDamage());
}
@Override
public boolean equals(Object obj)
{
return obj instanceof BlockInfo &&
((ItemInfo)obj).item == item &&
((ItemInfo)obj).meta == meta;
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + item.getUnlocalizedName().hashCode();
code = 31 * code + meta;
return code;
}
}
@@ -1,71 +0,0 @@
package mekanism.api;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* Use this class's 'getItem()' method to retrieve ItemStacks from the 'Mekanism'
* class.
* @author AidanBrady
*
*/
public final class ItemRetriever
{
/** The 'Mekanism' class that items and blocks are retrieved from. */
private static Class Mekanism;
/**
* Attempts to retrieve an ItemStack of an item or block with the declared identifier.
*
* Mekanism identifiers follow an easy-to-remember pattern. All identifiers
* are identical to the String returned by 'getItemName().' None include spaces,
* and all start with a capital letter. The name that shows up in-game can be
* stripped down to identifier form by removing spaces and all non-alphabetic
* characters (,./'=-_). Below is an example:
*
* ItemStack enrichedAlloy = ItemRetriever.getItem("EnrichedAlloy");
*
* The same also works for blocks.
*
* ItemStack refinedObsidian = ItemRetriever.getItem("RefinedObsidian");
*
* Note that for items or blocks that have specific metadata you will need to create
* a new ItemStack with that specified value, as this will only return an ItemStack
* with the meta value '0.'
*
* Make sure you run this in or after FMLPostInitializationEvent runs, because most
* items are registered when FMLInitializationEvent runs. However, some items ARE
* registered later in order to hook into other mods. In a rare circumstance you may
* have to add "after:Mekanism" in the @Mod 'dependencies' annotation.
*
* @param identifier - a String to be searched in the 'Mekanism' class
* @return an ItemStack of the declared identifier, otherwise null.
*/
public static ItemStack getItem(String identifier)
{
try {
if(Mekanism == null)
{
Mekanism = Class.forName("mekanism.common.Mekanism");
}
Object ret = Mekanism.getField(identifier).get(null);
if(ret instanceof Item)
{
return new ItemStack((Item)ret, 1);
}
else if(ret instanceof Block)
{
return new ItemStack((Block)ret, 1);
}
else {
return null;
}
} catch(Exception e) {
System.err.println("Error retrieving item with identifier '" + identifier + "': " + e.getMessage());
return null;
}
}
}
@@ -1,45 +0,0 @@
package mekanism.api;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraftforge.oredict.OreDictionary;
public class MekanismAPI
{
//Add a BlockInfo value here if you don't want a certain block to be picked up by cardboard boxes
private static Set<BlockInfo> cardboardBoxIgnore = new HashSet<BlockInfo>();
public static boolean isBlockCompatible(Item item, int meta)
{
for(BlockInfo i : cardboardBoxIgnore)
{
if(i.block == Block.getBlockFromItem(item) && (i.meta == OreDictionary.WILDCARD_VALUE || i.meta == meta))
{
return false;
}
}
return true;
}
public static void addBoxBlacklist(Block block, int meta)
{
cardboardBoxIgnore.add(new BlockInfo(block, meta));
}
public static void removeBoxBlacklist(Block block, int meta)
{
cardboardBoxIgnore.remove(new BlockInfo(block, meta));
}
public static Set<BlockInfo> getBoxIgnore()
{
return cardboardBoxIgnore;
}
public static class BoxBlacklistEvent extends Event {}
}
@@ -1,50 +0,0 @@
package mekanism.api;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import net.minecraft.item.ItemStack;
public class PressurizedProducts
{
private ItemStack itemOutput;
private GasStack gasOutput;
public PressurizedProducts(ItemStack item, GasStack gas)
{
itemOutput = item;
gasOutput = gas;
}
public void fillTank(GasTank tank)
{
tank.receive(gasOutput, true);
}
public void addProducts(ItemStack[] inventory, int index)
{
if(inventory[index] == null)
{
inventory[index] = itemOutput.copy();
}
else if(inventory[index].isItemEqual(itemOutput))
{
inventory[index].stackSize += itemOutput.stackSize;
}
}
public ItemStack getItemOutput()
{
return itemOutput;
}
public GasStack getGasOutput()
{
return gasOutput;
}
public PressurizedProducts copy()
{
return new PressurizedProducts(itemOutput.copy(), gasOutput.copy());
}
}
@@ -1,139 +0,0 @@
package mekanism.api;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
/**
* An input of a gas, a fluid and an item for the pressurized reaction chamber
*/
public class PressurizedReactants
{
private ItemStack theSolid;
private FluidStack theFluid;
private GasStack theGas;
public PressurizedReactants(ItemStack solid, FluidStack fluid, GasStack gas)
{
theSolid = solid;
theFluid = fluid;
theGas = gas;
}
/**
* If this is a valid PressurizedReactants
*/
public boolean isValid()
{
return theSolid != null && theFluid != null && theGas != null;
}
/**
* Draws the needed amount of gas from each tank.
* @param item - ItemStack to draw from
* @param fluidTank - fluid tank to draw from
* @param gasTank - gas tank to draw from
*/
public void use(ItemStack item, FluidTank fluidTank, GasTank gasTank)
{
if(meets(new PressurizedReactants(item, fluidTank.getFluid(), gasTank.getGas())))
{
item.stackSize -= theSolid.stackSize;
fluidTank.drain(theFluid.amount, true);
gasTank.draw(theGas.amount, true);
}
}
/**
* Whether or not this PressurizedReactants's ItemStack entry's item type is equal to the item type of the given item.
* @param stack - stack to check
* @return if the stack's item type is contained in this PressurizedReactants
*/
public boolean containsType(ItemStack stack)
{
if(stack == null || stack.stackSize == 0)
{
return false;
}
return StackUtils.equalsWildcard(stack, theSolid);
}
/**
* Whether or not this PressurizedReactants's FluidStack entry's fluid type is equal to the fluid type of the given fluid.
* @param stack - stack to check
* @return if the stack's fluid type is contained in this PressurizedReactants
*/
public boolean containsType(FluidStack stack)
{
if(stack == null || stack.amount == 0)
{
return false;
}
return stack.isFluidEqual(theFluid);
}
/**
* Whether or not this PressurizedReactants's GasStack entry's gas type is equal to the gas type of the given gas.
* @param stack - stack to check
* @return if the stack's gas type is contained in this PressurizedReactants
*/
public boolean containsType(GasStack stack)
{
if(stack == null || stack.amount == 0)
{
return false;
}
return stack.isGasEqual(theGas);
}
public boolean meetsInput(ItemStack itemStack, FluidStack fluidStack, GasStack gasStack)
{
return meets(new PressurizedReactants(itemStack, fluidStack, gasStack));
}
/**
* Actual implementation of meetsInput(), performs the checks.
* @param input - input to check
* @return if the input meets this input's requirements
*/
private boolean meets(PressurizedReactants input)
{
if(input == null || !input.isValid())
{
return false;
}
if(!(StackUtils.equalsWildcard(input.theSolid, theSolid) && input.theFluid.isFluidEqual(theFluid) && input.theGas.isGasEqual(theGas)))
{
return false;
}
return input.theSolid.stackSize >= theSolid.stackSize && input.theFluid.amount >= theFluid.amount && input.theGas.amount >= theGas.amount;
}
public PressurizedReactants copy()
{
return new PressurizedReactants(theSolid.copy(), theFluid.copy(), theGas.copy());
}
public ItemStack getSolid()
{
return theSolid;
}
public FluidStack getFluid()
{
return theFluid;
}
public GasStack getGas()
{
return theGas;
}
}
@@ -1,25 +0,0 @@
package mekanism.api;
public class PressurizedRecipe
{
public PressurizedReactants reactants;
public double extraEnergy;
public PressurizedProducts products;
public int ticks;
public PressurizedRecipe(PressurizedReactants pressurizedReactants, double energy, PressurizedProducts pressurizedProducts, int duration)
{
reactants = pressurizedReactants;
extraEnergy = energy;
products = pressurizedProducts;
ticks = duration;
}
public PressurizedRecipe copy()
{
return new PressurizedRecipe(reactants.copy(), extraEnergy, products.copy(), ticks);
}
}
@@ -1,258 +0,0 @@
package mekanism.api;
import java.lang.reflect.Method;
import mekanism.api.gas.GasStack;
import mekanism.api.infuse.InfusionInput;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
/**
* Use this handy class to add recipes to Mekanism machinery.
* @author AidanBrady
*
*/
public final class RecipeHelper
{
/**
* Add an Enrichment Chamber recipe.
* @param input - input ItemStack
* @param output - output ItemStack
*/
public static void addEnrichmentChamberRecipe(ItemStack input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addEnrichmentChamberRecipe", ItemStack.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add an Osmium Compressor recipe.
* @param input - input ItemStack
* @param output - output ItemStack
*/
public static void addOsmiumCompressorRecipe(ItemStack input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addOsmiumCompressorRecipe", ItemStack.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Combiner recipe.
* @param input - input ItemStack
* @param output - output ItemStack
*/
public static void addCombinerRecipe(ItemStack input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addCombinerRecipe", ItemStack.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Crusher recipe.
* @param input - input ItemStack
* @param output - output ItemStack
*/
public static void addCrusherRecipe(ItemStack input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addCrusherRecipe", ItemStack.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Purification Chamber recipe.
* @param input - input ItemStack
* @param output - output ItemStack
*/
public static void addPurificationChamberRecipe(ItemStack input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addPurificationChamberRecipe", ItemStack.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Chemical Oxidizer recipe.
* @param input - input ItemStack
* @param output - output GasStack
*/
public static void addChemicalOxidizerRecipe(ItemStack input, GasStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addChemicalOxidizerRecipe", ItemStack.class, GasStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Chemical Infuser recipe.
* @param input - input ChemicalInput
* @param output - output GasStack
*/
public static void addChemicalInfuserRecipe(ChemicalPair input, GasStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addChemicalInfuserRecipe", ChemicalPair.class, GasStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Precision Sawmill recipe.
* @param input - input ItemStack
* @param output - output ChanceOutput
*/
public static void addPrecisionSawmillRecipe(ItemStack input, ChanceOutput output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addPrecisionSawmillRecipe", ItemStack.class, ChanceOutput.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Chemical Injection Chamber recipe.
* @param input - input AdvancedInput
* @param output - output ItemStack
*/
public static void addChemicalInjectionChamberRecipe(AdvancedInput input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addChemicalInjectionChamberRecipe", AdvancedInput.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add an Electrolytic Separator recipe.
* @param input - input FluidStack
* @param output - output ChemicalPair
*/
public static void addElectrolyticSeparatorRecipe(FluidStack input, ChemicalPair output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addElectrolyticSeparatorRecipe", FluidStack.class, ChemicalPair.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Chemical Dissolution Chamber recipe.
* @param input - input ItemStack
* @param output - output GasStack
*/
public static void addChemicalDissolutionChamberRecipe(ItemStack input, GasStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addChemicalDissolutionChamberRecipe", ItemStack.class, GasStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Chemical Washer recipe.
* @param input - input GasStack
* @param output - output GasStack
*/
public static void addChemicalWasherRecipe(GasStack input, GasStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addChemicalWasherRecipe", GasStack.class, GasStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Chemical Crystallizer recipe.
* @param input - input GasStack
* @param output - output ItemStack
*/
public static void addChemicalCrystallizerRecipe(GasStack input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addChemicalCrystallizerRecipe", GasStack.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Metallurgic Infuser recipe.
* @param input - input Infusion
* @param output - output ItemStack
*/
public static void addMetallurgicInfuserRecipe(InfusionInput input, ItemStack output)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addMetallurgicInfuserRecipe", InfusionInput.class, ItemStack.class);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
/**
* Add a Pressurized Reaction Chamber recipe.
* @param input - input PressurizedReactants
* @param output - output PressurizedProducts
* @param extraEnergy - extra energy needed by the recipe
* @param ticks - amount of ticks it takes for this recipe to complete
*/
public static void addPRCRecipe(PressurizedReactants input, PressurizedProducts output, double extraEnergy, int ticks)
{
try {
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
Method m = recipeClass.getMethod("addPRCRecipe", PressurizedReactants.class, PressurizedProducts.class, Double.TYPE, Integer.TYPE);
m.invoke(null, input, output);
} catch(Exception e) {
System.err.println("Error while adding recipe: " + e.getMessage());
}
}
}
-149
View File
@@ -1,149 +0,0 @@
package mekanism.api;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public final class StackUtils
{
public static List<ItemStack> split(ItemStack stack)
{
if(stack == null || stack.stackSize == 0)
{
return null;
}
List<ItemStack> ret = new ArrayList<ItemStack>();
if(stack.stackSize == 1)
{
ret.add(stack);
return ret;
}
int remain = stack.stackSize % 2;
int split = (int)((float)(stack.stackSize)/2F);
ret.add(size(stack, split+remain));
ret.add(size(stack, split));
return ret;
}
public static Item getItem(ItemStack stack)
{
if(stack == null)
{
return null;
}
return stack.getItem();
}
public static boolean diffIgnoreNull(ItemStack stack1, ItemStack stack2)
{
if(stack1 == null || stack2 == null)
{
return false;
}
return stack1.getItem() != stack2.getItem() || stack1.getItemDamage() != stack2.getItemDamage();
}
public static boolean equalsWildcard(ItemStack wild, ItemStack check)
{
return wild.getItem() == check.getItem() && (wild.getItemDamage() == OreDictionary.WILDCARD_VALUE || wild.getItemDamage() == check.getItemDamage());
}
public static List<ItemStack> even(ItemStack stack1, ItemStack stack2)
{
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
if(getSize(stack1) == getSize(stack2) || Math.abs(getSize(stack1)-getSize(stack2)) == 1)
{
ret.add(stack1);
ret.add(stack2);
return ret;
}
if(getSize(stack1) > getSize(stack2))
{
int diff = getSize(stack1)-getSize(stack2);
List<ItemStack> split = split(size(stack1, diff));
ret.add(subtract(stack1, split.get(0)));
ret.add(add(stack2, split.get(0)));
}
else if(getSize(stack2) > getSize(stack1))
{
int diff = getSize(stack2)-getSize(stack1);
List<ItemStack> split = split(size(stack2, diff));
ret.add(subtract(stack2, split.get(0)));
ret.add(add(stack1, split.get(0)));
}
return ret;
}
public static ItemStack add(ItemStack stack1, ItemStack stack2)
{
if(stack1 == null)
{
return stack2;
}
else if(stack2 == null)
{
return stack1;
}
return size(stack1, getSize(stack1)+getSize(stack2));
}
public static ItemStack subtract(ItemStack stack1, ItemStack stack2)
{
if(stack1 == null)
{
return null;
}
else if(stack2 == null)
{
return stack1;
}
return size(stack1, getSize(stack1)-getSize(stack2));
}
public static ItemStack size(ItemStack stack, int size)
{
if(size <= 0 || stack == null)
{
return null;
}
ItemStack ret = stack.copy();
ret.stackSize = size;
return ret;
}
public static ItemStack copy(ItemStack stack)
{
if(stack == null)
{
return null;
}
return stack.copy();
}
public static int getSize(ItemStack stack)
{
return stack != null ? stack.stackSize : 0;
}
}
-42
View File
@@ -1,42 +0,0 @@
package mekanism.api;
import net.minecraft.creativetab.CreativeTabs;
/**
* Class used to indirectly reference the Mekanism creative tab.
* @author AidanBrady
*
*/
public final class TabProxy
{
/** The 'Mekanism' class where the tab instance is stored. */
public static Class Mekanism;
/**
* Attempts to get the Mekanism creative tab instance from the 'Mekanism' class. Will return
* the tab if the mod is loaded, but otherwise will return the defined 'preferred' creative tab. This way
* you don't need to worry about NPEs!
* @return Mekanism creative tab if can, otherwise preferred tab
*/
public static CreativeTabs tabMekanism(CreativeTabs preferred)
{
try {
if(Mekanism == null)
{
Mekanism = Class.forName("mekanism.common.Mekanism");
}
Object ret = Mekanism.getField("tabMekanism").get(null);
if(ret instanceof CreativeTabs)
{
return (CreativeTabs)ret;
}
return preferred;
} catch(Exception e) {
System.err.println("Error retrieving Mekanism creative tab.");
return preferred;
}
}
}
@@ -1,60 +0,0 @@
package mekanism.api.energy;
import net.minecraft.item.ItemStack;
public class EnergizedItemManager
{
/**
* Discharges an IEnergizedItem with the defined amount of energy.
* @param itemStack - ItemStack to discharge
* @param amount - amount of energy to discharge from the item, usually the total amount of energy needed in a TileEntity
* @return amount of energy discharged
*/
public static double discharge(ItemStack itemStack, double amount)
{
if(itemStack != null)
{
if(itemStack.getItem() instanceof IEnergizedItem)
{
IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem();
if(energizedItem.canSend(itemStack))
{
double energyToUse = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getEnergy(itemStack), amount));
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) - energyToUse);
return energyToUse;
}
}
}
return 0;
}
/**
* Charges an IEnergizedItem with the defined amount of energy.
* @param itemStack - ItemStack to charge
* @param amount - amount of energy to charge the item with, usually the total amount of energy stored in a TileEntity
* @return amount of energy charged
*/
public static double charge(ItemStack itemStack, double amount)
{
if(itemStack != null)
{
if(itemStack.getItem() instanceof IEnergizedItem)
{
IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem();
if(energizedItem.canReceive(itemStack))
{
double energyToSend = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getMaxEnergy(itemStack) - energizedItem.getEnergy(itemStack), amount));
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) + energyToSend);
return energyToSend;
}
}
}
return 0;
}
}
@@ -1,18 +0,0 @@
package mekanism.api.energy;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Implement this if your TileEntity is capable of outputting energy to cables, overriding Mekanism's default implementation.
* @author AidanBrady
*
*/
public interface ICableOutputter
{
/**
* Whether or not this block can output to a cable on a specific side.
* @param side - side to check
* @return if the block can output
*/
public boolean canOutputTo(ForgeDirection side);
}
@@ -1,59 +0,0 @@
package mekanism.api.energy;
import net.minecraft.item.ItemStack;
/**
* Implement this in an item's class if it should be able to store electricity.
* @author aidancbrady
*
*/
public interface IEnergizedItem
{
/**
* Gets and returns the amount of energy stored in this item.
* @param itemStack - the ItemStack to check
* @return energy stored
*/
public double getEnergy(ItemStack itemStack);
/**
* Sets this item's stored energy value to a new amount.
* @param itemStack - the ItemStack who's energy value is to be change
* @param amount - new amount of energy
*/
public void setEnergy(ItemStack itemStack, double amount);
/**
* Gets and returns this item's maximum amount of energy that can be stored.
* @param itemStack - the ItemStack to check
* @return maximum energy
*/
public double getMaxEnergy(ItemStack itemStack);
/**
* Gets and returns how much energy this item can transfer to and from charging slots.
* @param itemStack - the ItemStack to check
* @return transfer amount
*/
public double getMaxTransfer(ItemStack itemStack);
/**
* Gets and returns whether or not this item can receive energy from a charging slot.
* @param itemStack - the ItemStack to check
* @return if the item can receive energy
*/
public boolean canReceive(ItemStack itemStack);
/**
* Gets and returns whether or not this item can send energy to a charging slot.
* @param itemStack - the ItemStack to check
* @return if the item can send energy
*/
public boolean canSend(ItemStack itemStack);
/**
* Returns whether or not this item contains metadata-specific subtypes instead of using metadata for damage display.
* @return if the item contains metadata-specific subtypes
*/
public boolean isMetadataSpecific(ItemStack itemStack);
}
@@ -1,25 +0,0 @@
package mekanism.api.energy;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Implement this if your TileEntity can accept energy at a floating-point double value from Universal Cables.
* @author AidanBrady
*
*/
public interface IStrictEnergyAcceptor extends IStrictEnergyStorage
{
/**
* Transfer a certain amount of energy to this acceptor.
* @param amount - amount to transfer
* @return energy used
*/
public double transferEnergyToAcceptor(ForgeDirection side, double amount);
/**
* Whether or not this tile entity accepts energy from a certain side.
* @param side - side to check
* @return if tile entity accepts energy
*/
public boolean canReceiveEnergy(ForgeDirection side);
}
@@ -1,27 +0,0 @@
package mekanism.api.energy;
/**
* Mekanism-specific energy storage for TileEntities, already implemented in IStrictEnergyAcceptor.
* @author aidancbrady
*
*/
public interface IStrictEnergyStorage
{
/**
* Gets the amount of energy this TileEntity is currently storing.
* @return stored energy
*/
public double getEnergy();
/**
* Sets the amount of stored energy of this TileEntity to a new amount.
* @param energy - new energy value
*/
public void setEnergy(double energy);
/**
* Gets the maximum amount of energy this TileEntity can store.
* @return maximum energy
*/
public double getMaxEnergy();
}
@@ -1,21 +0,0 @@
package mekanism.api.infuse;
/**
* InfuseObject - an object associated with an ItemStack that can modify a Metallurgic Infuser's internal infuse.
* @author AidanBrady
*
*/
public class InfuseObject
{
/** The type of infuse this item stores */
public InfuseType type;
/** How much infuse this item stores */
public int stored;
public InfuseObject(InfuseType infusion, int i)
{
type = infusion;
stored = i;
}
}
@@ -1,113 +0,0 @@
package mekanism.api.infuse;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.item.ItemStack;
/**
* Use this class to add a new object that registers as an infuse object.
* @author AidanBrady
*
*/
public class InfuseRegistry
{
/** The (private) map of ItemStacks and their related InfuseObjects. */
private static Map<ItemStack, InfuseObject> infuseObjects = new HashMap<ItemStack, InfuseObject>();
/** The (private) map of infuse names and their corresponding InfuseTypes. */
private static Map<String, InfuseType> infuseTypes = new HashMap<String, InfuseType>();
/**
* Registers an InfuseType into the registry. Call this in PreInit!
* @param infuse
*/
public static void registerInfuseType(InfuseType infuse)
{
if(infuseTypes.containsKey(infuse.name))
{
return;
}
infuseTypes.put(infuse.name, infuse);
}
/**
* Gets an InfuseType from it's name, or null if it doesn't exist.
* @param name - the name of the InfuseType to get
* @return the name's corresponding InfuseType
*/
public static InfuseType get(String name)
{
if(name.equals("null"))
{
return null;
}
return infuseTypes.get(name);
}
/**
* Whether or not the registry contains a correspondent InfuseType to a name.
* @param name - the name to check
* @return if the name has a coorespondent InfuseType
*/
public static boolean contains(String name)
{
return get(name) != null;
}
/**
* Registers a block or item that serves as an infuse object. An infuse object will store a certain type and amount of infuse,
* and will deliver this amount to the Metallurgic Infuser's buffer of infuse. The item's stack size will be decremented when
* it is placed in the Metallurgic Infuser's infuse slot, and the machine can accept the type and amount of infuse stored in the
* object.
* @param itemStack - stack the infuse object is linked to -- stack size is ignored
* @param infuseObject - the infuse object with the type and amount data
*/
public static void registerInfuseObject(ItemStack itemStack, InfuseObject infuseObject)
{
if(getObject(itemStack) != null)
{
return;
}
infuseObjects.put(itemStack, infuseObject);
}
/**
* Gets the InfuseObject data from an ItemStack.
* @param itemStack - the ItemStack to check
* @return the ItemStack's InfuseObject
*/
public static InfuseObject getObject(ItemStack itemStack)
{
for(Map.Entry<ItemStack, InfuseObject> obj : infuseObjects.entrySet())
{
if(itemStack.isItemEqual(obj.getKey()))
{
return obj.getValue();
}
}
return null;
}
/**
* Gets the private map for InfuseObjects.
* @return private InfuseObject map
*/
public static final Map<ItemStack, InfuseObject> getObjectMap()
{
return infuseObjects;
}
/**
* Gets the private map for InfuseTypes.
* @return private InfuseType map
*/
public static final Map<String, InfuseType> getInfuseMap()
{
return infuseTypes;
}
}
@@ -1,47 +0,0 @@
package mekanism.api.infuse;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
/**
* The types of infuse currently available in Mekanism.
* @author AidanBrady
*
*/
public final class InfuseType
{
/** The name of this infusion */
public String name;
/** The location of this infuse's GUI texture */
public ResourceLocation texture;
/** The infuse's GUI texture X offset. */
public int texX;
/** The infuse's GUI texture Y offset. */
public int texY;
/** The unlocalized name of this type. */
public String unlocalizedName;
public InfuseType(String s, ResourceLocation location, int x, int y)
{
name = s;
texture = location;
texX = x;
texY = y;
}
public InfuseType setUnlocalizedName(String name)
{
unlocalizedName = name;
return this;
}
public String getLocalizedName()
{
return StatCollector.translateToLocal(unlocalizedName);
}
}
@@ -1,32 +0,0 @@
package mekanism.api.infuse;
import net.minecraft.item.ItemStack;
/**
* An infusion input, containing the type of and amount of infuse the operation requires, as well as the input ItemStack.
* @author AidanBrady
*
*/
public class InfusionInput
{
/** The type of this infusion */
public InfuseType infusionType;
/** How much infuse it takes to perform this operation */
public int infuseAmount;
/** The input ItemStack */
public ItemStack inputStack;
public InfusionInput(InfuseType infusiontype, int required, ItemStack itemstack)
{
infusionType = infusiontype;
infuseAmount = required;
inputStack = itemstack;
}
public static InfusionInput getInfusion(InfuseType type, int stored, ItemStack itemstack)
{
return new InfusionInput(type, stored, itemstack);
}
}
@@ -1,38 +0,0 @@
package mekanism.api.infuse;
import net.minecraft.item.ItemStack;
/**
* An infusion output, containing a reference to it's input as well as the output resource.
* @author AidanBrady
*
*/
public class InfusionOutput
{
/** The input infusion */
public InfusionInput infusionInput;
/** The output resource of this infusion */
public ItemStack resource;
public InfusionOutput(InfusionInput input, ItemStack itemstack)
{
infusionInput = input;
resource = itemstack;
}
public static InfusionOutput getInfusion(InfusionInput input, ItemStack itemstack)
{
return new InfusionOutput(input, itemstack);
}
public int getInfuseRequired()
{
return infusionInput.infuseAmount;
}
public InfusionOutput copy()
{
return new InfusionOutput(infusionInput, resource);
}
}