How’s it going guys and today we have kind of in unorthodoxed video we are going to be covering how to spawn custom structures in your world so if you do f3g you can see the boundaries of the chunks and we are going to try and work Within these chunks so let me go to the very boundary very edge and you can see what the coordinates are 0 for 0 okay and it extends to infinity this I’m using f3g by the way or function plus f3 g FN plus f3 G that’s what I have to do It’s just a debug system anyways so this next chunk is located at 1616 for so you’re gonna find something pretty consistent that every chunk is 16 blocks or 16 blocks wide starting at 0 and every value of 16 going forward is going to be another chunk that you’re in the Corner of so this is going to lead us to how do we come up with some kind of method to calculate what where the corner of the chunk is because what we want to do is find the corner of the trunk find the corner of the chunk spawn a Structure inside that chunk because if you don’t go chunk by chunk if you’re not lined up perfectly then you could have issues of your structure being half way inside a desert and half way inside a river biome or something like that so you want to be lined up with the chunks Because that’s how the game generates so let’s go ahead and take a look at this I have some extra stuff in here because I was just messing around but we don’t actually need tags and we don’t need advancement so we just need functions and we don’t need that and we just need These ok so we wouldn’t want to create a function that will help us locate when we are in the corner of the of the chunk so we’re going to just make a separate function and call that a line chunk o line ok so we’re going to run a function That will get us to the corner of the chunk and it’ll just put a block down in that corner and it needs to happen at whatever entity you executed at play or whatever wherever you are at it aligns it to the corner and this is actually a pretty simple Common coding problem that comes up especially when you’re making games is aligning to some kind of tile set so we’re going to need to do scoreboard objectives scoreboard objectives objectives add X dummy so when you’re making a data fact that you want other people to install you obviously don’t Want to use XYZ you probably want to use other stuff I’ll just call this let’s call this math a lot of times the math is a pretty common one and I like to use math because you don’t need to have separate scoreboards for this situation I guess for this simplicity of this I’ll Call it chords who cares anyways you need some kind of scoreboard so now on this scoreboard we’re going to save some temporary values that don’t get used anywhere else which makes it totally consistent so we basically need to do execute store result if you don’t know What this is based off of store result I have a tutorial on it I have a tutorial on MLS everything I talked about so store result score X cords run data get entity s pause at 0 so what this will do is that’ll grab my whatever this Entity’s position and the position at 0 is going to be the x coordinate and its gonna store it on X cords alright so now we’re going to do that for y and z arrays start counting at 0 if you didn’t know that so 0 will be the first element 1 and 2 is the third element so X Y Z so we have X Y Z so let’s say that our X Y Z is 6 and 4 so we need to figure out or let’s do a more complicated situation because you could just use some arbitrary annoying annoying logic here Anyways we’re at 22 and 11 we want to get to this one which is 16 and 0 how do we do that there is a cool math equation or function called the modulo percent and if you’ve ever been to elementary school you actually already did modulo That’s why we do elementary school so if you do scoreboard years operations X percent oh we actually don’t need y sorry about that because chunks are vertical percent equals hashtag chords percent equals hashtag 16 constant alright so score players operations scoreboard just type this wrong scoreboard players operation And that’s probably the correct thing my syntax highlighter is sometimes stupid all right cool so that’s the right thing it’s just telling me it’s wrong so now we go Z so what the modulo is briefly go over it is if I take 20 if I take 11 Right and I divide it by 4 well in elementary school this would not be I mean maybe if you’re above elementary school you would say that’s like two points something something something but in elementary school you can say 4 goes into 11 2 times with a remainder of how Many left so 2 times 4 is 8 8 plus 3 is 11 so your remainder is 3 and modulo basically just says do this math and your output is going to be this so what we need to do is if we do this our output is going to be how high above the Value we are so instead we need to save this value somewhere else so scoreboard players operation hashtag will use an invisible player using the hashtag symbol in front of it hashtag X cords equals x cords ok and then we’ll do the same for Z so then we just do it to These guys so what this will do is it’ll save will keep the values on X and Z they’re safe and we’re going to put them somewhere else do some math to them and now we need to so if our remainder is 3 then if we subtract the Remainder from it when we do % equals 16 then we’re going to be back at whatever value we’re going to basically take off any extra bits that we had leading up to 16 so we just have to subtract that remainder okay now the final touch on the end is you Need an area effect cloud so this area effect cloud is going to be temporary so that we can move to the location pretty quickly so we summon an area effect cloud and we give it a tag of chunk a line and then we’re going to store execute store result entity ie tag Equals chunk a line limit equals one because you can only do it one at a time and we’re going to save its exposition too and we need to make it a double with a scale of 1 so whatever the answer is after we subtract we’re going to take That number and put it on the exposition of this chunk a line and we can add type equals area effect cloud to make it a faster command so we need two of these one for X and again one for Z so this is a pretty common method that you see in a Lot of commands you start by taking some data from something you do some math to the data and then you put the data back on that something and you can also cut down on command count by putting the operation right here instead of doing it That again so if I do this we need one more thing we need to do execute at that eat I equals chunk line run set block Dimond block and once we do that we can kill eat I equals a chunk of line you don’t need to Kill it though I could just leave it like this it will die after the next tick so you could want to implement that I don’t know so now if we play chunk a line then we’re going to get this block here so we can debug scoreboard is just A sidebar chords so what happened is probably we didn’t get any values so let’s just go with this command here so we can run line by line to figure out what might have been the problem so we got 20 20 goes hashtag X Oh there is no 16 constant that’s our Problem so we’re gonna create a scoreboard with a list of constants scoreboard objectives add constant and then scoreboard players set hashtag 16 constant 16 and this is another popular method that I use where and a lot of people use where you have a scoreboard called constant and you save a bunch of Fake players that are invisible to have specific values so that you can do math on constants so let’s go ahead and run that one more time and now boom diamond block right in the corner of the chunk so that is our chunk aligned function it’s probably as best as it gets I don’t Know anyway and then also keep in mind that the Y level is whatever it is so we will come back to that in a second so next we just need really one more function and that is going to be what to do at these chunks so instead of setting A block to diamond block what we’re going to do is we’re gonna go we’re going to kill it because I don’t want it if we do this thing multiple times per take you’re going to get some ambiguity and we’re going to add type equals area effects cloud okay so always try and Make it as efficient as possible so we are actually going to fill wherever you’re at but at coordinates 0 at the very bottom floor and then 15 in front zero and 15 in front and we are going to use some kind of custom block what block are we going to use Pick your favorite I’m just going to go with yellow wool so what this will do is it’ll create a floor of yellow wool okay and then what you’re going to want to do now is that yellow wool is going to tell you where where you’ve already checked So let’s go ahead and break this into a separate function because I want to do multiple things there so s : set chunk okay so now we have another function this function is going to be called set to chunk all right so set chunk is going to put this wool And now you’re just going to do whatever you want to do in that chunk so there is a library of things I’ve made that can help you do this very efficiently very quickly okay so I have two data packs that are going to be useful here this One is the RNG data pack and what we’re gonna do is we’re gonna include it here and then we also have and I have it linked in the it’s in it I have a video on RNG and it has this in the description and then we also have find Biome okay so if we go into here and we got two tags and we go to functions and we go to load and needs find by it okay so these are both going to be the same so we just need to add these to our load So that when we load it everything is at the same time so you just do comma find biome in it comma RNG in it just like that so now we’re gonna have an rng function this is cool so what we can do is we can do scoreboard players set in Math zero scoreboard players set in one math two or one I’ll do a 50/50 then function RNG range I believe that’s the namespace that I have listed range LCG that’s what I call it this actual rain RNG data pack has a bunch of things you can just chop them and call and just Have the LCG because that’s the best one but anyways so we can do execute if score out math so out is going to be the output it’s going to be a random number between 0 and 1 so out math matches one so we’ll just do something of its one And we’re going to do we’re going to do position and we’re going to go 15 and 15 and now we’re gonna go to the middle so 7 7 and we’re going to go to block 6 run summon Pig so this one’s a someone a pig at a 50% chance in every single chunk That you check that is a lot aligned with the corner now we just have one more thing to do and that is to create a system to these chunks so we for now we’re just going to do execute as at 8:00 at s run function you don’t even Need the address really s : chunk the line now we just need one more thing if Blanc 0 unless sorry unless block yellow roll okay so what this system does is it only plays chunk a line if you are standing on yellow wool if you are standing on yellow wool it Aligns to the chunk then it sets the chunk and it will say sets chunk so I can prove that it’s not spamming and this is part of the efficiency part we have one constantly running command and if you enter a new chunk it does a slosh Fill and there’s a little lag you see that little lag there there is a little lag that’s probably mainly due to the lighting update because we are in a void world but you can see it’s fun to pick here and when I go over here it would Spawn to pick two and I go over here it didn’t spawn a pig so you can see the RNG going along there obviously you don’t want to update a chunk when the player there’s it so you need to create some feelers you need to create some testing Points so you have to add positioned and now this is where you add your little feelers you’re testing points whatever you want to call them so you create kind of a grid of these checks so instead we’re going to just do this and we’re gonna copy all this but we’re gonna do Run function s : check grid okay and this is going to create a grid I don’t need you anymore oh and I didn’t use the find biome so you can also do a slash function find a biome locate let’s go over to objectives of the play sidebar wait what does find Biome oh yeah there was a bug in this you have to do scoreboard objectives add biome dummy scoreboard I’ve like this with a side bar biome find biome yeah so it thinks I’m in the ocean but that’s just and it also has all these tell things but you Can get rid of them and mess with that obviously this is going to change once we enter in actual overworld so we’re just gonna play this function anyway because who cares it’ll be cool it’ll tell us what biome it’s in but anyways so let’s go ahead and set up these what I would call them feelers or something some a grid of checking so we go back into s we go into the actual S sub category and we do check grid so what you want to do is you want to check not the chunk they’re in but every chunk Like in front of them and like so I don’t want to check this chunk only check maybe like four chunks out and this will work if you type to explain when you first enter an area or when you TP to a new area this could cause a lot Of bugs or it could be laggy there’s two possible situations we’re just gonna go with a small grid but you can create a much bigger grid at the cost of the cost of performance you can also make the grid a ream instead of a grid so I can check every chunk except For the chunk I’m in now what this I’ll do is if you TP then you’ll have a weird thing of the chunkier in has not been loaded so when you leave the chunk it will we get loaded right afterwards which you can come up with some situations where you double check these Other spots but yeah you can either make the grid of checking very big or you can make it a ring but then suffer the consequence of TP bugging things about anyway so execute positioned and we’re going to check 16 blocks that way unless block yellow wool run function s chunk a Line okay so we just can have a bunch of these so 1 2 3 4 5 6 7 8 9 ok so one here one in the positive 16 one in the negative 16 one in the positive 16 on the other one in the negative 16 on the other one in both Positive 16 s wanted a positive and a negative one in a both negative and one in a neg negative it ended up positive y’all should choking up alright so there you go that’ll give you nine chunks it checks and it’ll just fly around one additional view thing if you just are Some kind of fanatic is you can actually make this dependent on we’re going to make this so that we get a checkered good because checker grids are spicy so we’re gonna go with two and two this is a cool trick so you can do now that you Don’t care about this course you can do execute how do I say this so you do scoreboard players operation ex corde percent equals hashtag thirty-two constant yeah okay so you basically want to see if you’re in an odd or even chunk and you can do that by Seeing if you do a modulo of thirty-two if you’re in a chunk with a zero or a 32 or 64 then it’ll return what will be left on the X is going to be a zero but if you’re in a sixteen or you’re in a forty-eight or you’re in a 96 then what You’re going to get back is gonna be 16 so you do this and then you say and then you do this to the Z okay so then execute if score ex corde matches one if score c-chord matches one so if they are both ones then run fill I’ll fill the Block above it but you could fill the block with green wool and then have a block tag to check for yellow and green wool at the same time I’m just going to do the one above it because we’re just doing visuals here so let’s go ahead and Do this what is wrong with this oh there’s no space so what this will do is if you’re on a trunk If you’re on a chunk that is a multiple of 16 I’m still trying to work this logic out so yeah be careful of that it’s still checking my chunk that I’m in that’s the thing so it’s still aligning to my chunk repetitively so I have to do I have to Summon area effect cloud tags check chunk I have to do area effect clouds all over these and then execute those guys you could also alternatively have a chunk aligned but then have like one for each grid coordinate this would be more efficient and those chunk aligns automatically take the players Coordinates and add whatever value they’re at to them so it would take my value and add 16 to it you can use that as more efficient but I’m doing what’s quicker to show you guys so then you can do execute as I eat I equals chunk check Chunk run function S chunk align kill I eat I equals check Chun and there you go so we can go out and you can see it will load in those corners those quadrants and then also let’s go ahead and do okay thank you that’s a little better it’s closer to What I want yeah so now we just have to do probably these on the same line as I said before and let’s go with lime wool and let’s reload and that’s giving us almost the right pattern we just need to say if they’re both one or if they’re both zero so if they’re Both even or they’re both odd that’s really all you’re checking out so if we do this there you go you get your checker grid thank God all right cool so there we go it is a checker grid spawning chunk detector doing random things at each chunk with a little bit Of lag when it spawns things in and it does the feelers of a 3×3 I think that is basically where I land this one in terms of you guys determining what to do that’s all down here you don’t need these extra stuff up here unless you Really like the look of it then also so down here what you would do is you would say like if you’re within one of these biomes play a sub function in that sub function you run another RNG that you run the RNG and then if the RNG is a Certain value then spawn a structure using a structure block you can do /setblock structure block with a specific structure name in it and you can force that thing to load or you could clone from one area to another I was really just showing you guys how to Do a chunk loader a random structure loader this is the core this is basically 99% of what you need and the rest is you making those structures and coming with up with some kind of reasonable spawn rate by anyways guys if you thought this was useful go ahead And leave a like tell me something else you want to see other than that thanks for watching and I’ll see in the next one You Video Information
This video, titled ‘How to Load Custom Structures in Minecraft [Datapack Tutorial]’, was uploaded by Cloud Wolf on 2020-03-24 16:57:03. It has garnered 22890 views and 620 likes. The duration of the video is 00:25:20 or 1520 seconds.
We cover how to locate new chunks and choose where to load custom structures in any world.
▶️ Datapack Tutorial: https://www.youtube.com/watch?v=1KPSfx3xSkY ▶️ Biome Detector: https://www.youtube.com/watch?v=3dPuGjJRI6w ▶️ RNG: https://www.youtube.com/watch?v=fzZASMieGn0 📦 Starter Pack: https://www.dropbox.com/s/l8vqplyw2d21fet/starter_pack.zip?dl=1 📦 End Result: https://www.dropbox.com/s/r13u06twylzodzv/tutorial_structure_core.zip?dl=1 📝New Challenge: Medium ➡️ Make a gang of bandits spawn randomly in badlands
⚔️ Server IP: cloudgames.ml 🔵 Discord Server: https://discord.gg/HyZPCTu 💻 Website: https://dtdeadpool.wixsite.com/cloudgames 🐺 Twitter: https://twitter.com/cloudwolfbane 📧 Email: [email protected]
Music: “Werq” Kevin MacLeod (incompetech.com) Licensed under Creative Commons: By Attribution 4.0 License
All Songs Used under fair copyright. Lincenses Below: License for commercial use: Creative Commons Attribution 3.0 Unported “Share Alike” (CC BY-SA 3.0) License. Full License HERE – https://creativecommons.org/licenses/by-sa/3.0/legalcode