All right techies episode eight of my minecraft modding tutorial series for version 1.19 and in this episode we’re going to be going over block states and block rotation so block states are essentially way a way of having different variants of a block sort so block states you can see them just like Tags by going into the f3 screen i’m just going to make this bigger so you can see so i can see if i look at these are all slabs there’s we can look at the block states which is just here above the tags you see the tags the ones with the hashes in Front of them you can see here we have uh type and water lock for slabs so you can see we have type bottom type top and type double so a block state can change the way a block looks so uh so it it can change the way the block Looks but can also not change at all and just be used for code so it can always be accessed by the code but it cannot also but it can also change the way it looks using the block state json so you see here we have the note block and this doesn’t change The look when i click it but you can see actually the note here is changing which is a block state property but it’s just not changing the way it looks now the reason we’re doing block states at the same time as rotation is because rotation also uses block states you’ll See here we’ve got facing east we have facing north we are facing west facing south and then there’s also ones like facing down and stuff like that but uh block facing uses block states and it’s also probably the best way to show off uh how to use block states in a Very simple way later on we may use certain block states like power to make redstone things just like this observer has but that can be that gets a bit more complicated so what we’re going to be doing is prefer we’re just going to make a simple block that is going to rotate When we are facing a different direction when we’re placing it we’re going to be doing it in this episode with just horizontal rotation so something like what can only rotate a lectern that can only rotate unless you can’t change you can’t change up and down uh but there is also Obviously you can make an observer face different directions and then obviously at some point you can start getting onto more advanced block states like this where you can have a different we can have different types so for here what we’ve done is the slab is actually has a block State saying that is the of type bottom and then the block state json will use a certain we’ll use a certain model uh for that type so to start things off i’ve added firstly a block model now this is a bit different to the ones we’ve normally used but we’ve parented Off of the cube all this then we’re paranoid off of orientate or orientatable vertical so what this does is rather than just having one texture of sort of an area we can add which is just we’ll do all of the faces there’s actually three we’re only using two here um But we there can be three i believe now for this one the side will just go on the top but you can also do top and then add your texture but for now it’s just going to do the same as side but we also means we have the front so What this will do is it will mean that we have different um it means that we can have diff different textures for different faces so on the front face which will be the north face normally this is going to have uh the um furnace top uh yeah this is going to have the That should be you know we want the so we’re going to have the that should be the side and then we want the space to be like this so the front face is going to be the the dispenser vertical texture i’ve just gone off of the minecraft textures the default Minecraft textures and then all of the side is going to be the same as the furnace so what this is going to do is it means we can have a block that can rotate round with this i’m not going to be adding any functionalities to this block i’ve Literally just called it rotate block this is just to show that it we can rotate blocks and then i’ve also added the item model as that is just the same as normal parenting of this block model and then i finally just added some language file to this Now you’ll see i haven’t added a block states file because that’s what we’re going to be doing now so uh before we’ve just done variance uh so we’ve done variants as we always have and then we’ve just done an empty quotations and then the model So we will write our block states in an ear a bit later but for now what what we see here is uh so we have the variance and what this is is showing every different block state so what we can do is here what it’s saying is just ignore Any block states doesn’t matter what the block state is uh these conditions well what’s gonna have to say what it actually is saying is these conditions to be met but we haven’t met any conditions into it’s just always gonna go to this model but we could put in that we want the Block state of facing so we have facing equals west and then we would do the west model uh or we could do facing east and would do the east model but for the like the sapphire block which is this one we don’t want any variance but what we’ll do for our rotate block Is we can actually do that now i guess so we can have our rotate block json and so we can have our variance and so for now um we’re going to have our facing values so obviously if you have different block states some block states if you don’t Want it to affect the look you would leave it out just like we did for here you would have nothing in here or you could just have the block states you want to affect so we’re going to have four we can have facing equals north Uh and this is going to open up and that’s this is going to be our model uh but let’s just add all of them for now so actually so we actually want our model and this is just going to be tutorial or mod and then block And rotate so the way to this model now obviously we don’t want to have a duplicate model for every single model so for everything all facing even so facing north facing south facing east and facing west so rather than actually creating a different model what we can do is we can Actually do more values inside these brackets so for facing south we can have another value and this is going to be y so what this is is it’s how much we’re going to rotate it on the y now we can only do it in increments of 90 so 90 80 and 270 but That’s what we need to do so facing south obviously we’re going to rotate it 180 degrees because this fit is this main one we don’t have to do anything for the north one because it’s already facing north for the south one it’s going to be opposite so we’ll rotate it 180 For the east one we’re going to be rotating it 90 as it is going clockwise uh if you’re looking down on it so the east one is going to be knighted we’re going to be rotating 90 hp and then for the west one we’re going to Be doing 270. so what this is going to do is for each of these variants it’s going to rotate it now if we will to load up a block right now with this block state it wouldn’t be able to load a model because it has no because we don’t have A facing block state in the block that we would load up to right now it wouldn’t know where to go because it can’t use this one because the condition isn’t met facing north and the same goes for all of these three and then it goes well we don’t have a block state can’t Do anything so it would because what it’s looking for is one like this where there’s no condition because there is because for that block there’ll be no block state so let’s create that block now uh one thing i’d also like to mention is let’s see i don’t have any textures in here because I’m using the minecraft textures so that is just by rather than putting tutorial and then the colons or your mod id in front of this i’m just leaving it blank or you could do minecraft and this just means that we’re taking it from vanilla rather from our textures So into the java code now to actually register the block we’re going to be doing this a bit differently we’re going to be using giving its own class so anyone with a basic knowledge of java could probably guess how we’re doing this with object-oriented programming and stuff like that so we’re just going To create a new package with blocks and in here we’re going to create our rotate rotate block plus and then this is going to extend block and so we’re going to create our constructor and these are just the properties properties and then for now we can quickly initialize this so We can do the same as normal we can create object and then we can call this rotate block and then blocks register and so again it needs to register your name so road rotate lock and then where we’ve done uh so rather than now rather than doing new block we can just do New rotate block and this app because this has the same constructor it’s the same thing we’re just taking in the properties and just now i’m just going to copy off of a blocks dispenser because there’s no need for me to make any properties for this and then the block Item is exactly the same as these other ones uh just because a block item is the same no matter what so we can do row rotate block item this can be detect rotate lock this and then i’m gonna this is gonna go in the mod stops um tab So we’ve registered that and now we actually need to create property so so what we can do is we can actually look if we want to at some of the previous um some of the vanilla stuff just so we can see what’s going on so let’s say we have a Electron that’s a good one electron block so what we’ve got is we can see here we have to create this um block state we have a variable here well constant which is our actually our block state so uh you can see we’ve got a facing property it also has powers property for The lectern and all this other stuff um and then so what we can do is we can go into our rota block and we can create our public static and this can be our direction property basin phase and it’s gonna equal horizontal directional block facing so This is to give us our facing property and so now we need to actually add this to our block states so we can do is create block state definition so this builder so what this is going to do is we can do builder dot add basic and so Basically what we’ve done here is we’ve created our variable for the facing and then we’re just adding it to the block so we’re registering it to the to the blocks well all the block states that it has so if we were to load this up now which i actually will do we can Go into the f3 screen and i believe we can have a look to see that it will be registered we went and the model won’t work though and obviously we won’t be able to change it okay so one thing that i had forgotten and sort of not realized is you do You do need this top uh so i’d left it out but you do need the top so i’m just at the top to be the same as the side uh and also the model is actually gonna work because we do have if you see we have our block state here uh facing north Um but it is defaulted to north and it will not change from north so you see if i’m facing if i place it it i’m indeed facing towards me and if i face that way it is facing north but that’s just because of where i was standing whichever way i Stand and place it it will always face north and this is because we have not made it so that it actually changes the block state so the block state is there we just need to make it change so the first thing we need to do is we Need to do get stateful placement and obviously this is going to set the state of all of the block states there’s gonna support the citizen set when it’s blocked when it’s placed so overriding this from the block class and we can do this return this dot default block state uh dot set value Of facing to be context dot gets nearest looking direction and one of you don’t get opposite because obviously the knit third looking direction is actually the direction the player is looking uh and then obviously we want it to be the opposite version because we want it to be facing us It is going to be dot get dot opposite so the next thing that we’re going to need is we’re going to need our rotate method so we’re going to do rotate and that is the wrong one we want to make sure we get the this one Um and we’re gonna do we’re gonna return um the state so this is state rotation so we’re gonna do return state dot set value to be facing and then rotation dot rotate and we’re going to do the state dot get value basing so this method is basically Just going to get pulled from where you want to whenever we want to rotate it and it doesn’t it’s just going to rotate it so the final method we need to actually rotate it is the mirror method so we’re gonna we have our state and we have our mirror so we’re going to Do i’m going to return state dot rotate mirror get rotation state dot get value facing and so that is all of it so firstly we have we have our block state and then we have our get state so the actual block state uh wires things whenever you whenever You do any block state you have to have the actual block stick variable obviously and then you have to remember to add it otherwise you will get an error and then you need to you need to be able to put the state for placement and then these are the two methods are Just for rotating it that is just specific for rotating it you don’t so whenever you do anything else if you have another property you might have a custom property we can go over that another episode and what you might do there is you might um you might use that just somewhere nor in Your code um and then that you won’t see anywhere you won’t need these rotate methods but you will have be adding it to the to the block state and you will be setting what it is when you place it so now if we actually run this what we Should see is we should be able to place this block with it rotating okay so one quick thing we did wrong is rather in the get stick replacement rather than get nearest looking direction that’s going to also do up and down we don’t want that we want to get horizontal Direction uh if you do nearest direction you will get an error thrown in the console um because it will try to because it will try to do it in the wrong direction that it can’t use uh but now that we’ve done that this should run and we should be able to Place that block in all the different directions so now in the game i have our rotate block and we can place it in all the different directions and it will face the way that we’re facing uh so obviously doesn’t have to be rotating your block state it can be anything but That is all we’re going to do in this episode if there’s anything you want me to cover in future episodes make sure to leave it in the comments and i hope you got what you came for cheers Video Information
This video, titled ‘Minecraft Modding Tutorials 1.19: Ep 8 – Blockstates and Block Rotation’, was uploaded by Relaxing Leg on 2022-09-19 15:59:31. It has garnered views and [vid_likes] likes. The duration of the video is or seconds.
This is the eighth episode of my minecraft forge modding tutorial series. In this episode we will be creating a block with blockstates …