Hello and welcome back to another tutorial in this tutorial we’re going to be covering tile entity renderers that allow us to render stuff based on the contents of our tile entity so under client.screen let’s create a new package let’s delete the screen and call it dot ter In here let’s create a new class called display case tile entity renderer and this class is going to extend tile entity renderer of our display case tile entity so let’s add the constructor and delete the to do and then let’s add unimplemented methods which is just going to give us the Render function however let’s also get the minecraft so let’s do private minecraft mc is equal to minecraft dot get instance now we can fill out our render function so here you can see we get the tile entity so let’s just rename this to te so in our display case time entity we Only really have one item so let’s just create a function here so let’s do public item stack get item and then we’re just going to return this dot items dot get zero which is going to return the item in the first slot so now in here we can do if te dot Get item and we can check if that equals so we can do dot equals item stack dot empty and if it does we can just return so we don’t want to render anything if there’s nothing to render next let’s get the client player entities let’s do client Player entity player is equal to mc dot player and next let’s create a function to get the light levels let’s do private get light level and this is going to take the world world and the block pause pause and this is going to return an integer let’s Import world and pause so next let’s get the int block light and that’s going to be equal to world dot get light for and then we need light to type so it’s going to be light type dot block at the pause and then let’s copy this and Change it to s light as in skylight and change the light type to dot sky and then finally we can return light texture pack light and you can pass in the b light and then the skylight so next we can get the int light level at the position that’s directly above The display case so we can do int light level is equal to get light level at t e dot get world and t e dot get pause and we want to do one up so the block above the tile entity so next i’m going to create another method called Private void render item and this is going to render any item we want and you can use this in any tile entity render not just the display case one so first let’s get the item stack stack and then we’re going to do the double array that’s the translation from the origin Next we need a quaternion for the rotation and we need a matrix stack stack and i render type buffer buffer float for the partial ticks an integer for the combined overlay an integer for the light level and a float for the scale let’s press ctrl shift f to sort that And we’re using stack twice so let’s change this to matrix stack so first we need to push the matrix stacks let’s do matrix stack dot push then let’s do matrix stack dot translate and then we can do translation zero for the x and then we can paste this Here and here and then do translation one and translation two then let’s rotate it let’s do matrix stack dot rotate rotation and then let’s scale it with matrix stack dot scale and then we can pass in the scale in all three values next we need to create an i Baked model and let’s call this model and this is the model of our item then let’s do mc dot get item renderer dot get item model with overrides then we just pass in the stack and two null values and then we can do mc dot get item renderer Dot render item then we can do stack and we can do item camera transforms dot transform type dot ground then true then matrix stack then we need to pass in the buffer then the light level then the combined overlay and then the model and that’s going to remove the error And then finally we can pop the matrix stack with matrix stack dot pop and this is going to render the item so now in here let’s render the items let’s do render item then we need the item stack so let’s do tile entity dot get item which is going To return an item stack next we need the double array for the translation so let’s create a new double array i’m going to put it to 0.5 d 1d and 0.5 d which is going to render it above in the middle of the block next we have The rotation which is going to be vector three f dot y p dot station degrees and then we need the float value in which is 180 f minus player dot rotation yield like so then we can delete this bracket and this is going to make the Item always look in the direction of the player let’s use ctrl shift f to just make everything look a little cleaner and that’s basically it except for the light level this is actually the scale so let’s just render it a bit smaller than usual with 0.8 f and this will Actually work but what i’m going to do next is i’m going to render the name of the item above the item so next we need another function which is going to render some text so let’s do private void render label then we can pass in the matrix Stack stack and we can pass in the i render type buffer from here so let’s just copy paste that into there then let’s get the int light level and then we need a double array called corner finally a string text component text and an int color let’s also format that and Now we need to render the text once again let’s do stack dot push now i need to get the scale so let’s do float scale is equal to 0.01 f then let’s get the opacity so we’ll do int opacity is equal to and then we can cast this next bit to an Int and then let’s open more brackets and let’s do point four f times two five five point zero f and then let’s shift that 24 times then let’s get the float offset which is going to be a float and to do this we’re going to need a font renderer so let’s do Font renderer font is equal to mc.font renderer and then we can do minus font dot get string property width of the text and then we can divide that by two next we just need the matrix so let’s do matrix for f matrix is equal to stack dot get last dot get matrix Now that we’ve gotten all the values let’s do stack dot translate then we can do corner zero corner one and corner two and then we can add point four f to here then we can do stack dot scale and put in the scale into every value here and then we can do Stack dot rotate to mc.getrendermanager.getcamera orientation and next we need to flip it vertically so let’s do stack dot rotate then we can do vector three f dot z p dot rotation degrees 180 f and finally we need to render the font so let’s do font dot and this function hasn’t been mapped yet So it’s going to be funk 2 4 3 2 4 7 a and this is going to take text offset 0 color false matrix buffer false then opacity and then light level like so and then finally we need to pop the stacks let’s do stack dot pop And there we go that’s our render label function so now after the item let’s render label let’s pass in the snap the buffer the light level then we need to pass in a new double array of the position it’s going to be 0.5 d 1.3 d And then 0.5 d then we need the text component which we’re going to do later and then the color which is going to be 0x ffff that’s 6x next we need an i text component which is going to be called label and then we’re going to set that equal To now we need to check if the stack is an item custom names let’s do te.getitem.has display name and if it does we’re going to do te.getitem.getdisplayname and otherwise we can do te dot item dot get translation key which is a string and now we can do a new Translation text component of the key which is going to be te.getitem.gettranslationkey now we can pass in the label into here and to fix the error let’s change this string text component to an i text component and that is actually it for this class so now we need to bind This to our tile entity so in our client event bus subscriber we can do client registry dot bind tile entity renderer and then we can do tile entity types init dot display style entity dot get and then we need a new talented renderer which is going to be display Case thailand renderer colon colon new and now we can run the game actually another thing we can do is up here we can also check or tile entity dot get item dot get item equals air and then we can also not render it and now if we go into the game you can See i have an item a block and a named block if i put the block in it renders cross block or whatever language we’re playing in if i put in the named block it’s going to render the name of the block and if we put an item it’s going to render that item Same with blocks with custom models they’re also going to work and you can see that the text and block are rotated in the direction that we’re looking at so that we can always see them thank you for watching if you need any help join the discord and i’ll see you In the next episode Video Information
This video, titled ‘Minecraft Modding Tutorial 1.16 | 10.0 – Tile Entity Renderers’, was uploaded by Cy4’s Modding on 2021-03-04 10:29:21. It has garnered 5735 views and 114 likes. The duration of the video is 00:11:25 or 685 seconds.
this is a fun one! events next!
(ɔ◔‿◔)ɔ ♥ ~ expand me
C://Follow_Me/ Subscribe: https://www.youtube.com/channel/UCJIDXtGpf4wv1ybDzdTA_vQ/ Website: https://mcmodding.club/tutorials/
C://Help/ Discord: https://discord.gg/x9Mj63m4QG Or comment on this video!
C://Source_Code/ This Episode: https://github.com/Cy4Shot/ModdingTutorial1.16/tree/main/10.0-TERs All Episodes: https://github.com/Cy4Shot/ModdingTutorial1.16/