Let’s make a custom recipe tab for our blog entity forging fabric courses with advanced topics such as entities custom structures and three armor models linked in the description below all right we found ourselves back intelligent once more and in this tutorial we’re going to be adding a custom recipe type so this Will include reading in a json file and that json file b is basically representing the recipe for our customer block entity so what are we going to need for this well first of all in the tutorial mod package right click new package called recipe and inside of there we’re going To make two new classes one of them is going to be the gem cutting station recipe and the other one is going to be the mod recipes class and let’s start with the gem cutting station recipe so this is going to implement the recipe interface right here with the simple container as Basically here it’s type and then we’re going to hover over this implement method so you can see quite a few methods there and that is pretty much all that we need we actually need to do a lot of modifications in this class now what i will do is i will actually be Copying over sort of piece by piece of the actual methods all of this is of course available to you in the description below get a repository individual just as well so the first thing we’ll need are the three fields so the fields here are a resource location Id an item stack output and a non-null list of ingredients called recipe items and then we’ll also need the constructor right here there you go we can see just this is just the same name of course and then just passing in the id the output and the recipe types and then setting Them accordingly the matches method we’re going to ignore for a moment and we’re going to do all of the rest and then at the end we’re going to look at the mattress method because this is actually the most important method that we have because this determines whether Or not our well our actual recipe matches with what is inside of the container but we’re going to see that in just a moment the assemble method should just return the actual output so we can just do this aircraft in dimensions should just return true the result item should crazily enough return output.copy Actually very important here and then here the id is just id and then the serializer and the type are special things for which we actually need custom classes so the type class is actually fairly straightforward i’m going to copy that over you can see it’s just a static class type and it just Implements the recipe type of this particular station recipe here and you can see we’re just saving the instance here and the id right here so here inside of the get type method we’re just going to return type.instance and that is pretty much all that we need to do here The serializer is a little more complicated and is a little bit of a longer class here but i’m going to copy it over as well and we’re going to basically see what all of this means so we can see that the serializer class right here implements the recipe Serializer once again of gem cutting station recipe very important here is that the id given here this name right here has to be the name or is the name that we’re going to define inside of the json file in in a few moments when we actually say what type this basically is Right then we have three interesting methods that are the from json from network and to network we’re going to ignore those for a moment and just look at the rest here this is just some craziness that we need you know you see need wrapper because generics i am Honestly not 100 sure why we need this we just need it just put it in there don’t worry about it the registry name is just the id and then the registry name here is just the instance so we’re just returning the same instance here right and then to the three interesting Methods so the three methods the from json from network and from to network first of all the from network and two network well basically we’re writing the actual recipe to the network and here we’re getting the recipe from the network what’s very important here is that when we’re writing it you can see The first thing we’re writing is inside of the buffer right here we’re writing in the size of the ingredient list so basically how many ingredients are in there then we’re looping through all of their ingredients and writing each ingredient once again into the actual buffer and then here at the very end We’re writing the actual result item into the buffer as well and that order has to be the same order that you actually read it out from so this friendly buffer and this friendly buffer you can think of them as the same and we’re going through this first and then This second so to speak so you can see the first thing we’re reading from the buffer is an integer which is of course exactly right because we’re writing an integer first and we’re reading it makes perfect sense and then we’re looping through exactly that many steps as well And then reading in again ingredient from network buffer so we’re reading in the ingredients and exactly how many ingredients we have written in here so those two match exactly this and then you can see buffer read item is the last thing where we exactly read the item the Output here and then we’re creating a new gem cutting station recipe so that’s the general idea here those two methods have to match otherwise if the mod will actually not work properly when you try to join the server or if you try to use the mod outside of your dev environment So that’s very important here that you make sure that this matches if you have to have any modifications done there then those would be done right here and then there is the from json method which you can see basically just reads the json file and this basically well it Takes a look at you know there’s a member output okay then we’re getting an item stack from that output and we also have an array this is the ingredient area in our case this is actually only of size one because we’re only going to have one ingredient here but i basically Kept it as a list because you know sometimes you actually require maybe two different inputs so two different ingredients to well create a recipe and that is why i kept it and then you would change it right here this size does not have to match the size of how many slots You have because of course the ingredients here this list of ingredients these are the inputs right obviously even if you have four slots one of them is going to be the result slot so obviously even then this would not match so just to make that clear so That you don’t confuse those two numbers here right this is just the how many ingredients are read in from the json file and then in the serializer right here we’re just going to do the following serializer.instance and there we go and that should be that as well and then Last but not least we can take a look at the matches method now this is going to return the following i’m going to show you this though it’s going to return recipe items get zero this will return the first recipe item that was read in from the ingredient list from the json File and then it’s going to test it with the container so this would be our block entity and we’re gonna get the item of index one now if we actually take a look at the block entity one more time or actually we can take a look at the menu That’s even better you can think about this like this right index one right here so it would look at this particular slot right there look what is in there and when we think back right in our slot one what we wanted in there is a raw Citri so in our case the water is actually hard coded as well as the gem cutter tools so those two are basically hard coded quote unquote and the only thing that we basically want as a recipe is a one particular item this is why we’re basically only looking for one Item here to match and then we will have a recipe that is valid that is the general idea so the mattress method if that returns true then we have a valid recipe right so let’s move on to the mod recipes class and let’s actually register our serializer in this case so This is a public static final deferred register this time of type recipe serializer of type question mark c realizers which is equal to a deferred register.create forge registries dot recipe serializers comma tutorialmod.mod id and where there is a deferred register of course there is a public static void register method with An i eventbus called eventbus and then serializers.register passing in the eventbus and there you go let’s not forget to call this in our instructor right here tutorial mod class so this is going to be mod recipes dot register and then passing in the event bus and there You go now let’s get the public static final registry object of type recipe serializer of type gem cutting recipe very important here this is going to be the gem underscore cutting underscore let’s go see realizer go and this is equal to the serializers.register of course gem underscore adding that’s Going to be fine jam cutting and then a supplier of the gem cutting recipe.serializer is and now this is very important we also need to go into our event package mod eventbus events so if you don’t have this then you need to create this and Here we’re going to need a new method i will copy over and you’re going to see this is the register recipe types right here and in the registry event recipe serializers we want to register this under well pretty much like this so the ram cassie the gem cutting station Recipe id here and then here the type instance that’s kind of important if you don’t have this then it’s not going to work right once we have added this now the actual civilization is well basically in game and the the json file would be serialized however of course We’re not doing anything inside of our block entity and for that we actually need to modify this quite significantly so what i’m going to do is i’m actually going to copy over most of this or pretty much everything and that we’re going to need here and i will explain so The first thing we’re going to do is at the very top we’re going to add three different fields so this is going to be the container data as well as the progress and the max progress so this is going to determine how much progress has Been made inside of the uh you know with crafting this recipe so this would be corollary for this is basically is basically the arrow inside of for example the furnace and this is what this represents so this is the current progress and this is the max progress so As soon as progress has reached max progress we’re basically done that is the general idea and then we need this container data that’s kind of weird yes and what we’re going to do is we’re going to assign this inside of the constructor right here i’m going to copy This over as well so let’s just copy it right here and once again of course everything here is available to you in the description below get a repository individual just as well and then you can see we basically make some new container data and then passing in the progress and the max progress Under the indices zero and one here the count of course has to be exactly how many different fields or how many different variables we’re saving and this is pretty much boilerplate as well however many well basically data you want to save you can put in here now the Reason why we have to do this is because these fields are actually only saved on the server and we need to get them to the client meaning in our screen or screen here this is client only and to actually be able to use this right we have to somehow synchronize them from The server to the client and from the client to the server therefore we need this container data then passed in through the menu to the screen that is the general idea here and that is why we need to do this what we also want to do Is we want to pass this right here to the actual menu so this data data now this is going to be an error but we’re going to fix that in just a moment let’s actually finish the rest of the of the block entity here and then we’re going To fix that in the menu as well so in the save additional right here of course what we would want is we want the to save the progress as well so let’s just add this you can see we’re just putting in the integer progress right here under gem underscore cutting under Scorestation.progress and then under the load method we’re reading this out once again this is of course just to save the progress basically should be fairly self-explanatory and now we’re going to basically delete all of the methods that we have here and replace them with some other methods now this is going to be Quite a lot of methods we want basically everything from the tick method all the way to once again can insert amount into output slot method once again you can copy this over as well now once we copy this over we should get no additional errors there are one error there because There is should be gem color tools there you go so there should be no errors at present at this time and what we’ll see is we still have the tick method but it has become a lot more complicated so basically we’re still asking for a recipe and then we’re increasing the Progress so as long as the block entity has a recipe present inside of the inventory we’re going to increase the progress and as soon as progress is bigger than our max progress then we’re going to craft the item so this is basically going to make it so that we’re Going to well increase the progress every tick and at some point we’re going to craft the item so we’re no longer crafting the item every tick we’re only going to craft it every max progress amount of ticks basically the has recipes method has also changed quite significantly you can see we’re Basically filling a simple container with all of our slots right here so this is just some boilerplate code that we’re doing here and then we’re asking the actual recipe manager hey is there a recipe present for this particular inventory so we’re basically saying okay look at the inventory of the block Entity is there a recipe present that is under the gem cutting station recipe you know namespace so to speak and if that is present that’s great then basically the first boolean here is true and then all of the other booleans have to also be true so once again can insert amount Into output slot this is the at the very bottom here so we’re just checking okay if we were to you know add something to it would this actually be more than the stack size if that is the case then we would not add it basically and then also can insert item into Output slot basically checks whether or not the actual item inside of the output slot is already the item we’re trying to put in as well or if the output slot is empty that is the general idea here so nothing too crazy right there so those Would be this one and this one and then we also checking has water in slot water slot so we’re just checking once again if in the first slot we have water and then we’re also checking whether or not the tools are in the tool slot so that Is pretty much all we’re doing right here and then we’re crafting the item once again for crafting the item i’m actually checking once again if the recipe is present just in case and if that is the case then we’re going to extract the item from slot zero we’re Going to extract the item from slot one we’re going to hurt once again the gem color tools and then we’re just increasing how many items are in the output slot but this time we’re actually getting the actual result slot right here of the item and then we’re resetting the progress once again that Is the general idea here and then what we can also see is if we don’t have a recipe right here we’re continuously resetting the progress just in case so that if you take something out you know it doesn’t just stop there at the progress but it actually resets it as Well those are pretty much the modifications done for the tick method and that is pretty much also you know kind of what you need to do if you add the custom recipe types here and then let’s actually go into the station right here so for this data this is of course Going to display the progress arrow in just a moment so let’s go into the menu and actually fix the particular error here so we actually are expecting now a new parameter right here and that is going to be the container data and we’re just going to call this data and then we’re Going to get an error right here no worries at all we’re just going to add the following new simple container data and then passing in however many data items or you know the pieces of data we’re gonna add so this is once again the same as this one right here so the Count right here has to match this one right here make sure that you have this right otherwise you will get an error we also want to save this in a variable so private final container data called data and then after the level here we’re just going to say this.data is equal to data So we’re basically setting this particular field here to this particular data parameter and then incredibly important do not forget this we want to add um add data slots right here and then pass in the data so this is really important that we have this otherwise it’s not going to be Synchronized we are also going to add two new methods here and i will just copy them over once again everything here available to you or basically just checking okay is the first data variable here bigger than zero then we know we are currently crafting and then we’re Getting the scaled progress so this is just a bunch of you know interesting math basically to show okay how far along are we on crafting process and then we’re just you know having a bunch of math here to basically get it scaled so our progress Arrow size is 26 pixels in this case and then we’re just basically making sure okay if we’re 50 done then we’re gonna output basically 13 because then what we want to do is we want to get 13 pixels of that arrow displayed that is the general idea hopefully that should be Understandable it pretty much is just a bunch of math so nothing too crazy and then what we are going to do in the screen is then we’re going to draw this so i’m once again going to copy this over and i’m going to try to explain Because this is most of the time one of the parts that is a little confusing to quite a few people understandably so by the way because the blit calls are can be quite complicated so you’re going to say what are all those numbers what do They mean what the frick is all of this don’t worry we’re going to get through this so what we’re going to do is we’re going to open the gui and here we have it so let’s think about this what do we want to do with this well what we want To do with this is of course we want to draw this particular arrow right onto this particular arrow okay that’s that’s our goal and why are those numbers basically here well let’s think about this 102 and 41 what does that mean well 102 just means you know 102 Pixels to the right and then 41 pixels down once again we’re starting here right so 102 pixels to the right and 41 down is around right here and then about right here so right here is our 102 and 41 so this means that the first two Parameters so to speak so our x and our y plus whatever how many pixels we basically want to be from the top left corner of your gui right this is where your cur where your new image is going to be drawn okay so let’s just think about this we’re going to draw from Right here right about let’s say right right about here okay then let’s think about what is 176 and zero what what is that right that’s the offset you offset y offset what does that mean well this basically determines from where you take the image that you want to be drawn Because we’re saying okay we want to draw right here but what do we want to draw well we need to draw something from 0 so y 0 right and then x 176 right that was 176 yeah so we basically want to start drawing from here and then we have to Define what is the size of the image that we want to draw and you can see the width is 8 so that means that the width here is going to be 8 pixels okay and then what is the height ah the height is the scaled progress that we get from the Menu meaning that the more crafting progress we have the more of this arrow is going to be displayed until we basically have displayed the entire arrow and then we’re done crafting then the progress is going to be zero again meaning that after that the arrow is going to be basically not drawn anymore So this is what those numbers mean they can be quite complicated however once again i highly suggest just being open to experimentation on this as well trying out a bunch of stuff trying out some other numbers and then hopefully you’re also gonna get a little bit more Of an intuitive feel for it usually they are not that crazy when you really think about it uh what each of these different things are i had a difficult time in the beginning with the blit as well but you know if you actually think about it then afterwards you should be fairly Self-explanatory all things considered right now the last thing that we need to do is add the recipe so let’s add the recipe as well in the tutorial mod recipes right here so let’s just copy it over i’m going to copy this over this is the citrine from the gem cutting station And you can see this is the type right here this is the type that we’ve defined then we’re basically saying okay if we put in a raw citrine right here we’re going to get as an output a normal citrine that is pretty much all that we’re saying here and now everything Should be working totally fine exactly how you would expect it to and that’s actually you know the entire process of this it can get quite complicated and also you know i’ve sort of mixed the you know custom recipe serialization a little bit with the you know showing the Progress right here but that is pretty much gonna be fine so i guess for completion stick let’s see if it works or it finds us back in minecraft so let’s just put everything into place and let’s see if we can start seeing a progress arrow and there we go we get The progress arrow and after it’s done there we go we i mean everything works exactly how you’d expect it to let’s add another piece of water here another water bottle and there you go and then there’s another one and it should also just add it to it there you go two of Them so everything working exactly how you’d expect it to you know showing the progress doing everything that we wanted to do and crafting the correct item that’s really freaking awesome just like this you can basically make your own custom recipes for this particular block entity and as i’ve said you can always Modify the recipe as well to basically include some other things you know multiple different inputs whatever this is just you know this is a basically a canvas on which you can draw and just change it up however you need to or however you would like but for the time Being this is it for this tutorial right here i hope you found this useful and you learned something new if you did i would very much appreciate like and don’t forget to subscribe for more tutorials just like this one i also want to thank all of my lovely patreon Supporters for supporting me and this channel it is very much appreciated and i’ll see you in the next tutorial so yeah Video Information
This video, titled ‘Minecraft Modding 1.18.2 with Forge | CUSTOM RECIPE TYPES’, was uploaded by Modding by Kaupenjoe on 2022-04-23 13:59:50. It has garnered 8426 views and 138 likes. The duration of the video is 00:21:29 or 1289 seconds.
In this Minecraft Modding Tutorial, we add a custom RECIPE TYPE to Minecraft 1.18.2!
== MINECRAFT COURSES == ▶️ Learn Forge Modding with Minecraft 1.18: https://url.kaupenjoe.net/CourseForge118 * ▶️ Learn Fabric Modding with Minecraft 1.18: https://url.kaupenjoe.net/CourseFabric118 *
== ASSETS & DOWNLOAD LINKS == GitHub Repo: https://github.com/Tutorials-By-Kaupenjoe/Forge-Tutorial-1.18.1/tree/45-recipeTypes Gist: https://url.kaupenjoe.net/yt273/gist
== TIMESTAMPS == 0:00 Intro 0:30 Creating the Custom Recipe Class 7:21 Registering the Custom Recipe Serializer 9:20 Modifying the BlockEntity Class 14:48 Modifying the Custom Menu Class 16:43 Modifying the Custom Screen Class 17:01 Explaining what this.blit does 19:29 Adding the Custom Recipe 20:14 Demonstration 21:08 Outro
== TAKE A LOOK AT MY COURSES WITH COUPON CODES == ▶️ NEW Forge Modding with Minecraft 1.20.X: https://url.kaupenjoe.net/CourseForge120X ▶️ Learn Forge Modding with Minecraft 1.18: https://url.kaupenjoe.net/CourseForge118 * ▶️ Learn Fabric Modding with Minecraft 1.18: https://url.kaupenjoe.net/CourseFabric118 * ▶️ Complete and Roblox Lua Game Development: https://url.kaupenjoe.net/RobloxCoupon *
== SOCIALS == Discord: https://discord.com/invite/yqxykanpWf Personal Twitter: https://twitter.com/Kaupenjoe
Instagram: https://url.kaupenjoe.net/tutorials/instagram Facebook: https://url.kaupenjoe.net/tutorials/facebook Twitter: https://url.kaupenjoe.net/tutorials/twitter TikTok: https://url.kaupenjoe.net/tutorials/tiktok Written Tutorials: https://url.kaupenjoe.net/tutorials/blog
== LICENSE == Source Code is distributed under the MIT License. Additional Licenses for other assets can be seen below or in the accompanying CREDITS.txt on download.
== ADDITIONAL CREDITS == Outro Musik by Kevin MacLeod: “That’s a Wrap” Kevin MacLeod (incompetech.com) Licensed under Creative Commons: By Attribution 3.0 http://creativecommons.org/licenses/by/3.0
== AMAZON AFFILIATE LINKS == Amazon Referral [US]: https://url.kaupenjoe.net/amazonref/us * Amazon Referral [UK]: https://url.kaupenjoe.net/amazonref/uk * Amazon Referral [DE]: https://url.kaupenjoe.net/amazonref/de *
== AFFILIATE DISCLAIMER == * Some of the links and other products that appear in the video description are from companies which I will earn an affiliate commission or referral bonus from or are my own products. This means that if you click on one of the product links, I’ll receive a small commission or additional kickback without any additional cost for you. This helps support the channel and allows me to continue to make videos. Thank you for the support!
== HASHTAGS == #Minecraft #MinecraftModding #MinecraftTutorial #Kaupenjoe