Hey what’s going on guys turdy wordy here and welcome back to another minecraft modding tutorial video in this video we are going to be covering syncing our container so we’re going to want to sync our block entities data to the screen so that we can see it on the screen and We’ll be thinking integers because that’s what we can sync and this is extremely simple so we need to sync things through our container so i’ve already created the block entity block the item etc etc as i have in the previous tutorials and i’m doing a stupid thing in this Tutorial so i’m creating a poop storage uh as stupid as it is i know and essentially we’re just going to be displaying the amount of poop that is stored that’s basically what we’re going to be doing um and in the next video i’m going to be explaining blitz a little bit and we’ll Show you how we can actually display some something a little bit special anyways let’s get started let’s come into our container now the first thing you need to do is come into our server constructor and we’re going to want to put in here a container data and we can call that data And then we’re going to want to create a public final container data as a field and we’ll call that data too let’s initialize that in the constructor so this.data is equal data and at the bottom of our constructor we’re going to call add data slots and We’ll do data or we can even do add data slots no add data slots just like that now inside of our client constructor we need to pass in a data slot and essentially what that is is going to be a new simple container data so that’s basically just going to be an empty Piece of data storage and finally let’s come down into our menu constructing method and we’re going to put in here a new poop storage container data and this is basically going to need to take in a value so the value that we put in here Is the amount of pieces of data that we want to sync so for example since we only want to display one integer we only want to sync one singular integer and that is the count because of that we can essentially just put in one because there’s one piece of data but let’s say For a furnace for example you want to have three integers so you’ll want the burn time okay now you want four integers you want the burn time so how long that item burns for you want the current burn time so where that current sort progression of the burn is Then you want the smelt time so that’s how long it takes to smelt this item and then you want the current small time so how long it’s currently at out of that um that would be for a furnace for example so that’s four pieces of data and so you would put in four But we just have one and we’re also actually going to want to pass in our block entity here so we can pass that in first fantastic obviously that doesn’t exist yet now the thing to note is since we passed in one down here you’re going to want to Pass in one up here as well so it’s going to be that same value in this one and in this one now we’re going to want to create this class i’ve already i’ve already created a new package and start inside of our container called sync data And this is basically where all of our syncing container data will be now let’s create the container data this will implement container data there we go in fact we can okay that doesn’t really make any sense let’s instead extend simple container data and let’s remove this get count method okay let’s import that And let’s add the constructor that it wants and then let’s override get and we’ll override set let’s first rename this integer right here so we’re going to want to call this um count will do that might actually be a little confusing let’s rename it um amount okay and we’re going to want to Store our block entity in here so let’s just do a private final poop storage block nc and obviously that would be your block entity class of course um and i’m going to call this just block entity and let’s pass that into our constructor as well so i’m going to put it before The integer so poop storage block density and i’ll call that be and let’s set that so this block entity is equal be great now this get method this integer is the key so we’re going to get the key and for the set method is the key and the value now What you’re going to want to do in these getting set methods is for the get method this is basically the data that will be stored at this key so you can think of this class like a map it has a map of key to value each key will represent a different value And you can either get that value or set that value so we’re going to switch on the key Using the new switch expressions we’re gonna say for case zero then we can use an arrow for this we can say this dot block entity dot get item in slot zero dot gets count so what this means is when the key zero is passed in We just want to get the item in our slot that we want and then we get the count of it so that’s the data that i’m returning let’s say you wanted to get your progress you would just use like desktop block entity dot get progress or whatever your method or field is called Okay and let’s also do a default case otherwise it’s gonna give us issues so we’re to say default and we can just throw a new unsupported operation exception and we can put there is no value Corresponding to key plus key in and then we can put block entity that’s just what i like to do uh let’s also put some just a little quote thingies around that so we’ll put one at the end as well be a little more readable in the log And we basically need to do the same for the set method except we just don’t um we just need to set it basically so we can once again switch on the key this time we’re going to use the normal switch statements because we’re going to want to do a little more logic here So case 0 so if the key is 0 we’re going to get the stack in this lot first so we’ll go a final item stack stack is equal this stop block entity dot get item in slot zero now just before i continue this obviously if you just had a normal Integer value you could just do this stop block entity dot um progress for example is equal five or you would not do equal five because you do equal value or you might have a set progress method so yeah obviously this is just very um circumstantial i think that’s a word circumstantial probably And then we can just do whatever validation in here that we want so for example we could say if the value is greater than zero and the value is less than stack dot get max stack size then we can simply do stack.setcount value um we can also say else if Value is less than or equal to zero now if the value is less than equal to zero then we’re going to want to actually set it to something else so we can say list of blocking entity.inventory.set stack in slot zero and we’ll just do stack Uh item stack dot empty i mean not stack because if the value is less than or equal to zero then we’re just going to want to set it to an empty stack we’re not going to want to set it to the same stack group with a count of zero because that would Be a little weird then finally we can put say else if the value is greater than stack dot get max stack size so if it’s greater than 64 then we’re going to want to set it to the max stack size so this we can say you can say stack.setcount stack dot set count And we can say stack dot get max stack size and then we can set the in the slot so this dot block entity dot inventory dot set stack in slot slot zero and we can just put the stack great what you might want to do here is you might want to say instead Um yes so instead of making this final first of all we could say here stack is equal item stack dot empty and you eat this line right there there we go and you’re just going to want to break because now we need a default case so the defaults we’re once again Just going to copy this and get rid of that great okay that obviously it tells us that this can be replaced with an if statement which of course it can be replaced with an if statement if key is equal to zero now i’m going to leave it as a switch And the reason i’m going to leave it as a switch is just because if you want to add it to add to it in the future so you want to add another um free it’s different values then it’s just a little bit easier if it’s already a switch so i just prefer to Leave it as a switch make it an f if you want if you know you’re not going to add any more values and it’s only you know one or two then just leave it as an else if thing um but i’m just going to leave it like this So we can close that now and we can import that in here and imports hello thank you and great that should be what we need so let’s just quickly come into our screen and let’s create a simple way to display it so let’s come here let’s go this dot font dot draw Now obviously you can do whatever we you want with this value it doesn’t matter what you do and i’m just going to draw a simple integer in the next tutorial as i said i’m going to be covering the blitz method so this method that we used down Here i didn’t really explain it in the video um before because this is sort of a very simple use case for it but in the next video i’m going to be drawing a sort of progress bar essentially um i think that’ll be a little more exciting So what we’re just going to put in here um we’ll leave that for a second then let’s go put in a position so i’m going to say this dot left pause um plus 118 and desktop top pause plus 75 and those are values that i will that will make sense in a Minute um 0x 40 40 40. now for the thing that we actually want to draw we need to go ahead and get that value from our container and the way we can do that is go int count is equal this dot and here you might get a little bit confused because Instead of saying this stock container you’ll see that doesn’t exist we need to use this top menu and that gives us our container from there we can say data uh actually can we just use dot get no okay anyway dot data and then dot get and we’re gonna get it from data slot Zero now what you could do and actually i kind of recommend this so you’ll see in our container data here it’s a little bit confusing because we’re dealing directly with these sort of hard-coded integers so for example zero is mapped to the count but if you had like 20 Different things that you were thinking for example this is going to get really confusing really quickly remembering oh is this one this is this one that so what you could do is you could actually just create getters and setters for this so for example you could say public int get count And you could just do return you could return get zero and then you could have public void set count you could go int amount and then you could go set zero amount and i think that would be a little easier to understand oh we can’t actually call it get count um We can call it set stack count and get stack count in order to not override that and from there um we can just use menu.data now the issue is our data if we come into our data we can see it’s a container data so what you would have to do is cast it Which is actually not gonna work because our client constructor only has a simple container data not a poop storage container data so we can’t actually use that unfortunately i was hoping we could but never mind ignore what i just said on because unfortunately that’s not an Option so we just have to use the actual corresponding value and we can just put in count and obviously it doesn’t like that because count is an integer and not a string so converting that to a string we get the value we want and we can test this To see if it works correctly so let’s just go ahead and run client and i’ll see you in the game so here we are everyone we are in the game as you can see i’ve just placed down and made some textures for the things we’ve done previously so we’ve got the jaws we’ve Got our chest and this is our new block so this is the poop storage i’ve just put poop tm poop trademark i don’t know why um i spend way too much time on that to be honest so we can place it down and i’ve made a poop item which i’ve Also spent way too much time making this texture anyways we can put poop in here so this is the gui i’ve made and you’ll see that just goes ahead and puts the correct value in there which is fantastic that’s exactly what we need so yeah that’s how you can basically Sync an integer from your block entity to your screen and in the next tutorial i’m going to be covering the blip method as i said several times but i’m going to be using that to fill with this bar right here with poop um as you do you know that’s what everyone Does modding for right to make poop um but yeah we’re going to be filling this from the bottom to top of course uh something like um you might use that for something like drawing a water texture so say you are storing water in your block entity you Might want to draw a sort of bar of how much water is in there or any liquid or whatever um i think you get the point or any progress bar for example we’re basically drawing a progress bar so if you ever want to make a furnace For example uh it might be helpful to know how to do that but that will be the next tutorial and yes speaking of the next tutorial that is the end of this one so i hope you guys did find this tutorial useful and enjoy it 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 gold Foreign Video Information
This video, titled ‘1.18 Minecraft Forge Modding Tutorial – Syncing using a container’, was uploaded by TurtyWurty on 2022-01-24 23:45:10. It has garnered 1418 views and 31 likes. The duration of the video is 00:21:43 or 1303 seconds.
In this video, I show you how you can sync an integer from your block entity to your screen.
In the next video, I will explain the `blit` method more in-depth and giving a practical example.
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 Check out the trello: https://trello.com/b/6lLTY9js/118-modding-tutorials