Let’s add a custom recipe type to our custom block entity oh right we find ourselves back into intelligent once more and in this tutorial we’re going to be adding a custom recipe type to our custom block entity so last time of course we’ve implemented the block entity with well more or less a Recipe that is already well hard coded more or less in this case however now we’re going to make this a custom recipe type so that we can just make json files and then all of those recipes are just going to work it’s going to be absolutely glorious in our tutorial Month package we’re going to right click new package and this is going to be called the recipe package and so there we need two classes first one is the mod recipes class and the second one is going to be the gem infusing block nope gem infusing a recipe yeah There you go that’s actually a great name now let’s start here this is going to be quite a long class so sort of bear with me so we’re going to implement the recipe so this is going to be the net minecraft recipe absolutely the interface and this is of simple inventory You can hover over this implement methods you can see we have to implement quite a few methods over here and what we also will do is copy over a bunch of stuff now once again everything here is available to you in the description below get up repository and individual Just as well now what we’ll do is i will just copy over the three fields that we’re definitely gonna need that is an identifier a output as well as some recipe items so this would be the input basically and then we’re gonna have a new instructor with all of those things An id right a output as well as the recipe items as a defaulted list of ingredient so then we can basically go through this and let’s actually start roughly at the let’s actually start at the bottom and move our way up because the matches method is actually pretty Much the most important method while the rest is sort of boilerplate code more or less so let’s start with the type class so we’re going to have a class in here a set a class of type well i mean called type which implements the recipe type of This particular recipe now this is once again just a sort of a boilerplate thing just make sure to change the idea right here that is actually very very important and then we’re going to have another static class and that is the serializer now if we actually add this you can see This is of type recipe serializer or it implements recipe serializer of this type once again making sure that the id here is correct that is very important this is the name given inside of the json file make sure that this is done and then we need to implement three Methods the read the read and the write method let’s implement those and let’s see what those entail so those entail some interesting things the read method here is reading the json file while the read and the right method here are for what we say those are for the networking stuff to basically work Now i’m just going to start copying over stuff let’s just copy over the contents of the entire method here the read method and then i’m going to explain what this does so this is going to read the following first of all it’s going to read an an adjacent element right a json Object over here that’s called output and it’s just going to make sure that this is well it’s going to convert that output into a item stack that’s going to say oh this is now an item stack right and then we have the output we’re basically ready we’re also going to have An array so it’s adjacent area of ingredients and we’re going to basically read those in now we have a defaulted list here of size one this means that we are going to only read in one ingredient this needs to correspond to the number of crafting inputs you have this is not the Number of slots you have very important this is like how many things you want to ever be able to read in um and then also if you ever want to change this i’m going to say that like this you just have to play around with this a little Bit this is pretty much just json serialization so if this is like really interesting to you you can there are some things number one you can just look at java serialization how that works right java json sterilization and then secondly you can take a look at the well Shaped recipe for example so you can middle mouse point click on this there’s a crafting recipe and you actually have this available here somewhere if i recall correctly output from jason get item from a json object you have the civilizer so there you go so you have The read method the read method and the right method i cannot recommend this enough take a look at the uh the vanilla recipes as well to basically figure out how this all works or figure out the json civilization itself through java and then here we’re just sending the inputs and then making A new gem infusing recipe so this is of course one of one of our examples here in this case and then the read method and the right method are very interesting because we’re basically for the read method we’re just reading in the thing that we are putting on in the Right method so what does that mean well basically we’re taking the buffer over here we’re just getting the an integer this is going to be the size of our list and then we’re going to loop through this and we’re just going to say okay get me the you know the next ingredient Basically and at the end here we’re just getting at the output now how do i know that this is sort of a way to do it well because we’re also having to do the right method and you can see we’re first writing an integer and then we’re first Reading an integer and then we’re writing x amount of you know ingredients to this buffer and then we’re reading x amount of ingredients from this buffer and then lastly we’re writing an item stack which is the output and here we’re reading the item stack the order and the well i mean Things that we’re doing here has to match right so this is basically networking stuff if the packet buffer is off by i mean anything basically right if we add another integer and we’re not reading it or we’re writing something else or or we’re reading something that Doesn’t exist you will have an error now you might actually not get this error due inside of the environment here instead of the development environment this might actually only happen if you uh have a dedicated server and start it with a dedicated server so please keep that in Mind make sure that the write and the read method are basically well mirrors of each other okay and then we can actually go back to the normal class and just do some stuff here so this is just going to be type dot instance the serializer is got crazily enough serializer.instance The id is just the id the output is just um output.copy actually very important here it’s we’re just going to say true the craft method is just going to be the output and then the matches method is where the magic happens the first thing We have to do is we have to say world is client and then we just want to return false i’m not 100 sure why we have to do this i just know that that we have to do this otherwise it will crash on the server i Don’t know why it’s changed like in um i think 118 2 or something like that it changed for whatever reason i just found that this doing this basically i mean works so there you go what else does the mattress method do well it basically checks Or what you want to check in here is basically whether or not the recipe items are the same as the items inside of the inventory this means that we have a list of ingredients right here it’s ever only going to be one ingredient so basically we’re going to say recipe Items.get zero because this gets us the first ingredient remember arrays and lists and all of that start at zero and we want to test this against the inventory that gets stack of um from slot to one because we remember once again if we look at this This is going to be our input slot right zero one so this is our slot that we’re inputting our item into that’s why this is one this is zero because this is a different list right this has nothing to do with the with the inventory we’re basically getting the first item inside Of the list of our ingredients and this we want to match with whatever is inside of the inventory and if it does then we’re going to return true and then the mattress method is true and then we have a found a match for a particular recipe in this case That is the general idea the mattress method can get wildly wildly more complicated especially if you have multiple input slots and all of that in multiple input items um what i recommend here once again is just java knowledge if you have a sufficient java knowledge then this Should not scare you in the slightest right if you’re like i don’t even know what’s going on right now it might be worth going back to the drawing board a little bit because um you know especially when we continue along with this uh there’s gonna be so quite a few Things that are you know a lot more complicated than this right so just keep that in mind and this of course should serve only as an example to you so you have one particular implementation and then you can hopefully expand on this play around with this and hopefully be Fine with that let’s continue with the mod recipes method it’s actually not that complicated over here what we want to do is we just want a public static void register recipes method over here and this will just call the two things i’m actually going to copy this over because it’s actually Fairly straightforward you can see we have a registry register call of recipe serializers we’re making a new identifier of tutorial mode and then gem infusing recipe serializer id and then just passing in the instance here and then here we’re doing the same thing just with the recipe type Literally all that we need to do once again this is of course all available to you in the description below it’ll pass through an individual just as well and then we just call the mod recipes that register recipes down here and that should register the recipe as well now That is all fine and now the registry is reciproc that the registry no the recipe is registered there you go that way around however it’s not currently used in our block entity the block entity still uses our very crude method of literally just having a boolean over Here now how can we fix that it’s actually very straightforward this is why i’ve you know created this because it’s actually not that you know bad we’re just going to want to delete the uh the boolean here and instead we want to say optional of type A gem infusing recipe this is going to be the match this is equal to the world now we don’t have the world we can just say entity dot get a world dot get recipe manager this one right here and we want to say get first match of a particular recipe that is the Geminfusingrecipe.type that instance passing in the inventory as well as the world so this is once again entity.get world and there we go now this basically checks hey do we have any type of match and how do we check for a match we just say match dot is Present no math nope match dot is present there you go and that pretty much does the same thing now if this is true then the inventory that we have right so this one right here has found a match with any type of recipe of this particular gem infusing type that’s all That there is to it so is present match that is present is basically true if our matches method is true so that is why the mattress method is so important hello this is future counsel here with a little bit of an announcement it’s very important here that we actually do Change something else in the craft item method and that is actually we’re going to have to take the optional recipe here in here as well let’s just call this something like the recipe and what we actually want to do is of course here we still have this particular item stack in This case hard coded so we actually do want to change this so we can either say you know new item stack and then we can say recipe dot get dot get output you know item for example and then do something like this or you can also because of course the output here is Actually already an item stack so you could in theory also say something like this right so either one of those works i recommend doing something like this and then what you can also do is you can take the output itself instead of getting the stack that is inside of here Just taking whatever the output is and adding one to it so we can say get output dot get count in this case and then adding one to this as well so either way you know pretty much this should work as long as you have the correct item here and then if you’re not Reading in any count then that should be fine if you are reading an account then of course be sure to use the item stack that you’re using right here otherwise of course the count is not going to work so this is actually quite an important You know bit that you also have to do otherwise you will get regardless of the actual uh you know regardless of the actual recipe you’re always gonna get the tanzanite which of course is of course not something you want that is why this is quite important i’m gonna Give it back to a past count mojo where the code will probably change however this is the correct code keep that in mind and everything then should be fine um even more future account draw here before we get back to pascal there’s one more thing that we actually need to Change and that is in the can insert into items output slot over here because we still have the tens night right in here what we actually want to do is we want to say match dot get dot get output dot get item over here otherwise we actually once again It won’t work so keep that in mind as well uh so sorry for the for the weird um fixes over here but sometimes you know it happens block entities quite complicated so hopefully you can forgive me for that otherwise back to all comm joe and to the rest of the video and That pretty much is everything that we need to do in this case everything else doesn’t need to change we only needed to change this because we’re using the has recipe method we’re using it here as well so we don’t need to change this and that should pretty much Do everything you know on its own we now just need a json file let’s go into our data folder tutorial model recipes we’re going to right click new file here and that’s going to be the tanzan tan tanzanite from infusing or let’s call it gem infusing sure dot json And i will copy over the contents but they should be fairly self-explanatory you can see tutorial mode gem infusing should be nothing crazy right the gem infusion right here is the name right here let’s see this one right here and this one right here nope this one and this one Right those have to match that’s very important and then we have a an ingredient list so as you can see this is a json area or adjacent list and then we have an item that is the raw tanzanite and the output here is the item of tutorial mode tanzanite so we’re Basically going to get one tanzanite over here from one raw tanzanite that is the general idea let’s then see go into the game and actually see if it works all right francis in minecraft again so let’s just see so in theory i should be able to put the raw tanzanite in here And we should get the progress again and we should get a tanzanite out of it so that’s actually perfect and there we go and there we go we got a tenth night out of it exactly how you would expect it to so you might say well that’s literally The same behavior that we have before yes but now you can just create the json files and you can basically put any type of item in there and well it’s just going to interpret this for you it’s going to do all stuff for you and that is absolutely freaking awesome and that Would be it for this tutorial right here i hope you found this useful and you’ll learn something new and i’ll see you all in the next tutorial oh yeah Video Information
This video, titled ‘Minecraft 1.19.1 Fabric Modding Tutorial | CUSTOM RECIPE TYPES | #23’, was uploaded by Modding by Kaupenjoe on 2022-08-24 13:59:51. It has garnered 3494 views and 68 likes. The duration of the video is 00:15:03 or 903 seconds.
In this Minecraft Modding Tutorial, we are adding custom Recipe Types (and custom Recipes) to our Custom Block Entity in Fabric using Minecraft 1.19.1 (1.19.2 should work!)
== SUPPORT ME ON PATREON == ▶️ https://www.patreon.com/Kaupenjoe
== ASSETS & DOWNLOAD LINKS == GitHub Repo: https://github.com/Tutorials-By-Kaupenjoe/Fabric-Tutorial-1.19/tree/23-recipeType Gist: https://url.kaupenjoe.net/yt402/gist
== TIMESTAMPS == N/A RN
== 25% OFF FOR GAMING SERVERS == ▶️ https://www.bisecthosting.com/Kaupenjoe
== 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 *
== SUPPORT ME ON PATREON == ▶️ https://www.patreon.com/Kaupenjoe
== 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
== 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