Hello and welcome back to another tutorial in this tutorial we’re going to be starting work on the display case block by creating the block tile entity gui and container so let’s start by creating all the packages that we need in our parent package we’re going to create another new package Called dot client dot gui and click finish in our common package we’re going to create a new package called dot container and in our core package we’re going to create a new package called dot util in our util package we’re going to create a new class called client event plus subscriber and In here we’re going to add an add mod dot event bus subscriber then we need to pass in the mod id so let’s do mod id is equal to tutorial mod dot mod id then we need to set the bus equal to bus dot mod and then we need to set the value Is equal to dist dot client then we can import bus and then we can create an at subscribe event public static void client setup and we’re going to pass in an fml client setup event event and this class is going to be used for binding our gui to our container but we Can do that later next under init let’s create a new class called container types init and in here let’s create the deferred registry for our container so we can go into our tile entity types in it and copy all of this and let’s paste it in here this time Instead of tile entity type will have container type let’s replace this tile entity type with container types and instead of tile entities let’s do dot containers let’s import that and there we go now in our block package let’s create a package for our display case block right now i’m going to copy Everything in our quarry block and replace the quarry block with the display case block and make sure this extends block and then let’s import net.minecraft.block to block however we can change the tile entity type to display case tile entity type which we haven’t created yet but we will in a second Next let’s overwrite on block activated first of all we’re going to check if the world in is remote and if it isn’t remote then we can open a gui otherwise we can just return this and let’s add suppress warning deprecation let’s get the tile entities we can do tile entity te Is equal to world in dot get tile entity pos and now we can check if the tile entity is a display case style entity so let’s do fte instance of display case tile entity which is a class that we haven’t made yet then we can do network Hooks dot open gy then we need to get the server player entity so we can just cast our player to a server player entity And then we need our providers so we can just cast our tile entity to this and finally we can just pass in the position so now we need to create our tile entity but first let’s register the block in our block init class so let’s just copy our quarry change this to display Case change this to display case and change this to display case block then we can import display case block and now our block is in the game so now let’s create our tile entity in our tiler entity types init let’s copy the quarry and instead of quarry tile entity we can do Display case style entity and let’s also replace the one down here instead of blocking it dot quarry you can do blocking it dot display case and instead of quarry tile entity we can do display case tile entity type and instead of register quarry we can register Display case and now we can create our tile entity class so under t let’s create a new class called display case tile entity and this is going to extend lockable tile entity and now we can add our constructor and then just super and then we can also add another constructor Where we’re going to call the other constructor of tile entity types init dot display case tile entity type dot get now if we save this and go to our tile entity type we can import our display case tile entity which will fix the error in here if we Go to our display case block we can also import this and that’ll fix the arrow there and now we just have an error here actually let’s change the lockable tile entity to a lockable loot tile entity and then we can add unimplemented methods inside of get size inventory which is Going to return one and now we need to get a non-null list of item stack called items let’s create a protected non list of items stack called items is equal to non null list dot with size and then the size is going to be one and we can just fill it with empty Item stacks so we can do item stack dot empty now this one is the number of slots that we’re going to have and so is this so actually let’s just create a private static int slot and set it to one and then we could just use slots in here and slots in there Now to get items we can just return this dot items and to set items we can do this dot items is equal to items in to get the default name we’re going to return a new translation text component and in here we put the string so i’m going to do container dot plus Tutorial mod dot mod id plus and then we can do dot display case and that’s just so that we can fill out the lang file next in create menu we’re going to return a new display case container which is a class that we haven’t created yet of id and player and this Then we can override the write function and the read function which is going to allow to save our item to the world so first of all we can do super dot write compound to write all the necessary stuff to the compound and then we’re going to check If it hasn’t already written to the compound and if it hasn’t then we can do item stack helper dot save all items and then we can just pass in the compounds and items and then we can just return our compound and when we want to read from our thing We’re first going to read all the necessary data then we’re going to do this dot items is equal to non null list dot with size and we’re going to do get size inventory and then item stack dot empty and then we can just load all the items so we can check if This dot check loot and read mbt and if it doesn’t then we can do item stack helper dot load all items mbt and this dot item now we need to create our display case container so in our container package we can create a new class called display case container Then we can go back into our tile entity and import that now to fix this error we’re going to make this extend container and we can import container from the minecraft one then let’s add our constructor and add unimplemented methods then we’re going to create a public final display case tile entity Te and a private final i world cos callable which is going to be can interact with callable and then we can remove this constructor then let’s add another constructor and this is going to take a final int window id a final player inventory player inventory and finally a final Display okay style entity te then we can super off of container type init dot display case container type dot get and then window id and now let’s create our display case container type in container types init let’s create a public static final registry object of container type of display case Container and this is going to be called display case container type and that set it equal to container types dot register and under the name display case and now we need a supplier and then let’s create a supplier and for the supplier we need an i forge container type Dot create and then we need a container factory which is just display case container new however now you can see that we need a new constructor for a display case container type so let’s copy all of this but instead of that we need the final packet buffer And let’s call it data now this should fix our error and our container types in it but instead of this we need to call our other constructor and to do that we need a method which gets the tile entity from the data that we have here so let’s do a private static display Case tile entity get tile entity and this is going to take our final player inventory player inventory and our final packet buffer data now for both the player inventory and the data we need to check that they’re not nulls so let’s do objects dot require non-null player inventory and then we Need to pass in a message here in case it is a null so let’s just say player inventory cannot be null now let’s copy this again and this time do it for our data and now let’s put packet buffer cannot be no and now we can actually get Our tile entity so let’s create a final tile entity called t and let’s set it equal to player inventory dot player dot world dot get tile entity at data dot read block pause and now we can check if the tile entity is an instance of display case tile entity which should Always be true then we can return a display case tile entity of te and if it doesn’t return that we can throw a new illegal state exception which should never happen and we can just say tile entity is not correct and now we have our get thailand c so Now we can call it in this constructor so let’s just do this window id player inventory and then get tile entity to play inventory and data now we need to fill out this top constructor and then here we can do this dot t E is equal to t e and then this dot can interact with callable is equal to i world was callable dot of and then we can do t e dot get world and d dot get pause and that should fix the errors now we need to create our slots So first of all let’s create our main player inventory and this is going to require some very specific numbers to do with our gui so let’s create our for loop let’s create int row is equal to zero and while row is less than three we can do row plus plus And now in here we need to create another for loop so for int column is equal to zero column is less than nine column plus plus and now we need to do this dot add slot and let’s create a new slot and then let’s just add our player inventory and let’s import net.minecraft.inventory.container.slot And then let’s do column times row times 9 plus 9 then let’s do 8 plus column times 18 then comma 166 minus then we can open some brackets 4 minus rho and then after the brackets times 18 minus 10 and then we can add a semicolon then let’s add our player hot bar Then we can copy this for loop with the column over here then let’s do this dot add slot new slot player inventory because this is our slot in our inventory then we can just do column then 8 plus column times by 18 and then 142. and that’s our inventory Those will be the slots for basically any gui and then let’s add our tile entity which is just one line so we can do this dot add slot new slot and then we can cast a tile entity to our i inventory and then we can do 0 80 35 And that’s it for all of our slots then in can interact with we can return is within usable distance of our callable player in and block dot init.displaycase.k and finally in our container we need to override transfer stack and slot in order to get our slots to work So first let’s create an item stack called stack and it’s going to be equal to item stack dot empty next let’s create a slot slot and let’s set it to this dot inventory slots dot get index let’s check if slot doesn’t equal null and it has a stack in it and if it Doesn’t then we’re just going to return stack however if it does we can create another item stack let’s just call this stack one and let’s set it to slot dot get stack and then we can just set stack to this copy of the original stack one afterwards we Can check if the index is less than 36 and if it is we can also check that we can’t merge item stack stack one and then we need the size of the inventory which is going to be the slots variable in our display case tile entity so let’s just make that Public there we go and let’s do dot slot and that’s at this dot inventory slots dot size and if that is true we’re going to return an empty item stack otherwise we’re going to check if we can’t merge this again but this time we can do 0 And display case dot slot and we need to make sure that the first false here is set to true and if that is true then we can also return item stack dot empty otherwise we can check if stack one dot is empty and if it is we can do slot dot put stack Item stack dot empty and otherwise we can do slot dot on slot change and that’s it for this function and our container now we need to create our screen so let’s rename this client.gui that we made earlier to client.screen for better organization now in here we can create a new display case screen And let’s make this extend container screen of our display case container and let’s add the constructor then we can add unimplemented methods which is just draw the background layer and this class won’t be used on the server so we can add an only in annotation of dist dot client Let’s import only in and now we can add our gui resource let’s create a private static final let’s call this display case gui and this is going to be a resource location display case gui it’s going to be equal to a new resource location of tutorial mod Dot mod id and then we can pass in textures slash gui slash display case which is the path that our gui is going to be in and then we need to add a dot png on the end because this is a png file then in our constructor we can set this dot gui Left to zero this dot gui top to zero and we can set this dot x size to 175 and this dot y size to 201 and those are our dimensions of our texture then we can override the render function and instead of this to do we can do this dot render background Afterwards we can call super dot render and then we can do this dot render hovered tool tip then we need to draw our gui container foreground layer and we’re going to do this dot font dot funk 2 4 3 2 4 8 b and this function hasn’t been mapped Yet but we can just pass in our matrix stack then we can pass in this dot player dot get display name then we can get the x position of our inventory as a float so we can do this dot player inventory title x and then do the same thing with the y And then for the last variable we can put four two one oh seven five two and that is actually it now in our background layer we can do render system dot color for f and then we can just pass in one f in every single value and then we can Add a suppress warnings deprecation then we can do this dot minecraft dot texture manager dot bind texture and then we can pass in our display case gui now that we’ve done that we need to calculate where we want to render it so let’s create an Int x and we already have an in text let’s change this to mouse x and mouse y which is what it actually is we can change it to this dot width minus this dot x size divided by two and then we can copy this change this to into y And this to height and y size and then we can do this dot b l i t the matrix stack x y then 0 0 this dot x size and this dot y size and that is it for our screen now we need to bind our screen in our client event bus Subscriber screen manager dot register factory container types init dot display case container type dot get and for our screen we do display case screen colon colon new and finally we need to register our container types in it so let’s go to tutorial mod and under here we can do container types init dot Container types dot register bus and that is actually it i’m not going to be creating the model in this tutorial but we are going to fill in the texture this texture is going to be in the github in the description so under textures let’s create a new package called dot gui So i already have my texture prepared and i’m going to drag it into gui and make sure it’s called display underscore case.png however i made two small mistakes this here was a multiplier this should just add column and row and down here i had index is less than 36 I don’t know why but that this should just be display k style entity dot slot and now if we run the game we should see a very weird looking block but if we place this down we can open it and we can place stuff inside it And take stuff out in the next episode we’ll be going over a custom block model for this and after that we’ll be creating tile entity renderer to render the block that’s inside of it however that’s going to do it for this episode the source code is in the description And so is my discord thank you for watching and i’ll see you later Video Information
This video, titled ‘Minecraft Modding Tutorial 1.16 | 8.0 – Containers + GUIs’, was uploaded by Cy4’s Modding on 2021-02-27 13:04:45. It has garnered 17530 views and 267 likes. The duration of the video is 00:20:17 or 1217 seconds.
this is a long one lol
(ɔ◔‿◔)ɔ ♥ ~ expand me
C://Links/ GUI Texture: https://bit.ly/3uBRcnn
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/8.0-Containers%2BGUI All Episodes: https://github.com/Cy4Shot/ModdingTutorial1.16/