Hello and welcome back to another tutorial in today’s episode we’re going to be covering data generation which will allow us to automate the creation of some jsons we’re going to be automating block states language item models and block models for the assets as well as tags recipes and loot tables For the data so let’s begin by creating a new package right click on our main package and go to new package and let’s name this data gen inside this package let’s right click and create a new class and let’s call it tutorial data generation next we want to annotate this Class with an event bus subscriber so that we can register our data generators when they need to be registered let’s add a at mod dot event bus subscriber and press ctrl shift o to import at mod let’s set the mod id to be our tutorial Mod dot mod id and that set the bus to be equal to bus dot mod let’s once again press ctrl shift o to import bus and now we can register our generators let’s create a public static void called gather data and this is going to take a Gather data event event and in order to make sure that it’s run we need to annotate it with an at subscribe event next let’s get the data generator so let’s do data generator generator is equal to event dot get generator and then we can check if event dot include client And then here we’re going to do client data generation and we’re also going to check if event includes server and here we’re going to do server data generation so everything in here will be our resource pack generation and everything in here will be our data pack generation so let’s start with our block State in our data gen let’s create a new package called dot client and in here let’s create a new class called mod block state provider and this class is going to extend block state provider and we want to make sure to use the net.minecraftforge.client.model.generator let’s hover over this and add a Constructor let’s rename gen to generator we can remove the mod id and change the existing file helper to just be helper then over here we can change the generator to generator the helper to helper and the mod id to our tutorial mod dot mod id next let’s hover over This and add unimplemented methods which is going to add our registered states and models and in here we’re going to register all of our models and block states so i’m going to start by creating a simple block and this block is going to be block init Dot example block dot get and all this is going to do is generate a simple block state for our example block and you can see there’s other things that you can override including configured models and custom model files but we’re not going to do that in this video Otherwise it’ll be very long now we need to register our mod block state provider and we can do that in here in our include client we can write generator dot add provider and then we just pass in a new mod block state provider this is going to take our Generator and and file helper so to get the file helper let’s create a new existing file helper called helper and set this equal to event dot get existing file helper now i can just pass that helper into here and there we go now we’ve created a model and block state for our example Block and if you want to add more you can always add more lines over here for different blocks you can also change the simple block to be a function of your choosing but i’m just going to leave this as simple block for now next let’s cover item models in our clients let’s Create a new class called mod item model provider and once again this is going to extend item model provider we can hover over this and add a constructor once again we can rename this to the helper remove the mod id change this mod id over here to tutorial mod dot mod id And this bit over here to just be helper now i can hover over this and add our register models however i’m going to create a couple of custom methods which will help us over here which aren’t included by default so let’s create a protected void called simple block item And this is going to take an item item and then we’re going to do get builder and then we need a path so we can do item dot get registry name dot to string and then we can do dot parent and here we need to pass in a model file so here We’re getting the builder for the item and then inside that item model we’re going to need to define a parent and our parent is just going to be the model of that block so now we need to get the model of the block and to do that we use Get existing file now we just need to pass in the file for our block and that’s going to be mod location so that’s using our custom mod id of block slash plus the registry name of our block so that’s item.getregistryname.getpath and remember that in this case our item Is our block because all blocks are actually items but not all items are blocks now let’s create a protected void called one layer item which is going to be our default model for all our items and this is going to take in a item and a resource location for the texture we Can press ctrl shift o to import resource location and then we can create a new resource location for our item texture and this is going to be a new resource location with texture dot get namespace comma item slash plus texture dot get path and that is the resource location of the texture which We’re going to need to use in the model and now we’re going to check if this texture exists so we’re going to do existing file helper dot exists then we pass in our item texture and we’re going to type pack type dot client resources then we need the Extension of the file that’s a dot png and we’re going to search in textures since this is a texture and if it doesn’t exist we can just do system.out.printline texture form plus item dot get registry name dot to string not present at item texture dot to string and now over here we’re Going to do something similar to what we have over here so we can just copy paste this to get our builder except now instead of converting it to a string we’re going to do dot get path and then we want to set the parent to minecraft item generated So to do that we can do parent of get existing file and then we do mc lock since this is a minecraft model and then we can do item generated and that’s going to set the parent now we can set the texture at layer 0 which is the main layer To our item texture and now we’ve created our one layer item next i’m just going to make the exact same method so one layer item but this is only going to take an item and all this is going to be is to call one layer item again with the item and Item dot get registry name now in our register model we can call all of these things so we can do simple block item for our block init dot example block dot get dot as item and then we can do the exact same thing for our rotatable block and now we can do Our simple items to do that we’re going to create a one layer item for item init dot example item dot get and now we’ve created item models for our blocks and item models for our items and if we compare what this does to what it makes We can see that we’re first getting the builder for our item then we’re setting the parents to a minecraft location of items generated so that’s this and then we’re adding a texture at layer 0 with our item texture and that’s this variable over here and a similar thing is happening for our Simple block item next let’s create a language provider so in our client i’m going to create a new package called lang and then i’m going to create a new class called mod en us provider and you’re going to need to make a new provider for each language that you Choose and this is going to extend a language provider and then we can hover over this and add all of this in instead of the mod id and the locale mod id is going to be equal to tutorial mod dot mod id and the locale here is going to be en Underscore us since this is our mod enus provider then we can hover over this and click add to add our translations and now we can add our translations for literally anything we can add blocks and items as keys so for example we can do add item so we can do item Dot get init.exampleitem.get then set that equal to example item we can also do similar things for blocks by just changing this over here to block init dot example block dot get and this to example block also in our lang file we have item groups but you can see that they aren’t actually here In one of the methods so we can just do add we can do item group dot tutorial mod which is the name of our item group in our landing json and we can set that equal to tutorial mod tab so just as you can use this default stuff you can also create Your own keys next let’s register our item and language provider in our data generator so let’s do generator dot add provider new mod item model provider with generator and helper and then generator dot add provider with new mod en us provider and there we go now we have data generation for our client Next let’s move on to the server let’s start with recipes so in our datagen package let’s create a new package called dot server and then in here let’s create our new class called mod recipe provider and this is going to extend recipe provider let’s hover over this and add a constructor This is going to take a data generator called generator then let’s overwrite build crafting recipes and this is just going to take a consumer and we don’t need to call the super let’s start with shaped recipes so let’s do shaped recipe builder dot shaped And then we can pass in an item as the result so let’s say this is going to be our example item then we need to set the keys so we can define a character with an ingredient so for example let’s define the letter a as block init dot Example block dot get dot as item and we want to make sure to use single speech marks here since this is a character let’s now define another character which is going to be b and this is going to take tag init dot items dot cool items Which means that b is going to accept any cool item now that we’ve defined this we can now add our pattern and to do that we just add pattern and to do that you can picture our shapes recipe over here so the first line of the Pattern is going to be this the second line is that and the second line is the third one and i explained how this works in the last episode so i’m going to say the first line is going to be aba and the second line is going to be bab and The third line is also going to be a b a you can use the save function to finally complete this recipe and to do that you’re going to need the consumer passed into the function and the resource location and this is going to be a new resource location of tutorial mod dot Mod id and then the name of the recipe so i’m just going to put the output of our item as the name for the recipe so iteminit.exampleitem.get.getregistryname.getpath and if you want you can add something onto that for example underscore hello and now that’s going to use the registry Name of the item underscore hello as the name of the recipe and you can use that to stop conflicting but i’m going to remove that for now next let’s create a shapeless recipe with shapeless recipe builder and then let’s do dot shapeless now we need the output And if you want multiple items you can always add a number after this so this is going to give us 10 example items this shapeless one is going to give us example blocks so let’s do block init dot example block dot get dot as item And this is going to give four of them if you only want one you can just not have a number over here all you need to do to shapeless recipes is to add ingredients and to do that you can do dot requires and then you can once again Pass in anything that you like these can be blocks items tags etc so i’m going to say that to make our example block we’re going to need three example items so iteminit.exampleitem.get so i’m going to need three of those and then i’m going to need one diamond so let’s do items.diamond And there we go now we need to save that let’s do dot save and this is exactly the same as before so this is going to take a consumer and a new resource location of tutorial mod dot mod id and then we can give it a name so i’m going to do blockinit.exampleblock.get.getregistryname.getpath And that is our shapeless recipe so now with three example items and a diamond we’re going to get four example blocks finally i’m going to briefly show a cooking recipe so let’s do simple cooking recipe builder and then we can do a blasting campfire cooking or smelting or even smoking I’m just going to do smelting over here then we pass in the input and the output so i’m going to say a block init dot rotatal block dot get dot as item can smelt into a item init dot example item dot get however this first bit has to be an ingredient so we Can do ingredient dot of and then put this bit into brackets then we give it the experience so let’s say one experience orb and the cooking time so let’s say 200 ticks remember there are 20 ticks in one second next we can save that with our consumer and a new resource location Of tutorial mod dot mod id and the name of our output but here as you can see the recipe name will be the same as our first one so on the end we can add underscore smelting just so that they don’t conflict but you don’t have to do This if your recipe names are going to be different next let’s register our mod recipe provider so back in tutorial data generation we can go here and do generator dot add provider with new mod recipe provider and pass in our generator next let’s create block and item tags providers so Let’s create a new class called mod block tags provider and this is going to extend block tags provider then you want to hover over the error and add the constructor that has the mod id and the file helper let’s rename the data generator to generator delete the mod id And change the existing file helper to just helper then over here we can do the same thing change the mod id to tutorial dot mod id and change this to just her next we can override at tags we can delete the super and in here we can add Our tags in here you can create a new tag and then you pass in a block tag so you can do tag init dot blocks dot cool blocks and then dot add and then add as many blocks as you want so for example if i want to add a acacia Button to that i can do something like this and then if i want to also add my own block onto that i can do block init dot rotatable block dot get and i can just chain these on to create my tag i can also do that with a default Minecraft tag so i can do tags dot blocks dot dot and i can say that my rotatable block is actually a dirt and that’s it for our block tags next let’s create a new class called mod item tags provider and this is going to extend item tags provider And then we can hover over this and add the second constructor which has a file helper now we can delete the mod id but here we also get a block text provider let’s do generator blocks and helper and then rename the super stuff to generator Blocks to real mod dot mod id and helper now once again we can overwrite at tags and this actually works in the exact same way as before so you can do tag of tags dot items dot barrels and then add stuff to the barrel tag so that i can say my Rotatable block is a barrel however this is a block so i need to use as item here since i’m making an item tag now let’s register this in our data generation class however we’re going to need to store our block generator somewhere so over here we can do Mod block tags generator and then we can do block tags is equal to a new mod block tags provider and then we pass in the generator and the helper and now over here we can do generator dot add provider and then we can add the block Tags and then we can do generator dot add provider with a new mod item tags provider with generator block tags and helper finally let’s do our mod loot table providers let’s create a new class called mod loot table provider and this is one of those moments where we’re just Going to have to copy and paste some code this is quite a big chunk of code because unfortunately a loot table provider doesn’t exist properly in forge but this loot table provider is going to be the same for every mod that has loot tables so don’t worry About changing stuff there will be a link in the description and this original code was made by mcgitty so in my datagen package i’m going to create a new class called base loot table provider and then i’m going to copy and paste the code and you want to make sure To leave this class abstract and then we can press ctrl shift o and import the log4j logger the minecraft data provider the world item the java path the minecraft block the log4j log manager and java util map and that should fix all of the errors in this class Now we can save that and in our mod loot table provider we can extend our base loot table provider then we can hover over this and add a constructor which just takes our generator so we can rename that over here and then we can hover over this and add Unimplemented methods which is going to add tables now in the add tables function we can add our tables let’s create a simple table with our block so block init.exampleblock.get.getregistryname.getpath and in here we’ll just pass in block init dot example block dot get we can even simplify this by creating a protected Void drop self which will take in a block block and this is just going to do create simple table with block dot get registry name dot get path and block and now instead of this we can call drop self and pass in block init dot Example block dot get we can also do the same thing for our rotatable block or we can do a silk touch so let’s create a silk touch table with glock init dot rotatable block dot get dot get registry name dot get path next we need to pass in the block so That’s our rotatable block dot get next it’s the item that we drop if we don’t still touch it let’s do item init dot example item dot get next is our minimum value with fortune so let’s say one and a maximum value of let’s say four finally let’s add this to able provider Into our tutorial data generation so let’s do generator dot add provider new mod loot table provider and then pass in the generator and that is actually it so i have completely gotten rid of our lang so i’m just going to delete this lag that we have in my block state provider I created a simple block state for my example block so i’m going to delete that in my item model provider i created item models for all of the three item models that we have so i’m going to delete all the item models that we have we’re going to leave our textures we’re Going to leave the minecraft tags for our loot tables i’m going to delete the current block loot table that we have we’re going to leave the recipes and we actually set the cool blocks but not the cool items so i’m just going to remove this line for cool blocks and then keep The tags and in our recipes class we forgot to add criterion so what we can do is do dot unlocked by and then add a criterion so we can do has underscore plus lock init dot example block dot get dot get registry name dot get path and for The criterion we’re going to put has and then we need to pass in an item so we can do lock init dot example block dot get dot as item and we can do the same thing over here but this time instead of using that we’re going to use our example item Like so and we can do the same thing for the cooking recipe this time using the rotatable block and what this criterion does is unlock this recipe when you have this item in your inventory and let’s just fix our base loot table provider let’s create a public void called add And this is going to take a block block and a loot table dot builder builder and all we’re going to do here is do loot tables dot put the key and the builder now in our loot table provider in drop self we have to do is add block Colon and then the rest of the function and then down here we can do protected void silk touch and then we can do the block block the item silk int min and int max and what this is is the block that it drops so it will drop itself Otherwise it’s going to drop silk so now we can do add lock colon and then we can copy all of this and paste it in here then we can change the rotatable block stuff to block here and here we can change this bit to silk this to min And this to max and then over here we can add silk touch with block init dot rotatable block dot get and the item that it drops when it’s mined with fortune is iteminit.exampleitem.get with a minimum of four and a maximum of one now we need to actually run our data generation to Do that we can click the drop down next to the run button and go to run configurations then we can select run data and click run and then when those are complete you have to go to source generated resources right click on that and click refresh Now we can run client this video is sponsored by mtxserv mtxserv provide game server hosting for games such as minecraft rust and valheim the servers are incredibly performant with a amd ryzen 5800 x and unlimited ssd storage space as well as ddos protection and all Of this for a pretty low price use code cy4 to get five percent off your server today so now if we start the game we can see that all of the language files and the names of the blocks have loaded properly we can also see that the loot tables Have worked so if i use silk touch on my rotatable block i get my rotatable block and if i use fortune on it you can see that i get a couple of my example items also in my crafting table you can see that i have a shapeless recipe with Three of my example items and a diamond to make for example blocks i can also use my example blocks with any cool item remember that’s my example item or a diamond to make 10 of my example items and finally i can smelt one of my rotatable blocks To be an example item and this gives me one orb of experience that’s going to do it for this video if you need any help join the discord and the link for the data generation code is in the description if you like my overall content i just opened a kofi so you can Go donate to that if you’d like to in the next episode i’ll probably start covering tile entities containers and guis thank you for watching and i’ll see you next time You Video Information
This video, titled ‘Minecraft Modding Tutorial 1.18 | #4 – Data Generation’, was uploaded by Cy4’s Modding on 2022-03-20 13:09:49. It has garnered 11467 views and 249 likes. The duration of the video is 00:26:44 or 1604 seconds.
hallo, i made a kofi, links are all below 😀
(ɔ◔‿◔)ɔ ♥ ~ expand me
C://Links/ BaseLootTableProvider: https://github.com/Cy4Shot/Modding-Tutorial-1.18/blob/main/Useful%20Resources/BaseLootTableProvider.java
C://Ko-Fi/ Buy me a coffee 😀 https://ko-fi.com/cy4modding
C://Help/ Discord: https://discord.gg/x9Mj63m4QG Or comment on this video!
C://mTxServ/ Get your server today! https://mtxserv.com/ Use codes cy4-3, cy4-6, cy4-16 and cy4-32 for 5% off!
C://Source_Code/ https://github.com/Cy4Shot/Modding-Tutorial-1.18
C://Time_Stamps/ 00:00 – Intro 00:20 – 1. Asset Generation 10:35 – 2. Data Genration 24:55 – mTxServ.com 25:18 – Testing 26:09 – Outro