Hello hello hello everybody and welcome back to another minecraft mining tutorial for version 1.19 in this tutorial we’re going to be covering block entities so this is the start of what i will consider a mini series where we are going to be trying to create a crush out block this will have A gui a container custom recipes all of that fancy stuff so let’s go ahead and get started so i’ve already done the basic stuff of creating a block i’ve got a customer class of course because we’ll need that and i’ve done the assets as well so let’s jump straight into our block Now the first thing we’re going to want to do is implement entity block and this will allow our block entity to um essentially be a block entity so we’re going to want new block entity and get ticker now before i continue with this i’m going to briefly explain what a block entity is As some people may not be aware so block entities essentially allow us to both store data and to be able to perform something every tick with our block additionally it allows us to do something like a block entity rendering which allows us to do special renderings such as Rendering an item on our block rendering a fluid something like that or you can use it for things like energy storing items storing fluids all of that fancy stuff which we will be covering soon so with these methods let’s quickly just go ahead and rename some things so this Depos this is the state this is the level soon we will be switching to parchment um instead of these horrible parameter names but for now we’ll just put up with this so okay we’ll do new block entity first so for this we’re actually going to need to Register a block entity so let’s come into our init package and let’s go a new class and we’ll do block nt init okay and we’re going to want our usual public static final deferred register of type block oh type block entity type and this will just be uh of wild card And then we’ll just call this block and support entities and that will be equal to deferred register dot create forward registry stop block entity types and then our mod id and before we forget let’s go ahead and register this in our main class constructor so block entity init dot block entity dot Register and okay then let’s just create a block entity so we’re going to want a public static final registry objects this will be of type block entity type and in here we’re just going to put a block entity class which will be a crusher block entity and i’ll just call this crusher It’s equal block entities dot register crasher all of this should be fairly familiar to you by now as we’ve done this thing many many times we’re just going to do block entity type dot builder dot off and then we’re going to do crusher block entity colon colon new And then it’s we also need to supply the valid blocks and this is just a list of blocks that this block entity will be valid for so we only want our one block and that is the crusher but say you wanted it to be valid on a Different block as well you could have multiple blocks in here so you could say blocks dot dirt for example um but we’ll just stick with the crusher for now okay and then after that we just want to do dot build and pass in no okay so let’s go ahead and create this Class we’re going to want a new package for this so we’ll do we’ll just call this block entities and in here we’re going to want a new class this will be our crusher block entity extends block entity okay fantastic and we’re just going to add the constructor now straight away let’s rename these Parameters so we’ll go pause and be state and we’re going to remove this first parameter and just pass in to the super block entity init dot crusher dot get there we go now if we come into here we can just import that class there we go And that’s gonna tell us it doesn’t like that but that’s fine that’s not an issue and fantastic so we can now come into our block class again and we can do block entity init dot crusher dot get and then you can just call dot create and pass in the pause and the state There you go alternatively you could do just a new crash or block entity however i prefer to do it this way just in case you know i i don’t know it just makes more sense to me to do it this way it’s not completely hard coded and then we’re going to basically we’re Doing the same with the ticker so i should mention you only need this get ticker method if you intend your block entity to do something every tick if you if it’s not going to do something every tick then you can just completely just get rid of that method you don’t need it But our block entity is going to be doing something every tick so what we’re going to do is we’re first going to check level dot is client side and if it’s client-side we’re just going to say no now if it’s not client-side we’re going to want to add this functional interface here And rename these to their respected things so this is a level as this first parameter so we don’t actually need this so i’m just going to do dollar sign zero and then this is the pause now we actually do want this this here this is the block state so we Can just do dot sign one we don’t want that and this is the actual uh block entity so we’re going to want that one okay and all we need to do is say if um block entity is instance of our block entity class so pressure block entity and i’ll just call this crusher Then all we need to do is do pressure dot tick there we go now if we come into our crusher class we can just go ahead and create this tick method that’s a public void tick there you go and you’ll see that works perfectly fine okay fantastic so We actually don’t need this pause so we could just do dollar sign one for that and dollar sign two for that one well actually can we no okay fantastic so that’s pretty much all we’re going to need we are going to want to override the use method but that will Be more for a future tutorial so i’m just going to quickly go ahead and rename these and we’ll cover the actual uh use in possibly the next tutorial we’ll see so this is the level and this is the pause the player and the hand and finally the hit result there we go Okay we’ll just leave that there for now so now we can come into our block entity class and we can do whatever we want so you have this tick method you are free to do whatever you want in here so if you want to access the current uh level You can just do this.level if you want to access the current block position it’s just this dot block pause or the stopworld they’re the same thing um if you want to access the state you can just do get block state Yeah and that’s pretty much all you would really need yeah so from there you can really do uh whatever you want if you want to save data in your block entity which you’re probably going to want to do let’s say you want to have a field here so private int progress Right and you’re probably going to want to save that progress so let’s go ahead and say um let’s just say in our tick method we do progress plus plus if progress is greater than and we’ll just create a quick constant here so private static final um into max underscore progress We’ll just say if it’s equal to 100 so let’s just do that okay so if it’s greater than max progress then we can just say progress is equal zero and then i don’t know you could um do something so like this.level dot add fresh entity a new Uh pig entity maybe a new pig and just give it the stop level i don’t know what it takes okay so the entity type so entity types dot pig and then uh this sort level right and that’s actually not going to work because we haven’t set the position so Let’s just quickly do our pick let’s equal that and then picked or set position uh this.worldposition.x just upload position.y and this.wordposition.c and then just add a pig and you would now have that so basically that would mean uh every uh that’s fine that’s not to be null just ignore that But that would mean essentially every 100 ticks is going to spawn a pic right um and you may want to save that progress for when you leave the world and come back you may want to save it so to do that you would just override the load method And also the save additional method so just quickly go ahead rename these so that’s the nbt and that’s the mbt okay we’re gonna still want the super.load ideally put that back in and all you’d need to do is something like this dot progress is equal mbt.getinteger or getint progress And when you save it you just do nbt dot put int progress let’s stop progress and boom you’ve now saved some data and we can actually go ahead and test this i suppose um because that’s pretty much it that’s all i kind of wanted to show in this Tutorial in the next one we’ll probably be doing storing items in here but can i please get rid of this error or warning because it’s wrong uh okay well i guess what i can do if level is equal now then just return not that that it should never be null But intellij is just being a little bit silly so if we do now go ahead and run the game we should go ahead and see that it should spawn a pig essentially every 100 ticks so let’s go ahead and test it all right so here we are got my crusher Block out as you can see it’s a professional texture as usual and if we place it down we should wait five seconds and a pig spawns obviously it’s going to spawn inside of the block because we haven’t made any adjustments for it to do otherwise but that’s going to happen every five Seconds and you should see right so that’s that was about a second there that the past so if we load back in we hopefully should see and we don’t have a way to properly confirm this right now but if we go one two three yeah there you go so it’s about right It’s safe essentially and that’s just gonna keep killing them isn’t it i don’t know why i can’t hit them oh there you go So yeah that’s going to be pretty much it for this tutorial however in the next tutorial we’ll probably be covering storing items um either that or syncing to the client but that will probably be in the future tutorial uh if it would make more sense there So yeah i hope you guys did find this tutorial useful if you did please do be sure to smash your face into that like button and subscribe if you really enjoyed please do be sure to share it and uh yeah i’ll see you guys in the next tutorial good bye Video Information
This video, titled ‘1.19 Minecraft Forge Modding Tutorial – Block Entities’, was uploaded by TurtyWurty on 2022-09-08 16:30:01. It has garnered views and [vid_likes] likes. The duration of the video is or seconds.
Hello everyone, in this video we will make a block entity that ticks and saves and loads data. In the next video we will be covering …