Hello my name is vulgar and in this tutorial i will be attempting to give you a brief but in-depth description of how to implement your own custom block into minecraft using data packs and resource packs the advantages to using this is you can attach them to a world file nobody else Has to install anything and the code will work fine even if you upload it to a realm or a server that you are port forwarding if people download the resource pack then everything will look perfectly as well so what are data packs they are pretty much just a code that says anything that A command block can do a lot of tutorials out there do a really good job of telling you how to write the code and where to put it but in my opinion they’re a little lacking on why the code is written the way it is so i’m going to get into that So first things first you have to create your own model some prerequisites for this tutorial include blockbench i use it to create models and a simple knowledge of how to create resource and data packs even if you don’t put anything in them because the folder organization for them Is important for minecraft to read them so i recommend looking up some tutorials on that as i will be getting specifically in a custom blocks assuming you already know about data packs and resource packs so first things first you create your custom model as you can see i’ve done that here What’s important to note is that if you open up a model from a that’s already in the game and work off of that so if i go into models here any of these if i can open them in here i can export them as the same file type Even after editing them so i can open any of these json files if you want to know how to get these on your own i’m not allowed to redistribute them due to copyright laws uh and minecraft not allowing me to redistribute them because with these models you could Attempt to make the game for yourself without purchasing it but assuming you’ve purchased minecraft if you want access to any of these uh there’s two ways one is there’s a plugin in blockbench that will allow you to do this for entities but if you want the same for Any block what you can do is you can go you can in command prompt run percent app data percent you can navigate into your current version folder for minecraft my current 1.19 and then you can it should be 1.19.jar and then you uh copy it as dot zip so You copy it somewhere and then rename it.zip and then extract it using winrar or the default extractor on windows and what this does is it includes every asset in the game including all these model folders so these are json folders these are what minecraft uses to create models How to know the shape of a block and stuff like that what textures to call to so that it knows what that block will look like as well so you can open up any of these and when you do as you can see i’ve messed with the scaffolding In file you can export as a block slash item model what does this mean it means even after editing it like i have here clearly i’ve i’ve scrapped the top part of it it’s three blocks thick instead it’s not thick i can put my own texture on it um and edit it So as you can see i put my own texture on the top you know it’s a bit see-through it looks a little weird but the point is i can edit it however i want i can add another cube i can add another cube here and say like okay now This is part of it too you know now i have a little rod on the bottom whatever i do to it i can export it as a block slash item model and this will mean it exports as a json file that you can put into your resource pack Into the models portion of your resource pack or custom as i have put it inside of models and it will read like this it’s it’s something that minecraft can read and that’s really important because it means you don’t have to write any of this code in blockbench you can do all This export it and then you don’t have to worry about writing or editing any of this code it does the rest for you the only thing you need to do is make sure that whatever textures you did for it as well off to the side here i use default textures Any textures you use as well are called to a file and then at the top you make sure they’re called correctly which is something i’ll go into a second so as you can see uh i’ve made my own uh model for a cooking bench is what i’m calling it for now And then i exported it as a json file type has its own textures uh and then in the code it calls to it so because this is mostly done through blockbunch i won’t get too into depth but the general gist is uh these are all tags at the you know At the side uh the first one is textures and this pretty much says okay from now on for the rest of the file whenever i say these things so three particle side or bottom uh you will call to these files instead so anywhere you see a three it means What it’s really doing is it’s saying okay go to custom cooking bench top side and have that as the texture and anywhere you see side go to block slash scaffolding side so that’s the default texture in the game and for all of these portions so these Are all the cubes you created these here all the cubes you created in blockbench and here it’s saying okay for this side of this cube for these coordinates of the cube this is the texture we want to use for it so we call to hashtag side which we call up here this So that’s the gist of how these model files work uh they pretty much are responsible for what kind of pixels they take up and the textures that you call to for them i’m gonna take a sip of water real quick all right excuse me all right so that’s how these model Files work they tell you they call to different textures that you create again i’m assuming you know how to make your own resource packs so if i go into textures and then go into custom and go into cooking bench top side you can see that this thing we saw in black bench Was there and the model is calling to it the model is saying okay go to that texture and grab for cool face it’s saying grab part of it for this is saying grab all of it whatever all right so now that you’ve made your custom model Uh with the custom textures uh there are block bench tutorials out there if you do not know how to do that i’m not proficient enough with blockbunch to warrant the need for me creating the same texture but now that we’ve done our custom model and texture Let’s get into the files the the data pack files and so the resource pack files so as you can see here i’ve created this little data pack um i have the the code here the main things to know are you want to create in your functions a load and a tick And what do these do load means whenever you load up the data pack this code will execute uh if it were a command block it’s effectively saying we’re pressing a button it activates once when on load you know when it first happens for tick instead it’s happening every tick in Minecraft so i believe how minecraft works is every 60th of a second the game is detecting everything that’s happening and what tick does is says okay we want to execute this code every tick so every 60th of a second we do this instead of just once we want it to constantly happen All right so let’s go into my load file and kind of get a gist of of how tags work and what we’re doing here so the first thing is just to make sure my data pack is loading i have some uh tell raw what that means is we it’s typing Something into the text channel in minecraft so what we’re saying is telra and then anything at all players um anything in here and what does this mean uh why didn’t i just put text in there and say like call it pink whatever well the format for dot mc function files which Are what these are functions they run like command blocks requires these tags to understand what this is made of so i’m i want to tell everyone in the chat what do i want to tell them well for the text property uh which is if it isn’t obvious already This is the literal words that get displayed i have the text tag and then a colon that says okay whatever comes next that’s what the text tag is so text colon this and all of this stuff highlighted here will be the text tag which means in the Game it’ll show up as the text and then i put a comma and what the comma does it says okay now i’m going to start a new tag this next tag is going to be color and this is the color of the text the color i form is formatted in the form of Hash codes you can look up how that works but effectively if there’s any color you like you can look up what is the hashcode for that color so if i look up what is blue hashcode there are plenty of colors with the hash code attached to it so it Says here this is a good one this is an example blue the hash code for this is this which means if i copy paste this right here and i put it right here and that color will show up as the text in the game i have chose pink and purple Because they are my favorite colors uh just to make sure they work so though as you can see uh oh and we have one more tag here bold um this is a boolean type tag it means you put true or false after it uh true means it will be bold false Means it will not be bold that’s how this tag works so if i go into the game files and reload if you do slash reload it will load up all the data packs you have make sure all the code is working from scratch you can see that i put the text in there With the colors and the boldness that i wanted all right so now that we know our data effects working let’s actually get our item in the game so the gist the the general synopsis of how we create our custom block is we have a problem blocks cannot have their own tags which Means they can’t have their custom ids uh if i go into my texture pack here um into assets minecraft uh models so if i these are all items so if i go into bread right i have this this extension and what this does is says okay this is The texture we normally call for bread unless we give it this id if we give it this id then instead we call to this model and then we go into our models i see in custom we have this sushi model and then for the texture is something Different that i created it’s in custom sushi so if i go into textures because that’s what we’re calling from and then custom you can see that i have my sushi texture here that it’ll call from it’s really tiny but that’s what it looks like blocks cannot do this if you want to Retexture a block you can only do it with a texture pack and that means that all of that block is going to look that way so if you want a furnace for example that will only cook up fish then you can do that with a with datapack code but when you want to Retexture it it means every furnace will look that way even normal ones so you won’t be able to tell the difference between ones that are your custom one and ones that aren’t so how do we get a custom block in the game if blocks can’t have their own tags like this What we actually do is we create an item we create an item frame that has a tag and has any tags we want and then that item frame contains itself it contains another copy of it with the same texture except blown up to the size of a block So what we’re actually doing here for this custom block before i explain the code for it is i’m actually putting an invisible item frame here that contains the texture of this custom model blown up to look like a block and as you can see if i put on this glass it isn’t Perfect mine isn’t perfect mine’s a little too tall it’s centered but it’s a little too tall so as you can see it kind of digs into the block below it excuse the rain so what’s actually happening here is there’s an item frame that summons this model inside of itself and then blows it Up so that it looks like it’s the size of a block and it’s about the size of a block uh if you want proof of this you can see if i break here where the item frame would be that the custom model goes away i broke It i killed it and instead this block is left behind why is this block left behind well at the same time i summoned my item frame i also summoned a block at its position and the purpose of summoning the block was to say okay i Want a hitbox to work off of so if i set the time today so that it’s a little more clear you can see that i didn’t do this perfectly either if i put down this block and then put my mouse over it you can see that the icon the little highlight That goes along here for the hitbox isn’t the same as the block so if i hit here it won’t break but if i finally go here where the model for the scaffolding’s hitbox is then it is so what i really did here just to recap if there’s an invisible item from here that Contains an item that looks like this i made sure it looked like it was about the size of a block and if i go back into block bench you can see where i did that um this is in animations which i’ll just go into the scaffolding table instead i go Into display you can see okay let’s what does it look like in an item frame instead i want it to like be out i want it to be maybe out more and then i want it to be bigger so that it’s about the size of a block whatever So i and i can put it there and so i just effectively i’m faking it i’m saying there’s actually an item in here that’s about the size please don’t save this that’d be terrible that’s about the size of a minecraft block and i made its texture just big enough to cover The scaffolding underneath it so that it has a hitbox equal to scaffolding all right so now that i’ve gone over that how do you code this well the item in my hand currently is actually an item frame that contains itself and looks like this right so i Need to give myself an item frame with a custom tags so let’s do that in the load function that i have open right now let’s close the resource pack i give the nearest player i’m the only one in the world it’s myself this is just an example To show how to get the item if you want to create custom crafting you can for items like this there are tutorials on that as well but anyway so just to make sure it works what you should do is you should say i give the nearest player an item frame In this uh how is this item frame displayed i gave it a custom name cooking bench so just to prove that this is a cooking bench with that name if you can see here if i disable my resource pack it’s an item frame in my hand and when i put it down It hold it’s invisible but holds another item frame inside of it and then summon scaffolding on it and if i break it it deletes the item frame at the same time if i turn it back on you can see that it really was an item frame the whole time And it’s holding something it’s holding its own texture but in this case i’ve changed its texture how did i do this again in the code i gave it a tag after renaming it so that it says cooking mention my hand i gave it a tag separated by a comma that Says custom model data and then my my custom number two which means that when we want to look for the model it’ll go into this assets pack it’ll go all the way into models um first it says item frame right and it says okay oh we found this number so Instead we want to use this model instead custom slash cooking bench and this is what the item looks like in your hand or in an item frame if i go back to load so it’s calling to that unique type and then the next tag is entity tag So this is the entity for the item frame these are all the entity tags for the item frame first things first i made it silent so that when i place it it doesn’t make a noise because i don’t want to really give away that it’s actually secretly an item frame With the texture covering it i want it to look like a cooking bench with tags some again as i said boolean types true or false in minecraft 1b means true so if i want to replace this with true you can look at what these tags are but I’m just going to use true false for the sake of simplicity um if i set it just true and then save it and then reload my pack slash reload you can see that when i place it it’s still quiet it doesn’t make a noise that’s just what one b means in the tag Um why is it like that that’s just kind of the formatting for the code i don’t know why whoever came up with the language did it that way uh there’s obviously some reason related to computer parts whatever uh how they did it why that was the best way to do it Perhaps it has something to do about hexadecimal code whatever point is i made it silent and then i gave it some other tag and other entity tags um i gave it uh the cooking bench tag in case i want to call to it later i don’t have that anywhere so this isn’t Exactly useful now but it’s just like a unique way to give it a name inside of the code and then i said you know for this item frame i want to give it an item so the item type gives it an item and inside i gave it an item frame I gave one of it the count is 1b again there are different formattings you could put a 1 here it would work just as well but 1b is the natural way the code works so that’s what i have it set to right now and i gave you this custom model data so It is an item frame with this id that contains itself as you see here it was here too i initially said okay we create an item frame with this id and then inside of it we give it an item that again is the item frame with this custom id but Outside of all these entity tags so this is these tags here are the any tags for what’s inside of the item frame or sorry inside here these tags are what’s inside the item frame right so then i said okay now that i have this item frame that contains another item frame and They both have this custom id and this custom id will instead link to this custom texture and it’s custom model i need to make the initial item frame invisible because if it’s not then there will be a little item frame connected at the bottom if that wasn’t Invisible as you saw when i uh disabled the resource pack it was holding an item frame but if that initial item frame is invisible this item frame right here would be visible and we don’t really want that and as you can see if i break it just to Prove there is the item frame there the custom model goes away and only the scaffolding is left so um anyway i made it invulnerable so that it cannot be destroyed um clearly i failed there i was breaking it as uh but i am in creative so never mind that makes sense Uh i guess i should test that huh so i have it here let’s check that that enrollment will tag work slash game mode survival let’s say i want to break it you can hear me hitting it but it’s not breaking if i do this it breaks and that thing goes away So the item frame is there but it’s invisible in invisible and invulnerable so perfect it’s working how we want it to uh i made it fixed this fix is its position this is kind of just like a safety thing uh and then i also set facing if The reason i did this is because it’s an item frame right so if i place it on the side of a block it will not face straight up it will instead face to the side facing tag for item frames ensures that it will always be facing up as you can See here when i mouse over it’ll tell me the direction the item frame is facing so if i as the user want to put like an item frame here because i want to attack like a block right and if i put a block here Then it’ll just place it next to it so i want to do the same thing even though it’s an item frame so facing it up forces it to look like a block that faces up all the time so that’s what that tag does if you want to know what all these oh And then i gave a one at the end outside so that i only give myself one if i put three here instead and save and reload slash reload i have 19 in my inventory right now you can see it gave me three instead i’m now up to 22. So let’s go back down to one just for my own sake because my inventory fills up really quick and reload give me one again that’s how that whole tag works so this makes sure that it works the whole purpose of this code right here the give is making sure that i’m calling The right item and all my models and textures are connected and it acts and behaves like a block um if you want a better knowledge of tags and how they work there is a wiki for it on the minecraft wiki these are all the tags so my color Picker open let me get rid of that it’s a lovely little tutorial as you can see here when i click on blocks there’s barely any tags so most of them don’t work they only work on blocks as items what does this mean it means if you’re holding the Block this is what tags work so it means uh this can only be placed on certain things uh they only work as an item in your hand when you actually place down the block it no longer has any tags that’s why we have to do this really weird Process of summoning an item frame with an item frame in it because blocks do not have their own tacks if i scroll back up and i go down to item frames or armor stands they’re also really good you can see it has all these different tags rotations invisible fixed uh Determine how the item frame works all right so one thing i did not test that i just noticed from looking at the tags is if i right click on that item frame will it rotate the model and no it doesn’t that might be what fix does if you’re worried that isn’t how it Works then you can set that with this tag here this item rotation make sure you know set it to the number you want and it will be one of the angles all in a circle you know how to spin things and how things spin in an item frame Uh but to continue with the code to make sure your block works fine um now that we’ve created this invisible item frame in which a a fake uh scaffolding is placed inside of its texture so that it has a hitbox and it works we want to make sure that um We can actually break it break it and it will remove the block and we can place it and it will summon the scaffolding so in the tick what do i do i have two uh two commands here one uh execute as makes it so whatever your command is it Will execute as whatever you put next so execute as at e means at every and then in this little thing i decide at every what so this is i’m executing command and i’m pretending that the game is pretending that this at everyone is going to do this command and Then these things in the square brackets determine who i kind of narrowed down who that everyone is so instead of executing as every entity i only want to activate this command as every item frame and only if the tag equals cooking bench uh as if we go back to uh the Item as we said i gave it this cooking bench tag that’s where this kind of kicks in uh if the tag is cooking bench and if the tag equals placed this is a custom tag that determines whether or not the block is currently placed down or the item frame Sorry is currently placed down uh if it’s an item frame called cooking bench and has a tag that is not placed the exclamation point in code means not it means whatever you’re saying after is the opposite so equals placed would say okay if it’s place equals exclamation point place Means if it’s not equal placed so i’m executing as every entity that is an item frame with this name with this tag that is not currently placed and then where are we executing this command at i believe slap i should look up what slash s is just to Make sure i don’t accidentally um educate you improperly at s minecraft target selectors at s is at the entity executing the command so this means we want to uh as every item frame that is that has these tags we want to activate at that item frame This command so if i instead put at 0 64 0 that’s the coordinate that this command would happen the next thing we put is the command so everything before this is where the command is going to happen so execute as every entity that is an item frame with these tags At all of those entities we run the following function so my current data pack is called love i am running a function inside love and then i’ve created a folder so called cooking bench in which i put down a place function and this is a command I did the same thing for remove it does the same thing but triggers a different function when you want to get rid of the block so what does it do it says execute as every entity that is an item frame with these following tags that has cooking bunch and is placed not not Placed but is placed and then execute the following command at that entity which is every item frame with these tags unless the block at that current position that these are coordinates they mean current position if you put one here this would mean one block above your current position if i Replace this with a 64 that means at your current position but at a height of 64. um if a scaffolding is there run this function so let me let me rephrase that execute as every item frame with these tags at all of those item frames unless the block at the position is a Scaffolding run the following function all right so let’s go into these functions first and this i created a folder that had these files what is the place function the first thing i do is i put a scaffolding there and then i call it placed so what does this do This is why there’s a little scaffolding inside because it detects it pretty much acts as a hitbox for the block all i did was i i created an item frame here it’s invisible right now and i put a scaffolding there to act as the hitbox that’s all it does And i called it placed so that i know if i break it in the future and i click on it in the future and it’s placed i can break it so what does the remove function do the remove function will first of all summon the custom item this is effectively the Same thing as what i put in the load it is the custom item with the custom ids it only gives one of them um so that when i kill the scaffolding here with the item frame at that position it will drop the unique item frame that’s what that code does the next Thing i do is i kill the the the scaffolding there the next thing i do is when i click on here i kill the scaffolding because if i set this down for example i try and click on it and break it and i don’t kill the scaffolding a scaffolding item will drop So the tick that you break this right because there is a fake there is a scaff oh let me clear the weather so there is a scaffolding here that acts as a hitbox right well if i don’t include this part of the command here the scaffolding item will Drop i can i can prove that right i can go into here i can comment this out that means the code is there but it doesn’t actually do anything that’s how a comment works make sure i save everything so let’s reload slash reload if i click on this position and break it A scaffolding should drop with it it might be because i’m created game mode survival oh yeah yeah so because i was creative it just destroyed it automatically as you can see a scaffolding will break with it now so we need to do a command that only drops the custom item and not The scaffolding that is the acting as the hitbox so that’s what this code here does so if i reload the code and i try again you can see that scaffolding no longer drops with it and then the last thing is we want to kill the item frame that Is there we want to get rid of the item frame is executing this command right because we don’t want an item frame to remain there that’s what that last thing does but kill at s is a way to say slash kill the entity that is executing the command So it’s kind of a way to say kill itself if i was to type that in right now it would kill me the player so that’s what it does uh just to let you know i do have a comment here call for armor stands because uh initially i Was summoning an item an armor stand within it but i’m no longer using that has nothing to do with this tutorial there are advantages to summoning item frames in things if you want to do right click detection which i plan on implementing the point is this part this little code Here is not necessary for your thing it’s just a comment this little green text you can get rid of it it doesn’t do the same thing all right so just a synopsis the tick function is happening every tick every 60th of a second um every sixteenth of a second it is detecting It is executing these commands and it’s saying okay if something’s uh has the not placed tag or is place tag execute these functions um so every single function is saying okay we see that you put down an armor stand here or uh sorry an item frame When i right click here the game is saying okay i see that you put an item frame here with the custom id so because i detected it because i detected that there’s a placed one uh i’m going to summon a scaffolding there and call it placed so that when you break it Uh so that when we detect that you try to break it because the tag equals placed here we can execute the remove function and i go to the remove function and we say okay we get rid of the item frame with all those unique tags then we kill the scaffolding item that Will drop from it then we kill the item frame itself that was holding the unique texture so that is a recap of how to add custom blocks how they work um and why they do it this way just to go over my thoughts on this process i think the coding language for commands Is nice i think it allows for a lot of customization but it does have the glaring problem of how complicated it is if the developers simply allowed blocks have nbt tags which they didn’t probably for other coding restriction i’m not saying they they are incompetent or anything obviously they’re not they Created this whole game uh the coding for this would be so much easier uh i don’t know if we’ll ever get that kind of functionality so this is the way to do it for now with uh item frames in other tutorials you may see methods where they do invisible armor stands That are wearing a helmet block and then you scale that item or a helmet as an item and then you you lower it and scale it to the size of a block instead of doing the same thing with an item frame there are plenty of tutorials out there I just wanted to give an in-depth one on how the code worked so this is my attempt at providing one i hope it helps anybody if anyone has any questions or suggestions on how to change this video i’d really appreciate it this is my devlog on how i’ve been doing Creating it uh it’s been extremely difficult initially i tried to create custom crops that’s a whole nother mess that i’m going to try to figure out and get into but yeah that’s my tutorial for now i hope it was useful if you have any questions you know please feel free to comment Video Information
This video, titled ‘How to Add Custom Blocks to Minecraft (1.19) and How the DataPack Code Works: Devlog#3’, was uploaded by Volgadorf on 2022-07-07 00:55:26. It has garnered 4302 views and 107 likes. The duration of the video is 00:34:33 or 2073 seconds.
I hope this is especially useful to those who know nothing about code and want to get started.
In this video, I primarily (and not-so-concisely) explain how the code to add custom blocks functions and why it must be this way. This is meant to supplement other tutorials and focus mostly on addressing confusing parts of how to code.
Timestamps: 0:00 Why is this tutorial different? 0:51 Creating the Block in BlockBench 4:41 How the Model File Works 6:38 Explaining the Datapack Files Code Syntax 10:00 Coding the Block into the Game; Why so Convoluted? 16:48 Explaining all the Tags 23:45 Initializing the Placement and Removal of the Block 28:03 Finally Coding what Happens when We Place and Break the Block 33:06 Personal Input. This System Kinda Sucks No Matter How You Do It
For other very useful tutorials including alternate methods and links to code generators, I highly recommend these tutorials as well:
https://www.youtube.com/watch?v=LUx9FqJpxQk&t=2s&ab_channel=TimberForge
https://www.youtube.com/watch?v=ENK0b_2yT1c&list=WL&index=16&t=351s&ab_channel=CloudWolf
Other useful links:
Blockbench download https://www.blockbench.net/downloads
Coding Generator for Syntax https://mcstacker.net/
Browser Texture Editor (No download necessary) https://minecraft.novaskin.me/