SHARE
TWEET

ChickenFurnaceRecipes.java

FlowArg Sep 24th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.flowarg.gunsofchickens.blocks.machines.chickenfurnace;
  2.  
  3. import com.google.common.collect.HashBasedTable;
  4. import com.google.common.collect.Maps;
  5. import com.google.common.collect.Table;
  6. import fr.flowarg.gunsofchickens.init.BlockInit;
  7. import fr.flowarg.gunsofchickens.init.ItemInit;
  8. import fr.flowarg.gunsofchickens.utils.util.UtilObjects;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12.  
  13. import java.util.Map;
  14.  
  15. import static java.util.Map.Entry;
  16.  
  17. public class ChickenFurnaceRecipes
  18. {
  19.     private static final ChickenFurnaceRecipes INSTANCE = new ChickenFurnaceRecipes();
  20.     private final Table<ItemStack, ItemStack, ItemStack> smeltingList = HashBasedTable.<ItemStack, ItemStack, ItemStack>create();
  21.     private final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();
  22.  
  23.     private ItemStack chicken_ingot = this.getItemStack(ItemInit.chicken_diamond);
  24.     private ItemStack chicken_diamond = this.getItemStack(ItemInit.chicken_diamond);
  25.     private ItemStack ultimate_ingot = this.getItemStack(ItemInit.ultimate_ingot);
  26.     private ItemStack chicken_block = this.getItemStack(BlockInit.chicken_block);
  27.     private ItemStack chicken_diamond_block = this.getItemStack(BlockInit.chicken_diamond_block);
  28.     private ItemStack ultimate_block = this.getItemStack(BlockInit.ultimate_block);
  29.  
  30.     public static ChickenFurnaceRecipes getInstance()
  31.     {
  32.         return INSTANCE;
  33.     }
  34.  
  35.     public ChickenFurnaceRecipes()
  36.     {
  37.         addSmeltingRecipe(chicken_ingot, chicken_diamond, ultimate_ingot, 99999f);
  38.         addSmeltingRecipe(chicken_diamond, chicken_ingot, ultimate_ingot, 99999f);
  39.         addSmeltingRecipe(chicken_block, chicken_diamond_block, ultimate_block, 99999f);
  40.         addSmeltingRecipe(chicken_diamond_block, chicken_block, ultimate_block, 99999f);
  41.     }
  42.  
  43.     private ItemStack getItemStack(Item item)
  44.     {
  45.         return UtilObjects.getInstance().getItemStackFromItem(item);
  46.     }
  47.  
  48.     private ItemStack getItemStack(Block block)
  49.     {
  50.         return UtilObjects.getInstance().getItemStackFromBlock(block);
  51.     }
  52.  
  53.     public void addSmeltingRecipe(ItemStack input1, ItemStack input2, ItemStack result, float experience)
  54.     {
  55.         if (getSmeltingResult(input1, input2) != ItemStack.EMPTY) return;
  56.         this.smeltingList.put(input1, input2, result);
  57.         this.experienceList.put(result, Float.valueOf(experience));
  58.     }
  59.  
  60.     public ItemStack getSmeltingResult(ItemStack input1, ItemStack input2)
  61.     {
  62.         for (Entry<ItemStack, Map<ItemStack, ItemStack>> entry : this.smeltingList.columnMap().entrySet())
  63.         {
  64.             if (this.compareItemStacks(input1, (ItemStack) entry.getKey()))
  65.             {
  66.                 for (Entry<ItemStack, ItemStack> ent : entry.getValue().entrySet())
  67.                 {
  68.                     if (this.compareItemStacks(input2, (ItemStack)entry.getKey()))
  69.                     {
  70.                         return (ItemStack)ent.getValue();
  71.                     }
  72.                 }
  73.             }
  74.         }
  75.         return ItemStack.EMPTY;
  76.     }
  77.  
  78.     private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
  79.     {
  80.         return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
  81.     }
  82.  
  83.     public Table<ItemStack, ItemStack, ItemStack> getDualSmeltingList()
  84.     {
  85.         return this.smeltingList;
  86.     }
  87.  
  88.     public float getSmeltingExperience(ItemStack stack)
  89.     {
  90.         for (Entry<ItemStack, Float> entry : this.experienceList.entrySet())
  91.         {
  92.             if (this.compareItemStacks(stack, (ItemStack)entry.getKey()))
  93.             {
  94.                 return ((Float)entry.getValue()).floatValue();
  95.             }
  96.         }
  97.         return 0.0f;
  98.     }
  99. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top