Jump to content

[1.12.2] Ignoring Durability on NBT-Tagged Items in Recipes


Recommended Posts

Posted

Hey guys,

 

I've created a  Hammer Item which uses NBT tags to create sub-items for each material it's made of and also has durability, which gets decreased when metal plates are crafted with it. The problem is that the crafting recipe only accepts the undamaged hammer item although i specified it as an ingredient with the Wildcard as data. I looked over my code, but can't find a solution on how to get it to accept hammers of every damage value.

 

ItemHammer.java:

Spoiler

package piggo.industrialization.objects.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import piggo.industrialization.Main;
import piggo.industrialization.utils.HammerUtils;
import piggo.industrialization.utils.HammerUtils.EnumHammerMaterial;
import piggo.industrialization.utils.IHasModel;

public class ItemHammer extends Item implements IHasModel{
      
    public ItemHammer(String name, CreativeTabs tab){
        setMaxDamage(0);
        setUnlocalizedName(name);
        setRegistryName(name);       
        setCreativeTab(tab);
    }
    
    @Override
    public void registerModel() {        
        Main.proxy.registerItemRenderer(this, 0, "inventory");
    }
    
    @Override
    public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items){
        if(this.isInCreativeTab(tab)){
            for(EnumHammerMaterial material : EnumHammerMaterial.values()){
                items.add(HammerUtils.createHammer(new ItemStack(this), material));
            }
        }
    }
    
    @Override
    public String getUnlocalizedName(ItemStack stack){
        return super.getUnlocalizedName(stack) + "." + HammerUtils.getRegistryNameFromNBT(stack);
    }
    
    @Override
    public int getMaxDamage(ItemStack stack){
        return super.getMaxDamage(stack) + HammerUtils.getDurabilityFromNBT(stack);
    }
    
    @Override
    public boolean hasContainerItem(ItemStack stack){
        return true;
    }
    
    @Override
    public ItemStack getContainerItem(ItemStack stack){
        if(stack.getMaxDamage() == stack.getItemDamage()){
            return (ItemStack)null;
        }
        else{
            ItemStack stack2 = stack.copy();
            stack2.setItemDamage(stack.getItemDamage() + 1);
            return stack2;
       }        
    }
    
}

 

JSON recipe:

Spoiler

{
    "type": "minecraft:crafting_shapeless",
    
    "ingredients" : [
        {
            "item": "idtn:hammer",
            "data": 32767
        },
        {
            "item": "idtn:ingot_steel"
        }
    ],
    
    "result": {
        "item": "idtn:plate_steel"
    }
}

 

 

It works that the recipe accepts hammer's with every nbt tag though.

 

Thanks for every helpful answer :)

 

Greets,  MrPiggo

Posted (edited)

Hmm, okay. I will do so, but is there an other way of keeping the amount of recipes as low as possible? Because when I create an Item for every Hammer I need to create a seperate recipe for each of them and each of my plate items.

Edited by MrPiggo
Posted

Tough.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.