Jump to content

How to register a recipe


Arkyo

Recommended Posts

14 minutes ago, Arkyo said:

which shall I use

Depends on what you want to do. It is generally recommended to use json recipes whenever possible since you get:

  1. No ~1000line-long classes that register various recipes but instead each recipe is neatly in it's own file. Easy to edit anytime you want without having to spend minutes trying to search for that one line that defines the recipe
  2. Any pack maker can easily alter your recipe with a datapack(1.13). No specific recipe-altering mods required.
  3. The _constants file. In it you can easily define a constant that corresponds to an item. Or to multiple items. Or to an oredict enty. Or to both. Here is an example of me using one constant to handle differently named oredict entries. While you kinda can do the same with hardcoded recipes it's not as intuitive and easy as just writing a couple of files in your json.
  4. If something goes wrong with a json recipe the game will kindly provide a log of what went wrong. If something goes wrong with a hardcoded recipe - it just will be missing from the game with no indication as to why.
  5. You will need all your recipes to be json recipes for 1.13 anyway.

However for some complex recipes you will need to use "hardcoded" IRecipe implementation. An example of that would be leather armor dyeing or firework making. There is however a point to be made that even custom IRecipe implementations can still be registered with json as I do here and here.

 

14 minutes ago, Arkyo said:

how to use

If you are using json recipes simply create a recipes folder in your assets/modid folder. All json recipes will then go there. Here is a minecraftwiki page with a description of the format and here is the examples I used myself provided by Lex.

If you are using in-code registration subscribe to RegistryEvent.Register<IRecipe> and use event.getRegistry().register to register your recipes. Do not forget to give them a registry name!

Link to comment
Share on other sites

12 minutes ago, V0idWa1k3r said:

Depends on what you want to do. It is generally recommended to use json recipes whenever possible since you get:

  1. No ~1000line-long classes that register various recipes but instead each recipe is neatly in it's own file. Easy to edit anytime you want without having to spend minutes trying to search for that one line that defines the recipe
  2. Any pack maker can easily alter your recipe with a datapack(1.13). No specific recipe-altering mods required.
  3. The _constants file. In it you can easily define a constant that corresponds to an item. Or to multiple items. Or to an oredict enty. Or to both. Here is an example of me using one constant to handle differently named oredict entries. While you kinda can do the same with hardcoded recipes it's not as intuitive and easy as just writing a couple of files in your json.
  4. If something goes wrong with a json recipe the game will kindly provide a log of what went wrong. If something goes wrong with a hardcoded recipe - it just will be missing from the game with no indication as to why.
  5. You will need all your recipes to be json recipes for 1.13 anyway.

However for some complex recipes you will need to use "hardcoded" IRecipe implementation. An example of that would be leather armor dyeing or firework making. There is however a point to be made that even custom IRecipe implementations can still be registered with json as I do here and here.

 

If you are using json recipes simply create a recipes folder in your assets/modid folder. All json recipes will then go there. Here is a minecraftwiki page with a description of the format and here is the examples I used myself provided by Lex.

If you are using in-code registration subscribe to RegistryEvent.Register<IRecipe> and use event.getRegistry().register to register your recipes. Do not forget to give them a registry name!

Thanks for the reply!

However my recipe still doesn't work...

 

{
    "type": "minecraft:crafting_shapeless",
    "ingredient": 
      {"item": "minecraft:lever"},
  "result": {
    "item": "openscriptie:bit"
  }
}

 

Also, is there anyway to specify number of ingredients in a single slot?

Edited by Arkyo
Link to comment
Share on other sites

11 minutes ago, Arkyo said:

number of ingredients in a single slot?

No, vanilla crafting recipes do not work in this manner.'='

 

11 minutes ago, Arkyo said:

However my recipe still doesn't work...

What does the log say? Also did you even take a look at mcjty's tutorial? You're missing the key and pattern tag.

Edited by Animefan8888

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, Arkyo said:

What does the log say? 

There is no reference to your recipe in the log, where is the json file located, and

4 minutes ago, Animefan8888 said:

Also did you even take a look at mcjty's tutorial? You're missing the key and pattern tag.

 

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

2 minutes ago, Animefan8888 said:

There is no reference to your recipe in the log, where is the json file located, and

 

I am using shapeless recipe, so no keys and patterns needed (?)

 

it is located as assets/openscripties/recipe/lever_to_bit.json

Edited by Arkyo
Link to comment
Share on other sites

10 minutes ago, Animefan8888 said:

You're missing the key and pattern tag.

Those are for shaped recipes, OP is using a shapeless one.

 

18 minutes ago, Arkyo said:

{

    "type": "minecraft:crafting_shapeless",

    "ingredient":

    {

        "item": "minecraft:lever"

    },

    "result":

    {

        "item": "openscriptie:bit"

    }

}

Shapeless recipes specify their ingredients as a json array named ingredients.

Additionally if the item has subtypes the "data" key must also be provided(data is metadata)

Link to comment
Share on other sites

Just now, V0idWa1k3r said:

Those are for shaped recipes, OP is using a shapeless one. 

 

7 minutes ago, Arkyo said:

I am using shapeless recipe, so no keys and patterns needed (?)

 

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

21 minutes ago, Arkyo said:

Failed

Is there an error in the log? Its most likely the ingredients being an array of objects instead of an array of strings.

Edited by Animefan8888

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

8 minutes ago, Animefan8888 said:

Is there an error in the log? Its most likely the ingredients being an array of objects instead of an array of strings.

I found an interesting thing

recipes seems to be completely ignored

[20:39:35] [main/TRACE] [FML]: Recursing into package assets
[20:39:35] [main/TRACE] [FML]: Recursing into package assets/openscriptie
[20:39:35] [main/TRACE] [FML]: Recursing into package assets/openscriptie/lang
[20:39:35] [main/TRACE] [FML]: Recursing into package assets/openscriptie/models
[20:39:35] [main/TRACE] [FML]: Recursing into package assets/openscriptie/models/item
[20:39:35] [main/TRACE] [FML]: Recursing into package assets/openscriptie/textures
[20:39:35] [main/TRACE] [FML]: Recursing into package assets/openscriptie/textures/items
[20:39:35] [main/TRACE] [FML]: Recursing into package chingdim
[20:39:35] [main/TRACE] [FML]: Recursing into package chingdim/OpenScriptie
[20:39:35] [main/TRACE] [FML]: Recursing into package chingdim/OpenScriptie/eventhandler
[20:39:35] [main/TRACE] [FML]: Recursing into package chingdim/OpenScriptie/item
Link to comment
Share on other sites

11 minutes ago, Arkyo said:

I found an interesting thing

recipes seems to be completely ignored

 

24 minutes ago, Animefan8888 said:

Is there an error in the log?

 

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, Arkyo said:

No error

Your path is assets/openscripties/recipes not assets/openscriptie/recipes

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

4 minutes ago, Animefan8888 said:

Your path is assets/openscripties/recipes not assets/openscriptie/recipes

My mistake , modid is openscriptie , no s

Changed ingredients to array of string , failed

Edited by Arkyo
Link to comment
Share on other sites

Just now, Arkyo said:

Changed ingredients to array of string , failed

Change it back, that was my mistake as noted by me striking out the text.

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

Just now, Arkyo said:

Done , and of course still failed :(

Post updated json and path as well as the log.

 

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

Yeah, the "problem" with the JSON asset system is that you have to get everything exactly right and if you don't there isn't always a lot of good warning on exactly what is wrong. For actual Java code, your IDE (like Eclipse) will warn you instantly of references to non-recognizable things, misspellings, wrongly formatted code. But for JSON you have to usually do a lot more manual checking -- is path exactly right, is filename exactly right, is the file a properly formed JSON, are the values in the JSON exactly right.

 

Once you're used to the amount of detail required though you'll pay attention and also have some common ideas on where to look to fix problems that arise.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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