Let’s take a look at block state properties all right we found ourselves back in intelligent once more and in this tutorial we’re going to be looking at the difference between blocks and block states and then diving into block state properties a little bit and for that we’re going to break out the craziest Tool ever and that is of course indeed powerpoint now what we have is a little bit of a presentation so i’m just going to go through a few things and the example block that we’re going to use is basically the redstone ore block because that is probably the easiest example That there is in minecraft or the block state properties and we’re going to look at the class in just a moment but first let’s go through some theory so the general idea is that the block class in itself is a singleton pattern what does that mean well it basically means that We have one field for one particular block when we go into our mod blocks class or when we go into our blocks class in vanilla we can see that for example for the redstone ore block we create one field and that is always going to be the only place where we have This new redstone ore block we can have maybe a different variant does exist but overall we only create one field for a block now you might say well but there are multiple blocks in the world if i set down a redstone ore block and then i Set one down two blocks next to it then we have two different blocks how does that work well those are block states and that is actually a very very important distinction here we can think of a block states as block instances inside of the world so block states Actually save the position some block properties so those would be the properties that we actually assign when we’re creating the block so the the block behavior properties and then also the block state properties which we’re going to see in just a moment now the block states they are basically saved by The world and they can also only be changed by the world or the level and this usually happens on the server so this is done by you doing level dot set block and then passing in some parameters now the block state properties what are those exactly well We can see the very well let’s say shortened version of the redstone ore block as an example here we have a boolean property called lit and this is just equal to some already defined boolean property here and we define those properties in a custom block class And we do need this create block state definition method to be overwritten that is very important and this is actually all that we really need as a general summary for block state properties they always have a value so they can never be null block can have multiple different properties So we’ve seen this with the stairs as you can see with the stairs and with the doors for example now it’s also very interesting is that the values of those block state properties can then be refers to in different model files so basically what that means is that We’ve seen the block says json file for some blocks that refer to different block model files depending on the values of their block state properties and that is really the power of this so in the redstone or example right here this is lit false so this is le true so We’re basically only lighting this up it’s not the craziest thing but it is still pretty cool that we can basically change the appearance of the block based on the block state property and you have to do it with a block say property you can’t just add a boolean Just a boolean variable to the block because of course this block here right this redstone or block is only created once but if you had a boolean inside of it and not a boolean property what would just happen is that for every block that exists in the world So every redstone ore block in that case would light up at the same time and that’s of course not what you want in this case that is the difference right the difference is between having the block state property which is only applied to the particular block seed so The particular block in front of you and not all of the ones that have the same type how do we change block states well we change block states by setting the block at a particular position right so we have to basically get the world and then we change the this at the Particular position and then we’re setting the value of a block state property to basically well a particular value and then the three here is just a particular flag for the updating behavior that’s pretty much all that there is to it the presentation is available as a cheat sheet in the Description below as well so you can take a look at that and then basically go through this one more time if you need to but for the time being we’re going to switch to intellij and what we’re going to do is we’re going to press the shift key twice and then we’re Going to search for the redstone or block right here and we’re going to double click on this and there we are so we can see right here we have the boolean property lit and it is of course used in well a few moments here but what Is important for us is first of all right here so the create block state the definition method you can see that the lit property is added to the builder right here this is extremely important this has to happen and then we can also see for example in the random tick right Here you can see a level set block at a particular position and then we’re setting the value of lit to false in this case and then adding the flag 3 in this case so we can hover over this and we can actually see what the flags mean usually it really doesn’t Matter for us at the moment three is the one that we really want to have basically all of the time and this is all still a little bit well i wouldn’t say necessarily esoteric but it’s very much just theory so how about some well actual implementation that’s what we’re going To do so we’re going to implement a sort of lamp that we can right click and then we can turn it on and off so in the custom package right click new java class and this is going to be the citrine lamp block and this is of course going To extend the block class there you go and i’m going to hover over this create constructor matching super and if this annoys you then you can just click on it press shift f6 and just change it to properties right here and then let’s add the boolean property clicked so we’re Just going to say public static final boolean property hold clicked and this is equal to boolean property dot create with the name clicked and then end this with a semicolon that’s it now of course we need to overwrite the create block state definition method right here so we’re just gonna Auto complete this with a tab and then we’re gonna say pbuilder dot add and then we’re just gonna add the click property there you go and that’s it then now this lamp block if we were to create it now has the click property associated with it now at this moment in time we’re Not actually changing it so how we’re going to change it well we’re going to use the use method right here this one and what we’re going to do is we’re going to say first of all that we’re going to return the interaction result success right here and then beforehand We’re going to just make this a little bit nicer to read there you go and i’m going to say if not the level is client-side and the p hand is equal to interaction hand dot main hand then we’re going to do some stuff but once again this is very Important here that we use not is client side so we’re going to put a exclamation mark in front of his client sides to negate this and then we’re going to say this is only done when we right click this with the main hand and then we’re just going to say boolean is current State is equal to pstate dot get value so this is how you can get the value clicked so this simply gets the value of this particular boolean property and then we’re just going to say p level dot set block at this position so this is the position that we’ve clicked the Right clicked the state dot set value of clicked and this is going to be not current state so we’re going to negate current state so basically just alternating between the two so when you right click and the current state is true then we’re going to set it to false and if it’s false We’re going to set it to true or should be pretty self-explanatory all things considered and not too crazy now they sit during lamb block of course we still need to create this in the mod blocks class now let’s just copy over the winter window and let’s just see what we Can do so this is going to be the citrine underscore lamp and of course for the name as well this is citrine underscore lamp and this is going to be a citrine lamp block now what we’re going to do is something very interesting first of all this is going to be a Property of let’s say material material.metal and instead of having the no occlusion what we’re going to do is we’re going to say first of all like strength 2 requires tool for drop and then let’s say we don’t have any sound yet but we have a light level so this is going to Be an interesting one so the light level right here you can see it takes in a two-in function of block state now a lot of you might say what the freak is a two-in function it’s not actually that crazy it basically is a supplier but instead of just having empty parentheses We have something in there so we can say state then we can do this and now we can use this state to determine what we’re going to return and a to in function when we think about it well it probably wants an integer returned and that is Exactly right so what we can do is we can just say 15 and in this way now we’ve created a lamp that is always going to be on but we actually only want this to be on when the state is true what we can say is we can say state dot Get value citrine lamp block that clicked and then we’re going to use the ternary operator to return 15 if this is true and 0 if this is false and with this we’ve created a right clickable lamp that is only on when well the actual lamp is on basically that’s pretty much All that we need to do for the block now the block states of course are what’s also interesting but let’s first of all add the translation just so that we have this of course this is always something that i might just forget so i’m just going to copy this over there you go Of course all of the code is also available to you in the description below get a repository and individual adjusts as well and the citrine lab block states let’s just copy this over and you’re gonna see ah this now makes sense because we have a click property that can either be False or true we’re basically looking at a different model so we’re looking at the citrine lamp off or citrine lamp on and those are just two different models which then point to two different textures that’s actually how easy it is and this is a completely custom one in This moment so this is completely custom you can of course make other custom properties here so if i for example middle mouse button click on this and then i believe i can press ctrl h on the property there you go you can also make integer properties or enum properties as Well so in theory you could even make completely custom properties that would also work but usually those three or you know three and a half let’s say different types of properties should be more than enough to well create sort of a block that you want to And let’s just go and copy over the two block model files as well so this is going to be in the block folder of course and there you go let’s just copy those over and you can see these are now completely normal block model json files they just point to a particular block Texture and then there is only one item file because of course in this case the item model file just points to the off texture in this case or the off lamp which points to the off texture and then let’s also get the two on and off Block textures over here as well and we can actually take a look at those as well just so you can basically see this is the off texture this is the on texture just a second there you go so of course there is quite a difference here when the actual light level also changes You know the difference becomes a little bit more contrasted even more so there you go but that is pretty much all of the things that we need to do but the really important thing is that we don’t forget the create block state definition method this is one of the most important Ones and you can basically expand this however you want to once again you can take a look at things like the door for some examples right we’ve seen the block state json file is pretty crazy so if we for example say door block right and then we’re going to go into the door Block you can see there are all of the properties that we’ve basically seen now this is far more complicated than for example the redstone or block this is why i said the redstone ore block sort of is the perfect example to see because it doesn’t have all of this clutter that Is you know look at this freaking craziness i mean this is that’s a lot but what you can hear see is actually very interesting if you have multiple properties you can just add them like this into the builder so that’s pretty cool and like i said always go to the External libraries take a look at some of the classes that might have some properties it can just help you out and it’s the best one of the best resources basically for everything we’ve added all of the things that we need to add so let’s see if it works or we of us back In minecraft and as you can see the citrine lamp has been added to the game and let’s right click it and you can see it works perfectly fine just like we would expect it to you know all of them work independently of each other and They give off a nice light here and this is pretty much the general idea we can also just take a look at the redstone or block just for the you know just for the sake of argument you set it down and i right click this you can see now it is Also giving off particles and also a little bit of a light glow here so you can see this is pretty much the idea of the block state properties pretty cool all things considered right block state properties overall is a very interesting topic quite important for a lot of Things as well so i can highly recommend it just playing around with this a little bit being open to experimentation the best thing to do just try and work with this i can also highly recommend maybe taking a look at some github repositories for popular mods to get a Feel of how because they use properties in even more interesting ways and yeah that’s pretty much the idea here right but that would already be for this tutorial right here i hope you found this useful and you learned something new if you did or 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 special golden thanks go out to mc arctic for actually supporting me with The gold block tier and i’ll see you in the next tutorial so Video Information
This video, titled ‘Minecraft Modding 1.18.1 with Forge | BLOCKSTATES EXPLAINED’, was uploaded by Modding by Kaupenjoe on 2022-03-05 14:59:50. It has garnered 5313 views and 129 likes. The duration of the video is 00:14:34 or 874 seconds.
In this Minecraft Modding Tutorial, I explain the concept of Blockstates 🙂
== ASSETS & DOWNLOAD LINKS == GitHub Repo: https://github.com/Tutorials-By-Kaupenjoe/Forge-Tutorial-1.18.1/tree/24-blockstates Gist: https://url.kaupenjoe.net/yt231/gist Textures Zipped: https://url.kaupenjoe.net/yt231/textures Cheat Sheet: https://url.kaupenjoe.net/yt231/cheatSheet
== TIMESTAMPS == 0:00 Intro 0:18 Blockstate Properties Theory 4:37 Looking at the RedstoneOreBlock Example 5:42 Adding the Custom Block Class 8:12 Registering the Custom Block 9:58 Adding the JSON Files 13:03 Demonstration 14: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