Let’s add a custom block entity renderer to our block entity all right we found this back until two once more and in this tutorial we’ll be adding a custom block entity renderer to our block entity now what does that mean well a block entity renderer basically allows you to render almost anything Well that is renderable in the game onto your block entities block and what we’re going to do is of course when we have our block right we have a little bit of a tray in the middle and what i want to do is i want to basically render The item either the item that is inside of slot 1 or if there is a item in slot 2 then i want to render that that is basically all that we’re going to do in this tutorial but it’s going to be actually really really awesome i have This in my own mod of course as well in resource slimes i’ve already done that and well i mean let’s just begin so in the entity package we’re going to right click new package and we’re going to call this the renderer and then inside there right click new java class this is The gem infusing station block entity renderer so quite a long name but no worries at all this will implement the block entity renderer of type gem infusing block entity hover over this implement methods the render method over here and then we also need a public gem infusing station block entity Renderer constructor with the block entityrender provider.context or context and we literally don’t want to do anything with it we just need this constructor that’s very important so the render method is basically where all of the magic happens and we’re going to well basically copy Over a line by a line so we’re first of all going to copy over the basics and then we’re going to have one error here but that’s no worries so we the get render stack method is actually a thing that does not exist in our block entity We’re just going to hover over this create that method here and once again i’m just going to move this all the way up over here just so that we have this a little bit higher up there you go and this will return the item stack that is to be Rendered inside of our little tray basically now i’m also just going to copy the contents over of this this is really simple so this should not be confusing to you at all we’re just saying hey we’re just getting a stack if there’s no stack if there is a stack in Slot 2 so if there is something in this slot right here then we’re just going to return that if there is not something in here we’re going to return whatever is inside of this slot that’s literally all that this does and literally all that we need to Do here now what we also actually do need to do is we need to synchronize this to the client again with a custom packet so for that once again we’re going to take the fluid sync packet i think and we’re going to actually make this the item stack sync s2c packet And this is going to look the following way so this is actually going to take in an item stack handler over here and this is going to be called the item stack handler let’s just change this around over here the item stack handler and of course Equal to the item stack handler here as well and now when it comes to the buffer this is a little more complicated but let’s just take a look at how this works so we’re basically making a list so you can see we can read collections with the friendly by buffer and we’re basically Reading the items over here so the general idea is that right because of course this one assigns the items from the this assigns the items to the item stack handler so we’re reading a collection and when we of course you know use the two byte over here we’re Creating a collection and then writing this collection so you can see we’re basically making a collection of item stacks and we’re using the right item here so if this is a little bit confusing to you don’t worry about it this is basically just the way that you Can well create an item stack handler via a friendly byte buffer and then here we actually don’t need the menu here what we do need is we want a set handler method we’re going to create that in just a moment and we’re just going to say this item stack handler so let’s Create that method as well and also just move this a little bit higher up because it doesn’t make any sense to have this at the very bottom there so let’s just use this right here that’s going to be okay and this is going to actually copy This over so the way that this is going to work is it’s just going to do the following so it’s basically going to take the item stack handler and just set each stack in that slot so the thing that we’re basically passing in via the parameter here we’re getting how many Slots this has and then sending each slot of the handler in the inventory itself to whatever is inside of the stack that we are putting in here this once again is just called on the client just so that it synchronizes everything as well so let’s just get this done in Here as well let’s you know register the message here so this is the item stack sync see absolutely there you go so all of those and then where do we call this well we call this in the block entity at the very top over here on contents Change so we’re going to say once again if not level that is client-side so we have to be on the server very important that you negate this keep this in mind and then we want to say more messages send it to clients a new item stack sync s2c packet passing in this And the world position and that should pretty much do everything that we need to do and this would now also synchronize the contents there as well uh because if we don’t do this then it the block entity renderer will only synchronize when we have the menu open Or when we open the menu and that’s of course not quite what we want we basically want this to happen automatically right so you can see we’re getting an item renderer over here and then we’re also getting the stack now what are we doing well here we’re Basically just pushing the a a post stack and we’re then translating scaling and changing the position of this particular item that we’re rendering and then comes the well i mean the switch method over here or the switch statement because the based on the facing we basically want to change the positive z rotation Over here uh because otherwise it will only always be the same rotation this is just rotating the item that we’re rendering and then when we render it we want to do this so we want to say item renderer dot renders render static passing in the item stack you know this Is going to be of transform typed gui yet light level is a custom method that we’re just going to copy over as well this makes sure that the item isn’t like dark or isn’t like black because otherwise it will have sort of a black overlay so we’re getting the light level There and then the rest you know passing in the block entity the block entity position over here no overlay post stack my buffer and then the one here at the end and then here at the end popping the post stack and then we should pretty much be fine now the block entity render Of course still has to be properly registered and that happens in a method in the events over here so we’re going to go into our mod events class actually the client events this is a client event of course because we’re rendering stuff and i will just copy Over the method nothing too crazy and of course everything available to you as well this is the german fusing station over here so you can see we’re using the entity renderers event that render register render us and then registering a block entity renderer for this particular block entity and this Particular block entity renderer class and that is pretty much all that we need to do so we need to synchronize this that’s very important and then here in the render method basically this is where all the magic happens and all the rendering happens uh this You know it’s just a matter of trying to change the numbers as well so those numbers basically you know i changed them until they worked and that is pretty much all that we need to do in this case so let’s go into the game and See if it works or it finds us back in minecraft so let’s just go in and if once i actually go outside of this menu we should see the diamond render and there it is the diamond is rendered exactly how you’d expect it to and it is actually rendered properly because we Set the block entity down in this direction so if we just you know did the same thing again right if i put a raw zircon in you can see there it is the raw zerkon it’s actually rotate around mirrored in this case but you know that’s totally fine it still renders and Once we actually you know craft something here then we can see you know it will change to the other one there you go so now it did change to the normal zerkon absolutely freaking awesome so this is a block entity renderer example here in this case hopefully that’s gonna be useful to you For all sorts of cool things that you can then show on your block entity uh it definitely does add a lot of flair to it and it’s just a really awesome thing to have all right but that’s gonna be it for this tutorial right here i hope you Found this useful and you learned something new and i’ll see you all in the next tutorial so yeah Video Information
This video, titled ‘Minecraft 1.19.2 Forge Modding Tutorial | BLOCK ENTITY RENDERER | #27’, was uploaded by Modding by Kaupenjoe on 2022-09-08 13:59:54. It has garnered 5247 views and 70 likes. The duration of the video is 00:08:43 or 523 seconds.
In this Minecraft Modding Tutorial, we add a custom BLOCK ENTITY RENDERER to Minecraft 1.19.2 using Forge!
== SUPPORT ME ON PATREON == ▶️ https://www.patreon.com/Kaupenjoe
== ASSETS & DOWNLOAD LINKS == GitHub Repo: https://github.com/Tutorials-By-Kaupenjoe/Forge-Tutorial-1.19/tree/27-blockEntityRenderer Gist: https://url.kaupenjoe.net/yt417/gist
== TIMESTAMPS == N/A
== 25% OFF FOR GAMING SERVERS == ▶️ https://www.bisecthosting.com/Kaupenjoe
== 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 *
== SUPPORT ME ON PATREON == ▶️ https://www.patreon.com/Kaupenjoe
== 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
== 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