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 com.gamebuster19901.supernatural.technical.DebugException;
- 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
- 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 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 amtItemsToRepairFound = 0;
- int amtrepairable = 0;//how many repairable items are in the grid
- int durability;//current durability of the item to repair
- ItemStack repairedItem = null;
- //DebugException e = new DebugException();
- //e.printStackTrace();
- 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();
- amtItemsToRepairFound++;
- if (amtItemsToRepairFound != 1){ //can only repair one item at a time, no more, no less.
- return null; //no need to keep checking
- }
- }
- }
- }
- if (repairedItem == null){
- //System.out.println("repaired item is null");
- return null;
- }
- if (repairedItem.getItemDamage() - amt >= 0 && amt > 0){ //if the item's damage will not be negative and has changed
- return new ItemStack(itemToRepair, 1, repairedItem.getItemDamage() - amt);
- }
- System.out.println("Result is null");
- return null;
- }
- @Override
- public boolean matches(InventoryCrafting inv, World worldIn) {
- System.out.println(1);//debug
- return true;
- }
- @Override
- public int getRecipeSize() {
- System.out.println(2);//debug
- return 0;
- }
- @Override
- public ItemStack getRecipeOutput() {
- System.out.println(3);//debug
- return null;
- }
- @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