Java Code Examples for net.minecraft.item.Item.isRepairable()

The following are Jave code examples for showing how to use isRepairable() of the net.minecraft.item.Item class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Soot   File: JEI.java   View Source Code Vote up 5 votes
private List<RecipeDawnstoneAnvil> generateDawnstoneAnvilRecipes()
{
    //I'm basicly sorry for all of this. Please forgive me.
    ArrayList<RecipeDawnstoneAnvil> repairRecipes = new ArrayList<>();
    ArrayList<RecipeDawnstoneAnvil> destroyRecipes = new ArrayList<>();

    for (Item item : Item.REGISTRY) {
        ItemStack stack = item.getDefaultInstance();
        ItemStack repairItem = ItemStack.EMPTY;
        try {
            repairItem = Misc.getRepairItem(stack);
        }
        catch (Exception e) { //Gotta catch em all
            e.printStackTrace();
        }
        boolean isRepairable = item.getIsRepairable(stack, repairItem);
        boolean materiaAllowed = item.isRepairable();
        if(isRepairable || materiaAllowed)
        {
            ArrayList<ItemStack> repairMaterials = new ArrayList<>();
            repairMaterials.add(repairItem.copy());
            if(materiaAllowed)
                repairMaterials.add(new ItemStack(RegistryManager.isolated_materia));
            ItemStack[] repairMaterialsArray = repairMaterials.toArray(new ItemStack[repairMaterials.size()]);
            repairRecipes.add(new RecipeDawnstoneAnvil(new ItemStack[]{stack.copy()}, Ingredient.fromStacks(makeDamaged(stack)),Ingredient.fromStacks(repairMaterialsArray)));
            if(Misc.getResourceCount(stack) != -1) {
                ItemStack material = repairItem.copy();
                material.setCount(Misc.getResourceCount(stack));
                destroyRecipes.add(new RecipeDawnstoneAnvil(new ItemStack[]{material}, Ingredient.fromStacks(makeDamaged(stack)), Ingredient.EMPTY));
            }
        }
    }

    return Stream.concat(repairRecipes.stream(),destroyRecipes.stream()).collect(Collectors.toList());
}