Advertisement
Guest User

Untitled

a guest
Dec 27th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. package com.nitrodev.warehousestorage.recipes.custom;
  2.  
  3.  
  4. import com.nitrodev.warehousestorage.items.ModItems;
  5. import net.minecraft.init.Blocks;
  6. import net.minecraft.inventory.InventoryCrafting;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.item.crafting.IRecipe;
  10. import net.minecraft.world.World;
  11.  
  12. import java.util.Random;
  13.  
  14. public class PlankRecipe implements IRecipe {
  15.  
  16.     @Override
  17.     public boolean matches(InventoryCrafting inventoryCrafting, World world) {
  18.         ItemStack saw = null;
  19.         ItemStack slab = null;
  20.  
  21.         for (int i = 0; i < inventoryCrafting.getSizeInventory(); ++i) {
  22.             ItemStack stackInSlot = inventoryCrafting.getStackInSlot(i);
  23.  
  24.             if (stackInSlot != null) {
  25.                 if (stackInSlot.getItem() == ModItems.itemSaw) {
  26.                     if (saw != null) return false;
  27.                     saw = stackInSlot;
  28.                 }
  29.                 if (stackInSlot.getItem() == Item.getItemFromBlock(Blocks.wooden_slab)) {
  30.                     if (slab != null) return false;
  31.                     slab = stackInSlot;
  32.                 }
  33.  
  34.             }
  35.  
  36.         }
  37.         return saw != null && slab != null;
  38.     }
  39.  
  40.     @Override
  41.     public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {
  42.         return getRecipeOutput().copy();
  43.     }
  44.  
  45.     @Override
  46.     public int getRecipeSize() {
  47.         return 4;
  48.     }
  49.  
  50.     @Override
  51.     public ItemStack getRecipeOutput() {
  52.         return new ItemStack(ModItems.itemPlank);
  53.     }
  54.  
  55.     @Override
  56.     public ItemStack[] getRemainingItems(InventoryCrafting inv) {
  57.         ItemStack[] result = new ItemStack[4];
  58.         for (int i = 0; i < result.length; ++i) {
  59.             ItemStack stack = inv.getStackInSlot(i);
  60.             if (stack != null && stack.getItem() == ModItems.itemSaw) {
  61.                 result[i] = stack.copy();
  62.  
  63.                 if (result[i].attemptDamageItem(1, new Random())) {
  64.                     if (--result[i].stackSize <= 0) {
  65.                         result[i] = null;
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.  
  71.         return result;
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement