Jump to content

[1.12] Recipe that accepts any level of damage on items


quantumapples

Recommended Posts

Hi. How can I configure a recipe JSON to accept items of any damage level? Currently my item damages itself during crafting and then I am unable to use it further.

 

I know I could make one JSON for each damage level (there are only 12) but I am hoping someone might have a more elegant solution to the problem. Any advice is appreciated, and the codes are below. Thanks!

Recipe:

Spoiler


  "type": "minecraft:crafting_shapeless",
  "ingredients": [
    {
      "item": "qraft:carnyx_sharpener"
    },
    {
      "item": "qraft:carnyx",
      "data": 0
    }
  ],
  "result": {
    "item": "sharpened_carnyx",
    "data": 0
  }
}

Carnyx Sharpener:

Spoiler

package main.java.common.item;

import net.minecraft.item.ItemStack;

public final class QraftCarnyxSharpener extends QraftItemBase {

    public QraftCarnyxSharpener() {
        super("carnyx_sharpener");
        setMaxStackSize(1);
    }

    @Override
    public int getMaxDamage() {
        return 12;
    }

    @Override
    public boolean hasContainerItem(final ItemStack stack) {
        return true;
    }

    @Override
    public ItemStack getContainerItem(ItemStack stack) {
        stack = stack.copy();
        stack.attemptDamageItem(1, itemRand, null);
        return stack;
    }

}

 

Edited by quantumapples
clarified title :>
Link to comment
Share on other sites

I believe set data to 32767 in the recipe.

  • Like 1
  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

I updated the relevant portion of the recipe:

Quote

{
      "item": "qraft:carnyx_sharpener",
      "data": 32767
 },

But in game I put the sharpener and the item in the crafting grid and it will only craft one of them still. I also tried it with a comma in the event that JSON required it and that didn't work either. Is there anything I need to do in the crafting for the sharpener? Any recipe factories I might need or would I need to add it to a recipe group? I appreciate the help

Link to comment
Share on other sites

17 minutes ago, quantumapples said:

I updated the relevant portion of the recipe:

But in game I put the sharpener and the item in the crafting grid and it will only craft one of them still. I also tried it with a comma in the event that JSON required it and that didn't work either. Is there anything I need to do in the crafting for the sharpener? Any recipe factories I might need or would I need to add it to a recipe group? I appreciate the help

Post your whole recipe json please.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, Animefan8888 said:

Post your whole recipe json please.

Sure:

Spoiler


  "type": "minecraft:crafting_shapeless",
  "ingredients": [
    {
      "item": "qraft:carnyx_sharpener",
      "data": 32767
    },
    {
      "item": "qraft:carnyx",
      "data": 0
    }
  ],
  "result": {
    "item": "sharpened_carnyx",
    "data": 0
  }
}

 

And if it is relevant, here is the recipe for the sharpener itself:

Spoiler


  "type": "minecraft:crafting_shaped",
  "pattern": [
    "A",
    "B"  ],
  "key": {
    "A": [
      {
        "item": "minecraft:iron",
        "data": 0
      }
    ],
    "B": [
      {
        "item": "qraft:carnyx",
        "data": 0
      }
    ]
  },
  "result": {
    "item": "qraft:carnyx_sharpener",
    "data": 0
  }
}

Thanks!

Link to comment
Share on other sites

29 minutes ago, quantumapples said:

Sure:

I'm not sure why this isn't working for you, and you may want to change.

 

31 minutes ago, quantumapples said:

"item": "sharpened_carnyx",

To have your modid

 

I have this which should be similar to your code and it works

Spoiler

{
				setMaxStackSize(1);
			}
			@Override
			public int getMaxDamage() {
				return 12;
			}
			
			@Override
			public ItemStack getContainerItem(ItemStack itemStack) {
				ItemStack stack = itemStack.copy();
				stack.attemptDamageItem(1, new Random(), null);
				return stack;
			}
			
			@Override
			public boolean hasContainerItem(ItemStack stack) {
				return true;
			}

and


{
	"type": "minecraft:crafting_shapeless",
	"ingredients": [
		{
			"item": "capacitance:hammer",
			"data": 32767
		},
		{
			"item": "minecraft:iron_ingot",
			"data": 0
		}
	],
	"result": {
		"item": "minecraft:iron_ingot",
		"data": 0
	}
}

 

 

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

14 minutes ago, Animefan8888 said:

I have this which should be similar to your code and it works

The last thing that comes to mind for me would be that my class (effectively*) extends item. Does the item need to extend tool for the 32767 to register as 'any damage level'?

Thanks for all your help, if I figure it out I'll update with what the issue was.

 

*I have an item base which auto-registers and does other basic stuff, but the item base extends directly from item.

Link to comment
Share on other sites

2 minutes ago, quantumapples said:

The last thing that comes to mind for me would be that my class (effectively*) extends item. Does the item need to extend tool for the 32767 to register as 'any damage level'?

No it does not because mine only extends Item.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

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.