Let’s take a look at block states all right we find ourselves back in the challenge more and in this tutorial we’re going to be talking about block state and block state properties so block states of course we’ve already seen the json files for the block sets If i were to for example take a look at the jumpy block block states json file over here we can see that we have variance but we just have an empty variant this was the standard block states json file for a normal block let’s say and there are also blocks that Have different variants that point then to different models the best example to take a look at is actually the redstone ore block so what we’re going to do is we’re going to press the shift key twice and search for redstone or block this one right here so let’s just click on This and then we can actually take a look at this block what’s very interesting here is that it has a static field over here called lit that is a boolean property and this is exactly the thing that we’re going to need to add because there is a difference between a Block and a block state and this is a very important difference for you to understand the block class represents the idea of a block while the block state is the actual block inside of the world meaning that for example if we go down a little bit we can see in this Light method right here world dot set block state it’s not called set block and even if it was we still need to pass in a block state because that is the actual instance of this block inside of the world because if i set down two redstone ore blocks they are both Redstone or blocks but they are different blocks right the bit different instances of the same thing so that is why there are block states and blocks and these block state properties basically allow us to add properties to the block states and not the block this Is why you can’t just add an integer to this block class in this case and it would work that actually wouldn’t work because the integer would actually be shared across all block states in the world that are of this block type so that is why that doesn’t work and that Is why we need to use these properties over here now the best way to actually try this out is to just make something ourselves so in our custom block package we’re going to right click new java class and that’s going to be the tanzanite lamp block there you go and This will extend the block class let’s hover over this create constructor matching super and now the first thing we want to do is we want to add a new property let’s just add a public static final boolean property this one right here for net minecraft state property called lit And this is equal to boolean property.of and then passing in a name that is going to be called lit over here and that is all that we need to do and this is how easy it can be to actually add a custom boolean property or a custom property Anyway because if we actually middle mouse might click on this i believe what we can do is we can then click on the property press ctrl h we can see there are boolean properties there are enum properties and there are end properties so those are basically the things that You can save in block states you know together with those you can create all sorts of different variants of your block and what we then have to do this is very important when you add a prop property to your block you need to call the append properties method and then do Builder dot add and add the block state property inside of the builder so this is very important to do this otherwise it’s not going to work and now we can basically change this property here and then by changing it we can then refer to a different model which we’re going to See in just a moment in the block states json file but we can then refer to a different model so we’re going to overwrite the unused method again this is the method that we when we right click it we actually do something and we’re going to say hey if we are not on The client so if not world dot is client there you go and and equals hand dot main hand then what we’re going to do is we’re going to say world dot set block state at the position that we’re at and then we’re going to say state dot cycle lit What does that all of this craziness do well this should be fairly self-explanatory right we’re only doing this on the server in this case and then also we are only doing this with the main hand please note the exclamation mark here in front of the is client meaning that we’re negating its client Meaning we want to be on the server not on the client because we can only set block states in on the server which should make a lot of sense right you don’t want if a client connects to your server you don’t want that client to just be able to set blocks to anything That they want right they could just be like oh diamond block diamond block diamond block and then all of a sudden you know the economy of a server crashes because everyone can just set any block to diamond blocks that is why this has to happen on the server and then the State cycle here simply cycles through the possible values of this particular property now because it’s a boolean property there are only two possible values true or false so this simply means that we’re changing it from true to false or from false to true that is basically what the cycle does and that Is actually all we need in this class so let’s just create the actual block here as well let’s register it so this is going to be the tanzanite underscore lamp and then same thing right here in the register block tanzanite underscore lamp now this is going to be very Important once again a new tanzanite lamp block over here and then this is all fine i want to add another method call on the fabric block settings and that is the luminance over here what we’re going to do is put in state and then an arrow and then we’re going to Return the following we’re going to say state dot get tanzanite question mark 15 colon 0. now this might be absolute insanity to you right you might be like i don’t even know what is going on here well let’s first of all go through this is a two-in function of Block state this simply means we have a block state over here and we want to return an integer that is all that that means and what we have is we are saying okay the state of this particular block right so we’re getting a block state if that is Lit right so if this is true then we want to return a luminance value of 15 meaning that we want this to shed light at a strength of 15 so light level 15 and if this is false so if the actual lamp is not lit then we want to return a Light level of zero that is all that’s happening here so nothing too crazy when you really think about it right continue along and now how does the block state json file looks like well let’s just copy over the one from the tanzanite block over here drag it into the same Folder while holding ctrl and we’re gonna rename it to tanzanite underscore lamp and if we then take a look at this well we of course now have different variants over here right so we have maybe a lamp block that is on right and then let’s just press ctrl d to Duplicate it and then we have one that is turned off right so those are going to be two different model files but we somehow need to we’ll say what are the variants here well the variant is just lit equals true when we want the on texture to be shown and then Lit equals false if you want the off texture to be shown or rather when we want it to point to the different model but usually in the different models you want to change or point to different textures that is the general idea now you might ask where does this come from Right this lit well that is actually what we have defined over here so this name right here has to match the name inside of the json file right here and then that should be fine let’s add the translation as well this is just going to be the tanzanite underscore lamp and Then of course right here as well tanzanite lamp and then in the models the block model files i will actually copy them over now those are just normal block model files they are not any different than the other ones you can see they just point to one texture with Cube all they are just named in a way that when we actually let’s close a few things over here right so they just named this one right here so tanzanite underscore lamp on inside lamp on and then points to a tanzanite lamp on texture and then the same thing for the Off one you can see tanzanite lamp off points to a different texture and it’s called off and this is exactly the block model file that is referenced right here when it comes to the item model file well this one of course once again needs to be named after the actual block but It points to the lamp off block model file but the block that appears in the inventory actually looks like it’s off let’s add the textures over here as well there we go and that should be pretty much all that we need to do to add this So it isn’t that crazy now of course there are examples of blocks that have an insane amount of different properties right so i can recommend you can of course look at this click on block press ctrl h and then you can see all of the blocks now the redstone ore block i Really recommend looking at this a little bit more because this is let’s say fairly easy to understand because it only has one block property if we were for example to look at something like the tripwire hook you can see there are three different properties and voxel Shapes and all of the craziness this is why i you know i don’t usually recommend going into into every block some of them are quite complicated but yeah the redstone or block is probably the best vanilla example to look at this otherwise you can of course also look at Some other vanilla examples as well whatever the case may be let’s enter the game and see if it works all right we find us in minecraft and let’s see there we are the tanzanite lab has been added and if i set it down you can see we have A texture and it is also emitting light and if i right click it you can see the texture changes and the light turns off as well so that is pretty much and that’s how easy it is to add a block with different block state properties for minecraft and that already concludes This tutorial right here i’ll be found this useful and you’ll learn something new and i’ll see you all in the next tutorial so yeah Video Information
This video, titled ‘Minecraft 1.19 Fabric Modding Tutorial | BLOCKSTATES EXPLAINED | #8’, was uploaded by Modding by Kaupenjoe on 2022-07-04 13:59:48. It has garnered views and [vid_likes] likes. The duration of the video is or seconds.
In this Minecraft Modding Tutorial, I explain what Blockstates and Blockstate Properties are! == MINECRAFT COURSES …