Jump to content

Recommended Posts

Posted

Sooo, I've spent far too long trying to figure out this new God-forsaken recipe system. I gave up with .json files, because let's face it - not everybody wants to be forced to use them, and I have been unsuccessful in getting them to work (every single example online is set out differently). Finding a way to program my crafting recipes is also proving to be a task and a half. This is extremely frustrating, and my mood has dwindled down ever since this 1.12 update. All I need is to be able to program my crafting recipes WITHOUT stupid .json files, because they don't work. No... they don't. Besides, what if I wanted to have a config to allow users to disable specific recipes?

 

So all I ask of you fine brainiacs out there, is this:

Does anybody know how to register crafting recipes in 1.12 using java code?

 

If someone can explain the current implementation of GameRegistry.addShapedRecipe() and how to properly use it in a mod, given the changes, that would be highly appreciated, and you'll receive 10 gold stars and a cookie (virtual). I don't even mind making a recipe helper class, I've already sifted through a few others provided by well-known mod developers, to no avail. Crash here, crash there, and normally I can understand crash reports and fix things, but not this time. So, without any sarcastic remarks, or "why not just use .json files?", please kindly provide any useful information.

 

And don't be one of those useless people who can't be bothered to properly answer a question. If you post a link to some code that someone else has thrown together to make THEIR mod work, it's NOT going to work in MY mod. At least mock up a quick and easily adaptable example with an explanation of what it does and how to implement it, that's all I need. That way, you'll be helping me and the hundreds of others who can't seem to get along with this new... *ahem*... "crafting system".

Posted (edited)

If you put your recipe JSONs in a assets/modid/recipes package/directory, they will be automatically loaded by forge. If you are having trouble with the formatting of the files, look at how Vanilla does it. You can also search your log for JSON parsing errors, they will tell you what line and column any JSON errors appear on.

 

As for having configs for disabling recipes, I'm not sure how it works but I think Choonster's test mod has something like that here: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/1.12.1/src/main/java/choonster/testmod3/crafting/ingredient/ConditionalIngredientFactory.java

 

Trying to make recipes work without JSON files is a lot of unnecessary hard work, if you learn how to use the new system it will be a lot easier for you.

Edited by laton95
  • Sad 1
Posted

Instead of storing a collection of items and comparing the contents of a the crafting grid against them, recipes now store a collection of Ingredient objects and ask each one whether the contents of the crafting grid match.

 

Recipes are now stored in a Forge registry, so each one has a unique registry name. This also means that they should be registered in the corresponding registry event using IForgeRegistry#register.

 

GameRegistry.addShapedRecipe works much like it did before, but now it requires you to specify the registry name (the first parameter) an optional recipe book group (the second parameter). Recipes with the same group will be shown together in the recipe book. The vararg parameter should contain the shape strings followed by the character and ingredient pairs, just like before. The ingredients can be ItemStacks, Items, Blocks, Strings (for ore dictionary matching) or Ingredients.

 

I highly recommend learning the JSON system. If you're getting errors that you don't understand, post them along with your JSON files and we can try to help you. 

 

 

26 minutes ago, laton95 said:

As for having configs for disabling recipes, I'm not sure how it works but I think Choonster's test mod has something like that here: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/1.12.1/src/main/java/choonster/testmod3/crafting/ingredient/ConditionalIngredientFactory.java

That's not quite what the OP is looking for. Forge already allows you to specify conditions for a recipe that can disable it at load time, that class allows you to specify conditions for an individual ingredient.

 

diesieben07 explains how to create your own conditions here:

 

  • Like 2

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)

Thank you, yes I had the .json recipes in the correct place, and had modified a vanilla recipe, adding the mod ID in places, and I was just having no luck getting it to recognise an item that has been properly registered and is in the game, and it didn't recognise the shape definition. I know people think the .json system is better, but I don't like it, partially because how arbitrary it is, partially because it doesn't seem to work with mods very well.

 

Choonster, as always your comment is very useful :) Could you please explain where the 'name' parameter of GameRegistry.addShapedRecipe() should point to?

 

Thanks

 

Untitled.png

Edited by Sataniq
Posted

It's a registry name, name it whatever you want, just like you would a block or item.

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.

Posted (edited)
13 minutes ago, Sataniq said:

Choonster, as always your comment is very useful :) Could you please explain where the 'name' parameter of GameRegistry.addShapedRecipe() should point to?

 

It's the same as GameRegistry.addShapelessRecipe: name is the registry name and group is the recipe book group.

 

13 minutes ago, Sataniq said:

Thank you, yes I had the .json recipes in the correct place, and had modified a vanilla recipe, adding the mod ID in places, and I was just having no luck getting it to recognise an item that has been properly registered and is in the game, and it didn't recognise the shape definition.

 

We could help you fix this if you posted your JSON file and the errors.

 

13 minutes ago, Sataniq said:

partially because it doesn't seem to work with mods very well.

 

It works perfectly fine with mods. If there are specific bugs you've encountered, report them so they can be fixed.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Okay, I finally got somewhere. It required the mod ID to be appended at the start of the name, followed by a colon (it seems).

 

New problem: in the recipe I defined that for the input, it requires a stack of 10, but it provides output when a single item is put in the crafting bench.

Also the .lang file isn't naming the items now. I'm aware you're supposed to append the mod ID in front of the item name, but this isn't working as per the examples.

 

AddRecipe(new ItemStack(ModItems.coinDwarfSilver, 1), new Object[]{"#", '#', new ItemStack(ModItems.coinDwarfCopper, 10)});

 

private static void AddRecipe(ItemStack output, Object... input)
	{
		ResourceLocation name  = new ResourceLocation(Main.MODID + ":coins");
		ResourceLocation group = null;
		GameRegistry.addShapedRecipe(name, group, output, input);
	}

 

 

2017-08-15_16.50.52.png

Posted
3 minutes ago, Sataniq said:

Okay, I finally got somewhere. It required the mod ID to be appended at the start of the name, followed by a colon (it seems).

 

Use the ResourceLocation(String, String) constructor to specify the domain (mod ID) and path (name) components of the ResourceLocation separately. You only need to combine them with a colon when specifying a ResourceLocation in a string (e.g. an item registry name in a recipe file).

 

4 minutes ago, Sataniq said:

New problem: in the recipe I defined that for the input, it requires a stack of 10, but it provides output when a single item is put in the crafting bench.

 

The vanilla crafting system has always ignored the stack size of ingredients, a recipe can only consume one item per slot.

 

 

I noticed in your previous post that you're registering the recipe in postInit, but it should be done in the registry event (as I said in my initial reply).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

So can I not make it so 10 copper coins can be crafted into 1 silver coin and vice-versa, etc? :(

 

And looking at your mod (from the link posted in one of the comments above), I've set my lang file out the same way, changing the mod ID of course, and no matter what it won't name the items. The modid is correct, the assets folder is correct, etc. I've made plenty of mods before and I do know how these things should be set out, but 1.12 changes are a real pain.

Posted
9 minutes ago, Sataniq said:

Also the .lang file isn't naming the items now. I'm aware you're supposed to append the mod ID in front of the item name, but this isn't working as per the examples.

 

We'll need a bit more detail than this.

 

Does the unlocalised name displayed in-game match the unlocalised name in the lang file?

 

What's the exact name of your lang file? Do you have a pack.mcmeta file and if so, what's pack_version set to?

 

If you have a pack.mcmeta file with pack_version set to 3 (which you should do), Minecraft will load all assets with lowercase names. This means your lang files should be en_us.lang, fr_fr.lang, etc.

 

If pack_version is set to 2 or you don't have a pack.mcmeta file, Forge will wrap your mod's resource pack in LegacyV2Adapeter which loads lang files with the old mixed-case names, e.g. en_US.lang, fr_FR.lang, etc.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)
8 minutes ago, Sataniq said:

So can I not make it so 10 copper coins can be crafted into 1 silver coin and vice-versa, etc? :(

 

Not with the vanilla crafting table. Either add some intermediate product so you don't have 10 ingredients in a recipe (e.g. 5 copper coins become a stack of coins and 2 stacks become a silver coin) or create your own machine that can handle the required recipes.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

-Yes, the unlocalized names match.

-The lang file is: assets.twt.lang.en_US.lang (I've also tried en_us.lang)

-Yes, I have a pack.mcmeta with the version set to 3

Posted (edited)
5 minutes ago, Sataniq said:

-Yes, the unlocalized names match.

-The lang file is: assets.twt.lang.en_US.lang (I've also tried en_us.lang)

-Yes, I have a pack.mcmeta with the version set to 3

 

I'm not too sure what's wrong, then.

 

Are those definitely nested directories and not just a single directory with dots in the name?

 

Is the lang file encoded in UTF-8?

 

 Are there any errors in the log?

 

Try rebuilding your project in your IDE and re-running Minecraft, it's possible that it may be using and old/broken copy of your lang file.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Yes, when I created the package in IntelliJ IDEA, it created it with dots so I deleted them and created them in Windows Explorer to ensure they're nested. No errors appear in the log. I'm not sure of the encoding of the .lang file, but usually IDEA makes the files properly and they work, so I'd assume they are encoded in the correct format.

Posted
6 minutes ago, Sataniq said:

I'm not sure of the encoding of the .lang file, but usually IDEA makes the files properly and they work, so I'd assume they are encoded in the correct format.

 

You can see the encoding of a file on the right-hand side of the bottom status bar.

 

 

I'm not sure what the problem is, so I'll need to debug it locally. Please create a Git repository for your mod, push it to a site like GitHub and link it here. Look at my mod and its .gitignore file for an example of the repository structure to use and the files to include.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I'm not a fan of GitHub, I find it confusing to use (all this push, pull, fork, requests, bash etc). I tried using it a while back with a tutorial and I just couldn't get along with it :/ Also you're right, and the encoding is indeed UTF-8 for the .lang file. This is how the file looks:

Quote

item.twt:coindwarfcopper.name=Copper Dwarven Coin
item.twt:coindwarfsilver.name=Silver Dwarven Coin
item.twt:coindwarfgold.name=Gold Dwarven Coin

 

Posted

Everything is fixed now, I changed my Item registration to work the same way as you had it set out in your test mod, and that seems to have fixed the language file naming. I also made the coin crafting recipe use 9 copper coins in a 3x3 grid to create a silver coin. I would've preferred to have the value equal to 10 instead of 9, but it's not super important. Perhaps I'll make a machine, but since this is a medieval themed mod, I don't really feel that machines would fit in.

 

Thank you for all your help Choonster

  • 2 years later...
Posted
On 8/15/2017 at 11:52 PM, Sataniq said:

GameRegistry.addShapedRecipe(name, group, output, input);

I don't understand what to fill in.  Can someone give like an example on what to fill in?

Posted
6 minutes ago, DarrylBD99 said:

I don't understand what to fill in.  Can someone give like an example on what to fill in?

This topic is old, please start your own thread with details of what you need help with, as well as what you have tried.

 

Please also keep in mind that 1.12 is no longer supported on these forums due to age, see the LTS link at the top of ever page for more information on supported versions.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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