Hello guys and welcome back to the second part of the ng tutorial series in today’s episode we’re going to go over creating an energy generator so let’s get started so the one I’m going to creating is going to be similar to things you see in most mods like a coal Generator and such where you put in an item and it generates a certain amount of energy in the last episode we went over and I demonstrated how the capability system works and how to manipulate your energy storage that we also created the last episode so now we Are going to actually go on and create a block go into your block in it and we are going to create a new block public static final block and this is going to be a glowstone generator so I put clothes down into my generator and it Will create some energy this is equal to a new block glowstone generator and its name is going to be close to generator so we now to Clyde the block we’re going to create block class and put it inside of blocks and we are going to extend block base control shadows it import That and add the constructor I’m going to remove the material and creative tab options and declare that material is iron as a machine I usually go buy in and put it in my main tab it’s going to be a rotation for this one and you want to try and avoid that anyway as Minecrafter making modifications to that in one play 13 you can go and say you free block in it now and the errors should go away it’s going to be a lot less functions in here than what you’re not really used to as I’ve managed to Shrink it down we don’t need a lot of the functions I put in before so the first one obviously we’re going to be opening in GUI so on block activated if the world is not remotes so x motion mark world in dot is remote then the Player will open the GUI player in the open GUI main dot instance for the object mod my GUI ID we’re gonna open her reference and create another ID and make the ID to three has been different at each year duis and then reference it here reference dot GUI Glowstone generator it’s in the world welding and then post architects poster get why and postal Gazette and then return true control shift s in to save reference and gloves tone generator so that that error goes away I was previously using the depreciated I talented provider but I’ve been informed That there’s a much more modern way of doing it which is the hazard tile entity you need to ensure that the method is the one with the I block state and return that as true and since it has a towns a team we have to declare it to great fatality So crate tile and see just returned knee which hanta T glowstone generator and then finally the brake block function leave it there for now we’ll come back to it but that’d be a little different to before so create this and put it in the tile and stay package as I said in The previous episode it will extend talents team and it will always implement IT kebab ensure that its net dot minecraft that you tilled article and then I’ve also made it so that the actual storage is a bit different to the way we did our furnace we are going to Be using a different another capability called a item handler so we need to declare that item handler public itemstack handler call it handler and that is going to be equal to in new item stack handler and you can put the size in here of but we only have one slot now We can go back into glowstone generator and finish this break block function we need to declare our tile entity so tile entity glowstone generator called thailand’s T is equal to Thailand steel in Veritate in brackets world in dots gets talons as heat for this position then what we do is we Go into Wilden dot spawn entity a new entity item world in past archaic pause don’t get why paused I’ll get Zed and then the actual slot tile entity dot handler dot gets a stack in slot slot 0 and that’s what we’re going to drop controller of go to import entity item And that will make it so that you are item drops on the floor you can now save the block gloves in generator and there should be no errors back in the tile entity we are also going to create our energy storage private custom energy storage cold storage is equal to a new Custom energy storage and then obviously you can as I said previously you can do different constructors I’m just going to do the single capacity of 100,000 once again we need aged custom name private string called custom name and then if you are doing the way I do it are we Putting in Item you may also want to cut time so public in cook time I was having some issues actually manipulating it using the way I showed in the previous episode so I decided to create my own energy variable so public in energy equals storage doctor ket energy stored This makes it easier to actually manipulate the energy the error is because we didn’t have the update function so we’ll create that and we’ll come back to it later you can go into the NGO toriel and take the capability functions and previously as it does have The engineer Bill T but it also has the item handler capability to integrate another one if capability is equal to capability item handler dots item hands like capability return this Scott Handler and we can copy the energy version here if it’s the item handled hey Phil T we can also return True as I mentioned in the previous episode this relies heavily on the right to and read from MBT so that’s what we’re going to be doing now firstly right to NV t we do super right to MBT we then save the everything in the inventory so all the slots compound dot Set tag call it inventory and then the actual value here is going to be this handler got serialize MBT so it converts all our slots into an NB t value we then need to set two integers compound doe seconds check the cook time and that is The cook time and then also our energy value compound got sets integer I call it GUI energy as this energy values only purpose is to make it work with the GUI and then I just this dot energy then we need the custom name so compounds dot sets string name and then I use get display name dot two string and then finally this dot storage dot right to MVT compound and return compound so this right empty will write our energy capacity max receive and max extract values there now in the read from MBT we have to do all of that in Inverse so firstly super dot read for MBT and then we deserialized NB t this got handler dot deserialize NB c– compound dr. get compound tag inventory then we set the cup time this cook time be equal to compound or get integer so the previous cooks hand that was the Same when we left the game and the same for the energy value this dot mg is compound dr. Ettinger GUI Andrey then this doctor custom name equals compound dot getstring name and finally this dot storage dot read from MBT so when we leave the game it will remember all our Slots remember how far through is cooking or generating power remember how much energy it has remember its name and also remember is capacity max receive and maxixe drives and then when it reads it will come back and get all those values again for the get display name I Found you can it can be a lot more simple you can just return the new text component translation container dr. glowstone generator that will look in our Lang file for that value and then we can set that to the the words glowstone generator we also need a Couple of values public in get mg start will just return the ng value public int gets max and restart will return this sort of storage doctor gets max energy stars we also are going to create our own guest and set fields public in gets Filled in tidy we use a switch of the ID case 0 return this to energy case 1 return this cook time and then default return 0 then the set field public void set field in tidy int value switch by the idea again case 0 this to energy Equals value case 1 this for cook time equals value and then finally it’s used by the player public billion is usual poked by player you can actually if you have the sintering furnace you’ve done the center and first tutorial you can come and copy it from here if you Haven’t then github link is in the description you can tear it off there or you can just write it off the screen it’s basically just checking how far away the players so that is all the simple functions done now the actual update function where we manipulate how much energy we have and Our slots and things like that this one’s very simple a couple of them that we will be doing in a future episodes might be a bit more complicated if handler gets stuck in slot 0 dot is empty and is item fuel handle or get stuck in slot 0 will come back and Create that is item fuel in front in a minute then increase the clock time once to cook time reaches maximum whatever you want to set a value to if cook time equals and then this value here is the maximum cook time for me I’ve put it as 25 but you can test out certain values and find out what works for you then energy plus equals which means that the energy value will equal itself plus the value pot here which is get fuel value for handle I guess that gives all 0 then the handler itself that slot by the fuel Is in there we’re going to shrink it by 1 so it will consume 1 fuel and then we reset the cook time back to 0 so we now need to create this is I some fill function we return they get fuel value function for the stack it’s greater than 0 if it’s not as if it’s 0 then it’s not a fuel bail item and create they get fuel value item stack here you just used lots of if functions and say if stack don’t get item is equal to the fuel you want to use so items dot glowstone dust for me And then return the amount energy you want it to put in I’m gonna put return 1000 and then else so any other items that isn’t the items you want return 0 and they won’t work as fuel and that is the tile entity hair done so if the fuel Slot is not empty and in that fuel slot is an item that has a fuel value then we will start to consume it and to create energy once the time has been reached we will it will create the energy and it will be consumed for the Purpose of tie and was going to copy in my container and GUI here as they are very simple and over and demonstrating to you now here what is different is we’re using something called slot item handler so a slot that works with the item handle of capability so you need to At least Claire this variable here IOM handle a handler equals tile entity gate capability the item handler capability obviously there is a default inventory swaps here and this is my fuel slot followed hips and send changes we have the energy in the cook time variables you’ll have seen these in previous Things basically it goes through and make sure that these values are updated and that the GUI and the container keep having the object up-to-date variables and then down here in transpose second slot this is a function that make sure that you can shift click it just goes Through and checks things you can copy this in the link in description now the GUI we have the resource location so it’s just that text is G right gloves and Jerry stop Eng we have two variables for the talents T and the player and it supras off of the container It also will write the title entity named the player display name which is the weight inventory and then here this M draws the amount of energy currently stored and so it just converts the integer into a strength and then we’ll draw the numbers of how much energy is Stored then down here we have this energy stored scaled function this is very similar to the cut progress scaled as it gets the current storage and the maximum of storage and then divides them by each other and multiplies them by how big the actual GUI element is as is 75 tall and then we are drawing our textured modal rect which is obviously a texture as this location in the GUI and this 76 minus K here is saying that it will draw the GUI going upwards I’ll show you the GUI here It’s very simple we have the slot we have an arrow that cook time will go across and then we have this energy bar that fills up along with the inventory down here this can be available on the link in description as well even down list or you can cut your own obviously If you create your own you’ve got to manipulate these x and y values to make these slots that line final thing we need to do is go into our GUI Handler and declare the GUI so it’s gonna be very similar to these ones so you can either use copy it and modify The numbers and names if reference drop GUI glowstone generator and then container glowstone director and tile entity close so narrator and then down here is gonna be exactly the same except for the GUI so change this word from containers to GUI if you haven’t watched any mother videos this G will handle it Needs to get registered inside of the init function the main init function I have this thing called init registries and then use a network registry to register a GUI handler the other thing we have is the talents D handler so we also need to register the tile entity For this so game registry dr. register talents to take tile entity glowstone generates a book class and a new resource location reference to Mahdavi + : and then followed by the name glowstone generator now those are registered it should now work in the game so we’re gonna run the game now Obviously we have this untextured item I’ll block here we place it down and right click on it opens up our GUI it says glowstone generator here this is in the Lange file and I have an athlete showing it on camera going to your cell time resources your line file And user declare container dock glowstone generator equals glowstone generator we have the one slot in the middle here and inventory and this energy bar if we get some glowstone it will start to add energy and as you can see the energy bar starts to increase proportionally to how Much Energy’s in there I will just cut the video here and I’ll show you it follow-up authors demonstrate the MBTs as you can see here it’s keep going up I’ll leave the game and then rejoin the game right click on it and it’s still smelting it was about halfway through There and this value still remains the same so we have our first energy system very very simple in the next episode I’m going to be showing you how to make your machine that runs all energy so if you can’t wait for that and subscribe to my Channel so you can be notified when that video happens if you like this video leave like down below thanks for watching my name’s been Harry and goodbye You Video Information
This video, titled ‘Energy Generator/Producer – Minecraft Modding Tutorial 1.12.2 – Episode 34’, was uploaded by Harry Talks on 2018-08-23 17:00:07. It has garnered 6452 views and 96 likes. The duration of the video is 00:19:15 or 1155 seconds.
Welcome to the second part of the Energy series. In today’s episode, we create our first energy block – a glowstone generator.
Links GitHub: https://github.com/HarryTechRevs/MinecraftModding/tree/HarryTechRevs-1.12.2-Tutorials Discord: https://discordapp.com/invite/xwg8zQJ Playlist: https://www.youtube.com/playlist?list=PLiDUvCGH5WEUEV9nc0Ll2pzUFmSFc21uR Subscribe: http://tiny.cc/sub2harrytech Twitter: https://twitter.com/harrystechrevs