Hey what’s going on guys turtley here and welcome back to another minecraft running show for version 1.15 in this tutorial i’m going to be covering how we can go ahead and add a structure to our game now structures have been very long awaited uh they’ve been People have been waiting for them for a very long time um and i have had a massive bug with them which i now know the fix to now before i start this i would just like to mention um that um none of this code is as such mine um i have Got it all from someone called telepathic grunts um so massive credit to him for this all i have done is just gone ahead and refactored um a load of stuff and just changed around how a few things work and then obviously put it in video form which i know some of you Obviously prefer which is why you’re here so yeah a massive shout out to him um for all this code uh he does have it up on github i will be linking the uh text tutorial version of this uh in the description uh which will be his Uh if you prefer text tutorials which is perfectly fine of course it’s people learn differently so let’s just go ahead and get started so the first thing we need to go ahead and do is create our feature in it so actually i’ve already created this class right here But in here this is obviously going to be a deferred register like normal so that is a public static final deferred register and that is of a feature and that takes in a question mark and i’ll just call this features that is going to be equal to a new Deferred register this takes in forge registries dot features and then it just takes in our mod id so that is tutorial mod dot mod id and i’m just going to plug this feature uh into there as well Just do the good old imports make sure you import it from net.minecraft.world.gender feature um otherwise you’ll have an issue there now obviously if you’re using uh i think the most recent version of 1.15 or if you’re using 1.16 this will be a deferred register.create and not a new deferred register obviously i Haven’t updated yet but that should be coming uh relatively soon okay so now we actually need to go ahead and create the registry object so that will be a public static final registry object and this just takes in well mine is going to take in a house structure So i’m going to be showing you how you can go ahead and create your structures with structure blocks obviously you can create them with jigsaws but they are much more complicated and i’ll be having this tutorial on them uh in the future not right now um just Because they are a bit more complicated and but yeah they will be coming in the future there’s a few things i do want to cover before those um but yeah and obviously there’s also structures which you manually have to code placing the blocks if you prefer those ones Um they’re pretty easy to do you don’t really even need to make them structures if you don’t want to um so yeah i’m just going to call this house so because i’m going to be creating a house of course and that is going to be equal to features dodge Register and this first takes a name so obviously just house and then a supplier of a new house structure and this is going to need to take in an i feature config so for that i’m going to put a no feature config dot uh no colon colon de serialize Just like that obviously we have an error because this class does not exist um and before we go ahead and actually create that class let’s also go ahead and register the eye structure piece type so because our structure is going to be using pieces well ours won’t be using Pieces but i’m going to show you how you can use pieces so pieces basically allow you to have multiple pieces of structure put them together and it forms the actual structure itself and so for example the woodland mansion is loads of different pieces like loads I think i think if you have it bigger than a chunk you need another piece i think that’s how it works um so we just need to annotate this class with at mod dot event bus subscriber and this just takes in the bus which is equal to bus Dot mod and it takes in our mod id which is equal to tutorial mode dot mod id and just go ahead and import those and then we need a subscribe event so that will be a public static void register structure pieces and this is going to take in a registry event dot register And that just takes in a feature which obviously takes in question mark we’ll just call that event now in here we can call registry.register this takes in registry dot structure piece now sadly we can’t do this with deferred registries however if you are in the latest 1.15 Or basically if you’re able to use deferred register.create you can create a custom registry um if you want but i’m not going to be doing that um so yeah and then for the second parameter we want to put house in all caps dot two lower case and that takes in locale dot root If i could spell um locale dot root and then for the third parameter that is just the actual structure piece so that is going to be um it will be called house underscore piece which obviously we now need to go ahead and create i’m just going to create that below the deferred register Above the registry object so that would just be a public static eye structure piece type and it’s static so we can reference it from the actual piece class which we haven’t created yet of course and that’s just going to be equal to house pieces dot peace colon colon new Now we have these errors right here because we haven’t created these classes so if we go into our world and feature package we can create a new package well i’m going to create a new package you don’t have to create a new package and i’m just going to call this structures And in here i’m going to create a house structure okay and this is going to go ahead and extend structure and that takes in a no feature config there we go just import structure make sure it is the minecraft one of course now we want to add the constructor and i’m Just going to rename this to config and change this to config there we go and then we want to go ahead and add the unimplemented methods now this method right here is basically whether it can be generated or not now if this doesn’t exist for you or it doesn’t come up like this It may be called can be generated so i’m just going to add a little comment above that so it will be called can be generated if your mappings are up to date um in here let’s just go ahead and rename some of this stuff so let’s call this manager Let’s call this generator let’s just call this rand this is the chunk x and this is the chunk z chunk z and this is just the biome of course now in here what we’re going to go ahead and do um we first want to get the chunk pause so chunk pause um We we can just call that pause it doesn’t really matter is equal this dot gets start position for position that takes in the generator taking rand chunk x oh chunk x not chunk c uh make sure you get that right um and then chunk z and then zero Zero so if you just hover over here uh the last two i believe are an offset but that might be wrong i’m pretty sure it’s an offset and obviously we don’t want to offset it and then we need to check if the chunk is valid so basically whether we can spawn in it And we can do that by checking if chunk x is equal to pos dot x and do the same for z so and and chunk z is equal to pause dot z now if that is the case we need to check if uh this biome can actually spawn this structure or not Uh because obviously if it can’t spawn this structure we don’t want to spawn the structure because that doesn’t make any sense so if generator dot has structure that just takes in the biome and this because this is the structure so if it does then we can just return true And if neither of those are true we can just return false just like that then we have the get size method now it appears that this is unused so i’m actually going to comment that as unused so we know that it’s unused so we just want to leave that as zero Um just in case then we have the start factory so that will just be house structure dot start which will be a subclass we’ll create in a second column colon new and then we have the structure name which is just a string so i’m going to put tutorial mod Dot mod id plus and then colon house okay then we need to actually override this get start position for position method as we just want to change it around a bit and so let’s just refactor some of these things as well um and we don’t want to return the super So we can just get rid of that line right there so the first one obviously is generator and then it is rand then it is the uh the x pause the z pause and then it is the is correct it is the offset so it is offset x and it is offset y Z not y we don’t mess with y um so here is where you can do a bit of config if you wish um so you can create a max chunk distance a min chunk distance so let’s say we set the max distance to 10 let’s say we set the min distance to Three okay so basically what this means is that the houses cannot be closer than three chunks and the houses cannot be uh further away than ten chunks now obviously uh if you don’t really want this you can just set the min distance to zero and set this to something stupid like uh 9999 Uh it doesn’t really matter um i suppose just like 100 would be the max distance because you’re always gonna get one uh between that range anyways um but i’m just gonna keep it as 10 and free so that we can actually showcase uh this feature or at least try to it’s hard to Actually show um but yeah and then it is quite a bit of math i would say with actually uh figuring out what’s happening so i’m just going to go ahead and copy in this math you can get this from the description so we just need to change a few things Which i called differently than what i had copied so this is the generator uh this we called rand this we called rand and this we called brand okay and then we just want to return a new chunk pause so a new chunk pods and that takes in the valid chunk x And a valid chunk z now obviously this has an error right here this uh git seed modifier um so let’s let’s go ahead and create that method i suppose shall we so if we just hover over this we should be able to create it yes we can Now this can be protected because we need it um in our subclass and basically what this is um so this is to make sure that it has the same uh spawn algorithm so it’s basically some random stuff but it makes sure it’s always the same algorithm that it uses Um so we just want to make this a really big number which is unique to this structure so uh i don’t know i’m just going to type some random numbers here uh just make sure it is an integer and and that you don’t go over the integer limit because obviously that won’t work Now if your biome only spawns in your dimension or only spawns uh basically in your chunk generator you can now go ahead and override the spawn get spawn list method which will allow you to spawn your entity in here or add your spawns to it however because our biome also spawns in the Overworld this isn’t going to work but it’s not going to work for our overall biome anyways so the best way to do this is to actually use an event and not this method and since this isn’t calculated when the chunk generator uh since basically the chunk generator doesn’t check For this structure because um oh it doesn’t know that it exists so um we can’t use this however we can use an event so there is an event um I’m not sure what it’s called if we just uh ctrl shift t i think there should be some spawn events i’m not sure um i’m sure i have put the event on screen right now anyways um because i’m not sure off the top of my head exactly what it’s called So the next uh thing we want to do is create this start class so that will be a public static class start and this just extends structure start structure start there we go oh i don’t know what i just did oh i deleted a bracket that’s what i did okay In here we want to add the constructor and add the unimplemented methods and as you can see we’ve got to do some refactoring here so the first one is just obviously the structure the second one is the chunk x then it is the chunk z this is just the bounding box of the Structure and then it is a reference as an int to the structure and then it’s a long which is just the seed and let’s just paste these into the super real quick so structure chunk x chunk z bounding box then reference and then seed okay then we want to go into the inlet Method right here and in here we basically this is basically where we put the pieces together so it’s what it does when the structure starts spawning basically so we first need to go ahead and create the rotation so rotation rotation is equal rotation dot values And then we can get it from this dot around dot next int and that will be rotation dot values dot length this just allows us to choose a random rotation for the structure obviously if you always want it to be a specific rotation you can just do rotation dots clockwise whatever But we can just choose a random one then we need to go ahead and convert the chunk x and chunk z to actual uh positions so it will be the center of the chunk so positions that we can use basically in a block pause so to do that Uh we use uh int x and then we just need to use um i think it’s called bikewise operations i think that’s what they call it i’m not too familiar with them but i kind of understand what’s happening so it shifts it left by four i think and then it adds seven And to get the center of the chunk as a block pause i’m not entirely sure how it works i i think i kind of understand how it works um but it’s not really too big of an issue because you don’t ever want to change this as such so That is something you want to keep the same unless you don’t want it to spawn in the center of a chunk for some reason i don’t know why that would be but and then we can create the y which is obviously slightly different so that will be generator dot Func and i believe it is c func c that just takes in x and z and then the height map i’m going to use height map dot world dot type i mean type dot world uh surface wg however obviously if you want to you can go ahead and experiment with These different um height maps if you wish i’m just going to use wg because that’s basically the recommended one for structures i would say and then we can obviously easily create a block pause from these uh x y z so new block pause x y z not y u very good And then we can actually start um putting the pieces together so that can just be house pieces which is obviously a class we haven’t created yet dot start that test takes in the template manager the block pause the rotation and this stock components which is the different pieces and this dot rand And after it’s done that we want to recalculate the structure size so that basically sets it to the new structure size containing all the other pieces as well since the current structure size only takes an account for the first piece and by recalculating it takes an account for All the pieces and then um obviously if you want you can go ahead and log the position of it so we know where it is i’m just going to do this so i can find it a bit quicker and just like that and that is it obviously we have an Error because we haven’t created this class uh we have an error hidden here because we haven’t imported okay let’s go ahead and create the house pieces class okay this class is not going to actually extend anything and but in here we basically put the pieces together so we can create a private static Final uh resource location and i’m going to call this part one is equal to a new resource location this takes in our mod id so tutorial mod mod id and then uh house or whatever the name of the exported parties now if you want well i assume you Do if you are actually going to use multiple pieces then you can just create a second part quite simply and then just do that i’m not actually going to use multiple pieces so i’m just going to comment that second part out and show you how you could use it If if you had multiple pieces so then we can create a private static final map of resource location And also the block pause we can call this the offset and that’ll be equal to immutable map uh immutable map there it is and just delete these generics we can be we can be raw here of and this can take in uh our part one and then a new block pause zero one Zero okay and then obviously if you wanted a second part so let’s just say i had the second part we can copy this and we can paste it change it to part two and obviously that would work fine i’m just going to go ahead and comment this out um So it will still be in my github if you need to see how you can do it oh i need to comment out the comma as well there we go okay then we can go ahead and create this start method so that was a public static void start that took in The template manager which i’m just gonna call manager then a uh block pods which will be the pause then it took in the rotation which i’m going to call rot and then took in a list of structure piece and we can call that pieces oh dear and then it took a Random which i’m going to call rand and let’s just import those things okay now in here we want to uh just get the x on z pause so into x is equal pause dot x dot get x uh int and just remove this there there we go Then we can create a block pause rotation offset is equal to a new block pause zero zero zero dot rotate and that can take in the road rotation and then we can go ahead and create a block pause from that so block pause block pause is equal to rotation offset Dot add that takes in the x plus dot get y and z and then you can just add that to the pieces so pieces dot add a new house pieces Dot piece which we haven’t created yet which takes in the manager Part one so this is the part that we’re messing with then block pods and rotation which is brought okay now obviously if you have a second one you can go ahead and decide how much to offset it by so i will just use the example that telepathic grunt has For his on the second one obviously it might be slightly different for you so he actually uses a negative 10 on the x right here um and then if we have a look let’s just make this on a correct line um yeah and then it’s the same Except it uses the second part that we have okay then let’s just go ahead and create this piece class really quickly so that is a public static class piece extends template structure piece now instead of writing this all out since we don’t want to be changing Any of this really i’m just going to copy it all in so this whole piece class will be in the description now here um you don’t want to change anything other than um this method right here so this is handling the data markers so basically with structure blocks uh you’re able to set Data markers and give them a name so let’s say you set one to chest you can check if it equals whatever this takes in and then it sets that block state to a chest um and then it checks if it’s a chest so here is basically you you can set a loop Table for the chest now obviously it doesn’t have to be a chest it can be a spawner a furnace basically anything with data you can actually set it here instead of doing it in the world but either is fine because obviously you can set a chest with a loop table In the world instead of doing it here um but that shouldn’t be too much of an issue really now this method right here so this is actually the create method if your mappings are up to date it will be create and not this function thing right there so you will just need To change that if you’re on a later version but that is now it pretty much um let’s just import our pieces now the the final thing and probably the most obvious thing to everyone and we haven’t created the structure now i’m not going to show you how to create the structure Um and there’s hundreds of tutorials on how you can go ahead and create a structure with structure blocks well yeah actually use structure blocks to export it um but once you have uh the different pieces if you’re using multiple pieces of course you just want to put that in data tutorial mod And then structures and in here as you can see i put house mbt in there and in the house pieces um house pieces you can see that we read house and obviously house two if we had a second part um but yeah there’s a bunch of tutorials i’ll link Uh probably one or two in the description for how you can create a structured block uh how you can create a structure from a structured block if you wish now obviously um the final thing we have to do is actually add the structure um so before we do that actually i Suppose we should init it so just like all our other deferred registries we can call fluid in it dot no feature in it.features dot register let’s say using the mod event bus that will just register our features for us so we don’t have to go ahead and do that ourselves um Now i’m going to create a new class in gen and i’m going to call this structure uh i suppose a feature no structure gen you know let’s just do it yeah let’s just call it here sure um i was thinking about doing it in the origin but it’s slightly weird So we can actually just copy our origin right here and instead of checking if it’s planes we can just check if it’s our biome so examplebiom.get and instead of all of this configured placement and jazz we can go ahead um okay so what you do is you can do biome Dot add feature um now add structure and that will be feature init dot house dot get dot with configuration and that takes in um i feature config dot no feature config okay and basically you need to add the feature to every biome but only add the structure To the biomes you want it to spawn it and this is to make sure it doesn’t spawn across chunks because obviously that would be a slight issue um because otherwise it will cut off at chunks and then you get a bunch of issues so basically what happens is add streak add structure Uh it tells minecraft that the biome can start the generation of the structure so this actually starts a generation and then by them to add feature tells minecraft that the pieces can be made in that biome so um we need to call biome dot add feature outside of this Uh if statement and we we want to do uh decoration dot surface structures since they’re surface structures obviously if they’re underground you can do that but you would have to have changed a lot of code for that um and then it is just feature in it dot house dot get Dot uh with configuration it once again takes in i feature config dot no feature config and then we can do that with placement a placement place mint dots nope is the one we want and then we can configure that placement to i placement config dot no placement config Just like that and that should basically work so um i’m actually now going to run the game and i will see you guys there okay yes i am very stupid um i figured something was completely wrong because this worked perfectly earlier so if we go into our structure then as You can see i’m not calling this um anywhere so we just need to go into our main class go into our setup right here and in here we can just call generates well i call it generator generate structures let’s go into their generate structures and obviously make sure you’re calling this So actually that’s on register biomes no no that’s not that’s set up so make sure you are calling setup right here by adding as a listener to the mod event bus and then when you close and reopen the okay so as you can see if you just check the log Down here you can see it’s already said uh we can find a house at blah blah blah find a house blah um so that’s two then there’s four more yeah as the chunks keep generating it’s gonna find more so let’s uh teleport to 777 um so slash tp at s7 77 And we should see our house so this is my amazing house it’s a bit floaty um obviously you can fix that because you can do fillers below it if you wish uh the majority of it is on flat ground as you can see so that is why um the front Isn’t um so it’s okay um this isn’t meant to this is more meant to be a ruined house anyways but if you can do what vanilla does if you wish so it adds basically filler blocks below anywhere where there’s air below it and so you can do that if you want to Because getting it to generate on actually flat ground is very hard so as you can see um i have the entity spawned in here so that’s nice uh the furnace has items in it because i set it to have items in it so just as a quick Uh tour you come through here you’ve got a nice staircase you’ve got your bed with a nice orange carpet around it with a shelf and a pro lamp you see it doesn’t look like a mushroom on a flower pot at all um you’ve got your furnace you’ve got your crafting table You’ve got two lip furnaces with coal in them which is nice and you’ve got some chests with uh generated loot so if i actually control middle clip i think yeah so if we open this you can see uh it’s some nice loot obviously it isn’t actually generated because It’s different from if i do that um by the way if you didn’t know you can do that you can control um middle click a chest so if i just place this one down and control middle click then it will basically give us random things every time which is pretty pog And because i’ve set a loot table to the chest i didn’t know you could do that maybe everyone knew that you could do that other than me but yeah um so we’ve got some nice windows of course you can see out into the land of the weird weird dimension um But yeah that’s about it so we now have structures spawning and as you can actually see it’s working in the desert bone so if i’m right here i should be able to see the biome is beach well not desert it’s beach but uh over here is our example one so it’s spawned In our example biome but that has actually gone ahead and perfectly worked fine in in uh in the desert planet or beach biome i suppose it’s calling it so yeah that’s quite nice um we do now know it works and there should be a chunk boundary here as well so every note every Uh much chunk boundaries let’s have a look f3 and g we should see it is able to cross chunk boundaries which was a massive issue we had previously but obviously that worked perfectly now um so yeah it’s actually in four different chunks which is very neat and it’s having no issue Uh converting between them so yeah if you guys did enjoy this tutorial 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 will see you guys in the next video good bye Oops my system crashed i lost my data but i had an antivirus antivirus is not enough you need protegent world’s only antivirus with data recovery software think beyond antivirus think protegent are you coding science Video Information
This video, titled ‘Minecraft Modding Tutorial 1.15 | Structures – Episode 48’, was uploaded by TurtyWurty on 2020-09-12 17:15:28. It has garnered 3418 views and 121 likes. The duration of the video is 00:43:31 or 2611 seconds.
Hey guys, I’m back with another video. In this video, I am going to be covering how we can go ahead and make structures for our mod. I would just like to emphasise that I take no credit for this code, and all credit goes to Telepathic Grunt. All I have done is some refactoring and made it in video form. The link to Telepathic Grunt’s text one is below, so be sure to star his repository to give him some recognition.
Original 1.15: https://github.com/TelepathicGrunt/StructureTutorialMod/tree/1.15.x Original 1.16: https://github.com/TelepathicGrunt/StructureTutorialMod/
My Discord Server: https://discord.gg/d5cGhKQ Episode 47: https://youtu.be/O-YJstE3b6Y My GitHub: https://github.com/DaRealTurtyWurty/1.15-Tut-Mod Tutorials I will be doing: https://trello.com/b/LNQlC0l1 A Free Java Course that I would really recommend: https://www.udemy.com/course/java-tutorial/
HousesPieces.Piece code: https://pastebin.com/GAfzyVAk getStartPositionForPosition math: https://pastebin.com/9DLUdKpR
Minecraft Forge 1.15.2: https://files.minecraftforge.net/maven/net/minecraftforge/forge/index_1.15.2.html