Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src.ic2.api;
- /**
- * @file
- * @author Player
- * @version 1.0
- *
- * @section DESCRIPTION
- *
- * The Ic2Recipes api class provides access to the Compressor, Extractor and Macerator recipes.
- *
- * The recipes are only valid after IC2 has been loaded.
- * The recipes are both meta and value sensitive, you can specify n:m processes, e.g. compress 3
- * wooden planks into 2 sticks.
- */
- import java.util.AbstractMap;
- import java.util.List;
- import java.util.Map;
- import net.minecraft.src.Block;
- import net.minecraft.src.Item;
- import net.minecraft.src.ItemStack;
- public final class Ic2Recipes {
- /**
- * Retrieve the registered Compressor recipes, key = input, value = output
- */
- public static List<Map.Entry<ItemStack, ItemStack> > getCompressorRecipes() {
- try {
- return (List<Map.Entry<ItemStack, ItemStack> >) Class.forName("net.minecraft.src.ic2.common.TileEntityCompressor").getField("recipes").get(null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * Add a Compressor recipe
- */
- public static void addCompressorRecipe(ItemStack input, ItemStack output) {
- getCompressorRecipes().add(new AbstractMap.SimpleEntry<ItemStack, ItemStack>(input, output));
- }
- /**
- * Get the Compressor output for a specific ItemStack
- *
- * @param input Input ItemStack
- * @param adjustInput remove the process requirements from input
- * @return resulting output ItemStack for the specified input ItemStack, independent ItemStack instance
- */
- public static ItemStack getCompressorOutputFor(ItemStack input, boolean adjustInput) {
- return getOutputFor(input, adjustInput, getCompressorRecipes());
- }
- /**
- * Retrieve the registered Extractor recipes, key = input, value = output
- */
- public static List<Map.Entry<ItemStack, ItemStack> > getExtractorRecipes() {
- try {
- return (List<Map.Entry<ItemStack, ItemStack> >) Class.forName("net.minecraft.src.ic2.common.TileEntityExtractor").getField("recipes").get(null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * Add a Extractor recipe
- */
- public static void addExtractorRecipe(ItemStack input, ItemStack output) {
- getExtractorRecipes().add(new AbstractMap.SimpleEntry<ItemStack, ItemStack>(input, output));
- }
- /**
- * Get the Extractor output for a specific ItemStack
- *
- * @param input Input ItemStack
- * @param adjustInput remove the process requirements from input
- * @return resulting output ItemStack for the specified input ItemStack, independent ItemStack instance
- */
- public static ItemStack getExtractorOutputFor(ItemStack input, boolean adjustInput) {
- return getOutputFor(input, adjustInput, getExtractorRecipes());
- }
- /**
- * Retrieve the registered Macerator recipes, key = input, value = output
- */
- public static List<Map.Entry<ItemStack, ItemStack> > getMaceratorRecipes() {
- try {
- return (List<Map.Entry<ItemStack, ItemStack> >) Class.forName("net.minecraft.src.ic2.common.TileEntityMacerator").getField("recipes").get(null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * Add a Macerator recipe
- */
- public static void addMaceratorRecipe(ItemStack input, ItemStack output) {
- getMaceratorRecipes().add(new AbstractMap.SimpleEntry<ItemStack, ItemStack>(input, output));
- }
- /**
- * Get the Macerator output for a specific ItemStack
- *
- * @param input Input ItemStack
- * @param adjustInput remove the process requirements from input
- * @return resulting output ItemStack for the specified input ItemStack, independent ItemStack instance
- */
- public static ItemStack getMaceratorOutputFor(ItemStack input, boolean adjustInput) {
- return getOutputFor(input, adjustInput, getMaceratorRecipes());
- }
- private static ItemStack getOutputFor(ItemStack input, boolean adjustInput, List<Map.Entry<ItemStack, ItemStack> > recipeList) {
- for (Map.Entry<ItemStack, ItemStack> entry: recipeList) {
- if (entry.getKey().isItemEqual(input) && input.stackSize >= entry.getKey().stackSize) {
- if (adjustInput) input.stackSize -= entry.getKey().stackSize;
- return entry.getValue().copy();
- }
- }
- return null;
- }
- /**
- * Retrieve the registered Recycler blacklist, key = blacklisted item
- */
- public static List<ItemStack> getRecyclerBlacklist() {
- try {
- return (List<ItemStack>) Class.forName("net.minecraft.src.ic2.common.TileEntityRecycler").getField("blacklist").get(null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- /**
- * Add a blacklisted item to recycler
- */
- public static void addRecyclerBlacklistItem(ItemStack newBlacklistedItem) {
- getRecyclerBlacklist().add(newBlacklistedItem);
- }
- public static void addRecyclerBlacklistItem(Item newBlacklistedItem) {
- addRecyclerBlacklistItem(new ItemStack(newBlacklistedItem));
- }
- public static void addRecyclerBlacklistItem(Block newBlacklistedBlock) {
- addRecyclerBlacklistItem(new ItemStack(newBlacklistedBlock));
- }
- /**
- * Test to see if item is blacklisted in the recycler
- * Quantity does not matter in isItemEqual()
- *
- * @param input testItem ItemStack
- * @return true if item is blacklisted
- */
- public static boolean isRecyclerInputBlacklisted(ItemStack itemStack) {
- for (ItemStack blackItem: getRecyclerBlacklist()) {
- if (itemStack.isItemEqual(blackItem)) return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement