Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gamebuster19901.supernatural.crafting;
- import java.util.ArrayList;
- import java.util.List;
- import javax.annotation.Nullable;
- import net.minecraft.inventory.InventoryCrafting;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.crafting.IRecipe;
- import net.minecraft.world.World;
- public class RepairRecipe implements IRecipe{
- protected final Item itemToRepair;//the item type that will be repaired
- protected final Item[] repairMaterial;//the materials that will repair the item
- private ItemStack output;
- public RepairRecipe(Item itemToRepair, Item repairMaterial){
- this.itemToRepair = itemToRepair;
- this.repairMaterial = new Item[]{repairMaterial};
- }
- public RepairRecipe(Item itemToRepair, ItemStack repairMaterial){
- this.itemToRepair = itemToRepair;
- this.repairMaterial = new Item[]{repairMaterial.getItem()};
- }
- public RepairRecipe(Item itemToRepair, List repairMaterial){
- this.itemToRepair = itemToRepair;
- this.repairMaterial = new Item[repairMaterial.size()];
- for (int j = 0; j < repairMaterial.size(); j++){
- if (repairMaterial.get(j) instanceof Item){
- this.repairMaterial[j] = (Item) repairMaterial.get(j);
- }
- else if (repairMaterial.get(j) instanceof ItemStack){
- this.repairMaterial[j] = ((ItemStack) repairMaterial.get(j)).getItem();
- }
- else{
- throw new IllegalArgumentException(repairMaterial.get(j).getClass().getName() + " is not an item or itemstack (" + j + ")");
- }
- }
- }
- @Override
- public boolean matches(InventoryCrafting inv, World worldIn) {
- List<ItemStack> list = new ArrayList<ItemStack>();
- int amt = 0;
- int amtItemsToRepairFound = 0;
- int amtrepairable = 0;
- int durability;
- ItemStack repairedItem = null;
- for (int i = 0; i < inv.getSizeInventory(); ++i){
- ItemStack itemstack = inv.getStackInSlot(i);
- if (itemstack != null){
- list.add(itemstack);
- for (Item item : repairMaterial){
- if (itemstack.getItem().equals(item) && !itemstack.getItem().equals(itemToRepair)){
- amt += itemstack.stackSize;
- System.out.println(itemstack.stackSize);
- }
- }
- if (itemstack.getItem().equals(itemToRepair)){
- repairedItem = itemstack;
- durability = itemstack.getItemDamage();
- amtItemsToRepairFound++;
- if (amtItemsToRepairFound != 1){
- return false;
- }
- }
- }
- }
- if (repairedItem == null){
- return false;
- }
- if (repairedItem.getItemDamage() - amt >= 0 && amt > 0){
- this.output = new ItemStack(itemToRepair, 1, repairedItem.getItemDamage() - amt);
- return true;
- }
- return false;
- }
- @Override
- public ItemStack getCraftingResult(InventoryCrafting inv){
- System.out.println("CraftingResult");
- List<ItemStack> list = new ArrayList<ItemStack>();
- int amt = 0;//how many repair items are in the crafting grid
- int amtrepairable = 0;//how many repairable items are in the grid
- int durability;//current durability of the item to repair
- ItemStack repairedItem = null;
- for (int i = 0; i < inv.getSizeInventory(); ++i){//loop slots in crafting inventory
- ItemStack itemstack = inv.getStackInSlot(i);
- if (itemstack != null){//if slot is not empty
- list.add(itemstack);//add item to list
- for (Item item : repairMaterial){
- if (itemstack.getItem().equals(item) && !itemstack.getItem().equals(itemToRepair)){ //if the item is a repair material and is not the item being repaired
- amt += itemstack.stackSize;
- System.out.println(itemstack.stackSize); //debug
- }
- }
- if (itemstack.getItem().equals(itemToRepair)){
- repairedItem = itemstack;
- durability = itemstack.getItemDamage();
- }
- }
- }
- return new ItemStack(itemToRepair, 1, repairedItem.getItemDamage() - amt);
- }
- @Override
- public int getRecipeSize() {
- System.out.println(2);//debug
- return 0;
- }
- @Override
- public ItemStack getRecipeOutput() {
- System.out.println(3);//debug
- return output;
- }
- @Override
- public ItemStack[] getRemainingItems(InventoryCrafting inv) {
- System.out.println(4);//debug
- ItemStack[] arrayStacks = new ItemStack[inv.getSizeInventory()];
- for (int i = 0; i < arrayStacks.length; ++i){
- inv.setInventorySlotContents(i, null); //all items in the crafting grid were used, even ones in a stack
- }
- return arrayStacks;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement