Hello hello hello everybody i am 30 worthy and we are back with another minecraft modding tutorial for forge 1.18 in this show we’re going to be covering something which is extremely fun and that is block entity renderers so first let’s talk about what they are and then we’ll talk about how we can Make one so a block entity renderer is essentially a way that we can render something using our block entity and yeah they’re fantastic they’re very powerful they are used by for example the beacon to render the beacon beam they are used for the enchantment table and the chest for their animations And they’re used for a few other things as well so how do we how do we make one you ask and to make one is actually extremely simple it could not be any simpler so what we need to do is we obviously need a block entity to Be able to do this your block entity doesn’t necessarily have to do anything it just has to exist so i’ve created this block right here which has this block entity is extremely simple stuff and there’s literally nothing happen happening here it doesn’t even tick because it doesn’t need to tick Now there’s one thing i’m going to do so the thing is with block entity renderers they are very specific on what you want to do um so you might want to do something different than what i’m trying to do and so this whole process might be a little Different so i’m going to try and explain as much as i think makes sense so i’m going to be doing is i’m going to be creating a block that will render the item that is in the player’s hand i don’t know why it’s stupid and useless and it’s just a Good example i think of rendering something and i’m actually not going to have a model for this block i’m actually going to render the model inside of the block entity renderer and that’s so that i can show you how to render both a block state and an item stack Both which are very simple by the way so since i’m not going to be having a model we need to tell minecraft not to try and load a model for this block and the way we do that is in our block class we can override a method Now i don’t remember what it’s called because it changes name all the time um it might be render shape but it’s probably not render shape it’s probably something like see if we can find the method that is used for this okay let’s try to get render shape i’m Not sure what render shape is other than the fact that it’s an enum ah yes render shape is what we need so what you’ll want to use if you’re rendering the model yourself is entity block animated and we can just rename this here to state there we go And fantastic so now we can close both of those with we don’t need those again the next thing you need to do is let’s go ahead and just create the block entity renderer so in our renderer package i’m going to create a new package for dot block And in there i’m going to create a new class i’m going to call this display and now these names can get quite long by the way so display hand block entity renderer you can see that’s quite a long name now what i often do is i reduce that down to display hand bur So bur standing for block ends t renderer it’s a little bit easier to understand and all this needs to to do is extend in lowercase of course block nc renderer um which of course is not called that is it okay let’s look at block entity render rows and that should Tell us what they are so for example the sign oh you implement it right of course of course you do so you don’t extend it you implement block entity renderers renderer not renderers there we go now that will ask for the unimplemented methods which is the render method And this first takes in our block entity now we can provide a generic for this block entity renderer which will take in our block entity so we can use our display hand block entity and that way we can pass that into our render method now let’s go ahead and rename some of These parameters so first we have the block entity of course then we have i believe the partial text then we have the pose stack which i’m going to name stack then we have the multi buffer source this is just the buffer then we have these two integers now i Often get these the wrong way around however i believe it’s combined overlay and then packed light i believe but that might be the wrong way around so now we can render something you can render whatever you want so i’m going to show you how to render both a block State and an item stack let’s start with the block to render a block let’s first go ahead and um let’s get an instance of the block entity renderer so we need to do minecraft.getinstance dot block renderer get block renderer and that gets us a block renderer dispatcher And we can make a field of that so i’m gonna call this dispatcher great and we can do dispatcher dot render and you’ll see there’s a bunch of different random methods you can render a liquid etc i’m going to render a single block and you’re going to want to use the Second one with the i model data on the end because this one above i believe is deprecated yes it is um and we can use the other one that’s fine so render single block now this first takes in the block state and yeah that’s just whatever you whether But whatever block you want to render so i’m going to just be rendering blocks dot glass block oh not black stained glass just just glass glass okay and the default blocks date of course great now it’s already put in the other parameters for us so as you can see Um it’s put in the post stack the buffer combined overlay packed light and it’s put in null for the model data that’s because it doesn’t know what that is that could be anything so what we need to put in for the model data is empty model data dot instance And there you go you’ve now rendered a block i’m actually going to test this first before we go ahead and try and render an item since we can do it as we go along we don’t need to do it all at once so first we actually need to bind this to Our block entity since currently our block entity has no um knowledge that this exists in fact it shouldn’t have any knowledge that this that it exists only this should have knowledge to the block entity either way we need to bind them so let’s come into our client mod events And in the entity tutorial we created this register renderers event right here and if you haven’t made that already you will need that for this and what we can do in here is bind it so this event isn’t just for entities it’s also for block entities so you can do event dot register Block entity renderer then you can pass in the type so block entity init dot display hand dot get and then you can pass a block entity render up provider so that is just block um what is that is display and and that does not work because it’s looking for something else okay what’s That looking for let’s see a block entity renderer provider and that takes in a context right of course so we need to create a constructor that takes this in so let’s come into our display and block entity renderer let’s make a constructor and let’s pass that in so this is the Block hence here under provider.context we can just pass in the context and we don’t need to do anything with that context i don’t believe um however we can actually use this context to get the block renderer dispatcher so actually yeah we will use that that should be quite useful um unless there Is a getter in here which already has it no there’s not so that’s that’s actually quite useful so private final and we can reference the context here and that way we can set the context in the constructor and instead of getting this reference to the minecraft class down here we can do this Dot context dot get block entity renderer or get block render dispatcher that’s it i don’t know what the block entity one is for what does that allow us to do oh that’s useful so that allows us to render an item okay i didn’t know that existed that actually Um will save us a little bit of time great so let’s set that down there fantastic so now let’s come back into our client mod events that error now goes away we can run the game just one quick thing i’m going to make sure i do Is i’m going to do the lang we do still need a block state if we’re going to do things like this and we’re still going to need an item model as well that hasn’t changed okay the item model is where things get a little bit confusing because it’s not quite the same so Since i’m not using a json model for for this block um we can’t really have an item model the exact same way so i’m going to create the json in here for the item model and i’m going to close display and just go ahead okay now what i’m actually going to do is I’m going to get rid of our tutorial mod prefix and i’m just going to say block 4’s last glass that way it will just use the glass block model and just for safe keeping maybe we can just put minecraft colon block forward slash glass just in case okay let’s run the game and Let’s see if it works hello everybody as you can see we are now in the game let’s get rid of our poop storage that’s from the last tutorial and as you can see we have our hand display which looks like a glass block fantastic that’s how it should look now If you place it down it looks like a glass block which is great because that’s exactly what we wanted now to prove that we are rendering this um differently let’s come into our display hand and let’s change this to something so let’s change it to an acacia door It now renders an acacia door fantastic now okay to prove it a little further let’s try translate the stack so let’s go stack dot push post all right let’s change it back to glass and we need to pop afterwards of course stack dot pop pose and let’s do stack dot mold pose Let’s go vector three f dot y n dot rotation degrees let’s go 45 degrees and you can see it’s now rotated obviously it’s translated since its center of origin is a little whack but you can obviously fix that by sort of translating it first so you do stack.translate um How do you do it it’s like negative 0.5 f zero negative zero point five f is that right positive anyways you you can you can mess around with that uh how you would want to mess around with that i’ve forgotten how you uh translate it around the origin Anyways we don’t want to do that so we’re going to get rid of that and that and we want to render whatever item is in the player’s hand inside of this block just to check something okay it renders the face in between just as glass normally does great okay And does it do that too yes and does it do that yes it does okay just just checking that it’s all rendering great and fine so we’re going to hold beans in our hand and let’s try and get the item in the player’s hand first so To do that we’re going to want the player and as you can see we don’t have any reference to a player so we’re going to have to try and get it so let’s go client player player i think it’s actually called local player isn’t it oh yes local player player is equal and We’re gonna do minecraft dot get instance dot player okay and we’re gonna need to suppress this and we’re just going to sis out um or what what we can do is we can say player dot um display client message player dot get item uh get main hand item dot get display name false And we’ll see what this does so this should absolutely span the chat which it does fantastic now you see if i switch it it’s now air if we put poop in our hand it’s poop clicker um what fungus etc etc you get the point so we don’t want to do that of course Let’s get that item again so let’s go item stack held item is equal player dot get item get main hand item great so that gets us our item stack and from there we just want to render that stack so we can do um this dot context dot render I think it’s render item is it not all right get block entity render a dispatcher and we can actually make a field of that as well why not so um i’m just thinking we don’t need to do this every tick we could actually create a field for These we’ll do that in a second because that will cause us to restart the game so let’s put a block nc renderer dispatcher and we’ll say be dispatcher is equal that and then we can say be dispatcher dot and what can we get from this other than that just out of pure curiosity We can get some interesting stuff i wish i knew about this sooner um anyways render item and this will first need e which i assume is the held item um and then it will need the post stack then you’ll need the buffer the combined overlay and the packed light So that’s not what it wants what is e then he extends block entity huh oh okay no we can’t use that that i thought unfortunately but that’s fine because we can get the item renderer instead so let’s create a final item renderer is equal minecraft don’t get instance Dot item renderer dot get item renderer and we should be able to use that to guess we can great and then we can use item renderer dot render item oh we never named it oops itemrenderer.render and you’ll see there are tons of different render methods here that’s fine um we can use a Um we’ll just use the normal render method yeah so this first takes in the stack of course then it takes in a transform type and that is an enum so transform type and you’ll see the different types so this is sort of how it would display so for example in Your inventory and in your hand there are two different sort of models two two different not models but two different sets of translations rotations and scales so whichever one you choose here is going to be how it renders it and i’m going to use fixed so that’s sort of the general One that you would use and then you have a boolean which is something that i don’t remember see if we can find out shall we it is passed into handle camera transforms which should tell us left hand ass so that’s just whether it’s left hand or not um Which we can check so player um we should be able to see which hand here we go um no you should be able to see if they are left-handed maybe it’s in minecraft.get instance uh maybe get item in hand renderer dot i don’t know we can just put false it Doesn’t really matter because it’s on the ground anyways and then we have the post stack the buffer the combined overlay the combined light and finally i believe this is a baked model okay this isn’t the one we want them we want render static because we don’t need a baked model And what is that going to require oh so that requires the actual player okay interesting and what is that null after the buffer that is the level so that’s also very easy to get to get the level that’s just minecraft.level and that should be everything let’s oh there’s a final integer what’s that I’m not sure then um let’s try it with zero and we’ll see we’ll see what it does so if we go in the game we should now see oh it’s not going to render anything because there’s nothing in my hand so let’s put example item in my hand that does work Great okay so that’s rendering fine now one thing we are going to want to do then is we are going to need to make some transformations to this because it’s a little weird interesting um i mean as you can see we can easily just mess around with these values and we’ll Get it to work you know if you’re wondering how i’m doing this because i don’t know if i’ve really talked about it um essentially if you press this bug button instead of this run button you can essentially just run debug mode and what that means is when you make any Changes inside of a method it has to be inside of a method otherwise it can’t hot swap it um if it’s inside of a method it will try and essentially put that code in instead um now one thing you could do this would actually be very interesting Is you could get it to sort of rotate towards you that could be quite complicated since um yeah i mean but you can you can try so i mean let’s just um no i’m not even going to try because i will fail at that but uh Yeah i mean that’s pretty much it you’ve got your item to render that’s going to be different for every player so i mean let’s look at like the toilet it’s there fine um you know poop and it’s whatever’s in the player’s main hand so if i put something in my offhand you’ll see That’s not the thing to render and i guess you could check if the player didn’t have anything in their main hand then you can render the offhand item um okay let’s actually do that which is great but um yeah so if you guys did enjoy this tutorial or found it useful please do Sure to smash your face into that like button and subscribe and it’s raining again if you really enjoyed already found it useful please do be sure to share it around and uh yeah i will see you guys in the next tutorial good bye Video Information
This video, titled ‘1.18 Minecraft Forge Modding Tutorial – Block Entity Renderer’, was uploaded by TurtyWurty on 2022-01-26 18:00:12. It has garnered 4672 views and 90 likes. The duration of the video is 00:27:17 or 1637 seconds.
In this video, I show you how you can create a Block Entity Renderer (BER), allowing you to have your Block Entity do any special rendering, such as rendering an item in the world.
In the next video we will be covering the energy capability!
Join my Discord Server, to receive support with your modding related questions: https://discord.gg/jCTnnhxc7J My CurseForge where you can find my released mods: https://www.curseforge.com/members/realturtywurty Github Repository: https://github.com/DaRealTurtyWurty/1.18-Tutorial-Mod