(Patched fully in 1.18 - see desc/pinned) How To Find Diamonds Mathematically

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone um it's matthew and i have something really incredible to show you today and i think we'll just get right into it um while this is loading up i want to quickly say that um while i rediscovered this mostly on my own it is very similar to work um done by captain wutex and lucky typhlosion around the time that the 1.16 snapshots were releasing um i think i've gone a little bit further than them um but uh just know that i'm not the first person to think of ideas like this and i also quickly want to acknowledge supercoder79 for her help when i was working out all the little details of this okay um now let's get right into it i think um so what i'm gonna show you is gonna seem insane at first okay so we're just gonna do it once um so this is a clay patch okay this is its center and we're gonna count six blocks so that's one and we're gonna three four five okay so that's six blocks we'll explain why i moved in a moment and we're just going to dig down here and there should be diamonds once we get down to diamond level and there they are all right so by now you can maybe guess what i'm gonna show you okay because every single one of these clay patches in a swamp can lead you to diamonds let's do another one let's do another one okay uh this one right here this way is positive z so we count out six blocks um this one's on a chunk border so it might fail in this situation um if it's not here i'll have to teleport i'll have to move over 16 blocks and then it will be there but it should be here there it is okay and let's do one more as an example um let me try and find one that doesn't cross a chunk border um this one maybe yeah okay so this one find the center and then i count over six blocks okay so um by now you're probably wondering uh how this works and if it always works um and the answer i'll explain the how by the end of this video um i do quickly want to warn some version of this always works on every seed um but um it's not always six blocks so on this scene in particular i'm counting over six blocks on um most seeds um on most seeds seven blocks is what will work um well really on most seeds it's six or eight but we'll talk about that in a moment um but every seed basically has a number like six which you can move over in the z direction and dig down to find diamonds and so sure enough with all these clay patches every single one of them represents a diamond door so sorry i had to take a brief break um this is the same seed as before and i'm now going to show that it works with these gravel patches in biomes other than swamps you can use these gravel patches you'll often see these in rivers and you can also use these clay patches which you'll also sometimes see in rivers um so again we're gonna find some diamonds um so for on this seed and in fact on most seeds uh you go two minus two from gravel patches to fine diamonds so let's see if this works um should be diamonds soon ah there they are okay and um it looks like i don't know what the clay number is off the top of my head for the seed but also it's not critical that you know your seed or whatnot um like it's two two or three this way from the center of clay so we can try and use that now um here so here's clay hmm the size of the gravel patch indicates how deep the grab the diamond door will be on this seed so even just looking at this gravel patch i can tell you that this diamond door probably tried to spawn in the bedrock so it's probably not worth it to check that one this one on the other hand the diamond door is either tried to spawn very high up or at y0 so we have a pretty good chance of some high diamond ore but it's on a chunk border so um i'm not quite sure if this will be correct um there's a certain chance that it could be there's a certain chance that it could have crossed over to the other side of the chunk here so if we don't find anything we'll dig down there but um there it is okay okay so but by now i think you should be convinced that this works um i've shown pretty much all the practical examples we can try doing clay it looks like clay is maybe minus two on this seed but whatever there's also a number that you can move from the clay in non-uh swamps it'll be different for swamps and foreign swamps um so yeah let's quickly review the actual numbers okay so first of all i want to stress with um chunk borders um if say you find on your seed you build over eight blocks from clay to find diamonds um you should never cross a chunk border so right here you know you shouldn't you shouldn't go through this red um you shouldn't go that way um but what you can do is you just teleport over to the other side of the chunk and keep counting and this will work um so just keep that in mind um the other thing to warn about is that if it lands like exactly here there's a chance that it's you know or even like near-ish like maybe sometimes if it's one block off um but if it lands near-ish um there's a chance that it is over here because the correct number isn't like exactly eight most of the time most of the time it's like move 8.2 blocks over but you can't measure the clay starting coordinates more accurately than a block so it's kind of hit or miss so just just be warned that on chunk if it hits a chunk border like this uh you might be in trouble um yeah so i'm going to give you numbers that that will work on the highest percentage of seeds and i'll give you the possible numbers for each seed so that is um i'm going to give you a number which if you always build this much out it'll work like maybe 75 percent of seeds and then i'm also going to give you numbers where like um these are the possible numbers for seeds so if you just have a survival world you don't know the seed of it um you can still measure a few diamond door and a few clay then you can make a good guess that your on your world six is the best number to build over or eight is the best number to build over right um so we're gonna review so first the first set of numbers is for non-swamp clay so if you have a clay patch that's not in a swamp for diamonds you're going to want to build two blocks over in the positive z for iron and you're going to have an 81.25 percent chance of two blocks over in the positive z working for diamonds from um non-swamped clay uh for non-swamp clay if you want to find an iron vein so this is i included this for maybe speed runners but you can build five blocks over and you've got a 62.5 chance of iron in the column if you build five blocks over and um also for speed runners if you have non-swamped clay and you really need gravel um you can you just you can dig down in the center of it and you've got a 31.25 chance of hitting gravel i'm sorry there's not much i can do about gravel i think some uhc players might be interested in gold ore as well because you can you know you can predict multiple lores i think it could be interesting for competitive minecraft to know where essentially full diamond armor and 10 gapples are just by like writing down some swamp clay coordinates um but i didn't bother writing the gold numbers here i might put those in the description but in theory gold should work too at the least the first gold vein in a chunk yeah that's the other thing this iron vein this is just the percent chance of finding the first iron ore there's 20 iron ore in a chunk so maybe this isn't the most useful um but it's got um if you if like you dig underneath the the larger clay circle um you're very likely to hit um a surface iron for some definition of surface um [Music] okay so the next batch this is uh gravel patches and rivers so we just saw 14. uh you can also use -2 because you know 14 is congruent to negative 2 mod 16. um for diamonds and then um you can build over two for iron so that's 56.25 percent for the iron 75 for the diamonds with river gravel um oh and i forgot to i forgot to make this table for the non swamp clay but whatever um so these are the possible um these are the actual possible offsets for gravel so as established 75 of seeds have one that is 14 long right um so that's pretty crazy um and that's also minus two right so you could also have just built um you could have built like that that's probably easier just go in the negative z instead of positive z um the last 25 percent are weird you should build over eight blocks on the last 25 percent of seats so if you're not finding the diamonds when you build over um seven when you build over 14 uh you should try building over eight um but the catch with this with this batch of seeds is that if you're on a seed where you have to build over eight from gravel to fine diamonds it's only going to work in half of all your chunks it's going to work in like a checkerboard pattern so um you should try like building over eight here and building over eight here if building over 14 is not working and try a bunch of chunks because sometimes the diamond like tries to spawn in bedrock or tries to spawn in a dirt patch or tries to spawn in a cave and then you won't see the diamonds um so just be warned that it can fail that way um but yeah so if you don't have a seed that that does where 14 works then you have one of these suckier seeds and the final thing that works is the swamp clay or the first sand in a chunk and for this one you can build over seven blocks and that will work on 87.5 percent of seeds now the seven blocks is slightly misleading in fact it's that um 50 of seeds um are eight blocks and 37.5 percent of seeds are six blocks and then um but um seven is right in the middle of eight and six and diamond or like um or is always biased to the negative direction so like this is where an or on a six would spawn and like this is where an or on the eight would spawn so um if you dig down at seven uh you'll be able to see both oars irregardless of what type of seed you are on um but if you then realize that like okay my seed's probably a six seed you can then dig as if it's a six seed and you'll get slightly better results but seven seven will work really well on most seeds um for iron 10 blocks um 68.75 percent and then for gravel and swamp clay built uh four blocks in the positive z and that'll give you 37.5 percent um and yeah same deal with the gravel over here um the final 12.5 percent of seeds you should dig down like directly in the middle of the clay but it's only going to work in 50 percent of chunks okay and then the final thing that i'm going to mention is that the size of the gravel patch and the clay patch indicates how deep the ore is so these are the sizes of gravel patch like this is radius 2 radius 3 radius 4 radius 5. this this clay is radius 2 radius um 3 or whatever little and big and so if we look over here if you're on a seed where building over 14 works then this is how the sizes work out and they're similar sizes for like the other types of seeds too but if you're building over 14 then radius 2 means that you should go it means that the diamond ore will be between y's 5 and y 8 radius 3 is 9 and 12. 4 could be y 13 14 15 or 0 it sort of wraps back around down um so there's a small chance that you won't find the ore if it's a radius four because it's gonna try and spawn in the bedrock and five is wise one through four which also is going to try and spawn in the bedrock so you're going to lose some mores in bedrock or behind a bedrock if you dig down underneath radius 5 gravel on most seeds for diamonds specifically for the other types of ores it's going to be different i'll try and put a table in the description which summarizes all this info for all the ores and all the different types of patches but um yeah but but you you get the gist um so so we'd know that like this indicates diamonds on this seed this patch indicates diet diamonds from y's five to nine this one's like 9-13 and then yeah you get the gel um and okay that's about all that there is in the tutorial section um we're gonna quickly explain why this works okay so we're gonna quickly explain why this works um so i first want to give a key um overview of just sort of intuition for why it should work at all the rough gist of it is that um uh inside the java programming language there's something called java.util.random okay and so this is the core random number generator used by a lot of the java programming language and a lot of minecraft code okay and the roughly java random has a major problem which is that um to start up a random number generator in java you have to give it an initial number okay so we're going to represent that with a little arrow and that initial number is called the seed okay it's not just the world seed of minecraft though this seed could be any number and indeed minecraft has thousands of random number generators inside it which all gets seeded with different numbers so what's going on here is that the diamonds are getting seeded with a certain seed we're going to call it s plus 60 0009 and the other stuff the patches are getting seeded with seed plus 60 000 and then either 10 11 or 12 down here oh wait no never 10 actually um a lot 10 anyway um 10 10 never happens 10 would represent lapis but you never really see lapis in a useful way um but okay and so the rough the rough idea that's going on is that this java random has what i consider to be a flaw which is that if you feed it two numbers that are very very close in numerical value um the outputs of the random number generator um of the ones seeded with say seed plus 6009 and seed plus 6011 their outputs will be strongly correlated and we can use the outputs of one to predict the other with high accuracy um and so that's all that we're doing here so now let's break into the nitty gritty of why that is and why it works the same way everywhere on a seed and um yeah um so we're gonna introduce a few things very quickly um if you've not seen this stuff before i'm sorry i don't know how well i can do without getting you lost but i'm going to be writing numbers in hexadecimal with a 0x in front of them so i'm going to write stuff like this so this is a hexadecimal number um so that's what the 0x indicates this is how you indicate hexadecimal in programming languages if you're unfamiliar with what hexadecimal is i'm afraid i'm not going to explain it to you i am also similarly binary numbers i'm just going to write out as like one zero zero one you know if it only has ones and zeros it chances are i mean base two again sorry but i'm lazy and i'm throwing this together late at night okay and then the final thing that i'm going to introduce is this symbol i'm going to use this to mean xor in a programming language you might see a carrot but i find that people on youtube tend to think that the carrot means exponentiation so we're going to be using the o plus as our xor symbol and if you're unfamiliar with xor it's an operation on binary digits so if you have zero one like this zero one one um it puts out a zero if the two digits are the same so one and one if the two so one and one those two are the same so their xor is zero and zero and zero their xor is zero because they're the same and then if they're different you get a one and um we define xor for list of numbers for numbers bigger than zero and one like say like this so these are in binary by the xor of their binary digits bitwise so zero and one gives us one zero and zero that gives a zero one and one that gives a 0. and so that that's xor and the main thing to understand about xor well xor has a few nice properties i don't think we need many of them here so we'll skip listing them for now just understand that this is how it's defined it's just another operation don't be too afraid of it um okay so how does minecraft give a seed to the random number generator so recall minecraft has an instance of the java.util.random object and it wants to use this java random to make diamond ore okay so what number does minecraft feed to this random number generator to kick start the diamond door and the answer is is that it uses a formula of the chunks coordinates and the um and the type of or it's making and the world seed itself to seed the diamond ore so let's write out let's write out the formula in its full glory so the formula is 16 times the x chunk coordinate times uh we're going to just write f of uh this the world seed we're let's call the world c w um time whoa sorry f of world seed plus 16 z um g of w so another function of the world seed and now all of this xor uh the world seed okay so this part right here this is important on its own you might have seen me talk about expressions which looked like this on the channel before this is just what i would call the decorator hash or the population hash excuse me but now mojang doesn't want to use this to make everything because if say they were making diamond ore they fed at this formula and then they went on and they then made lapis or and they used the same exact formula then lapis or and diamond or would try and spawn in the same spots for the most part or at least their x and z coordinates would line up probably actually lapis is a terrible example for that because lapis is a weird and broken or let's go with diamonds and gold um so what what mojeng does is they add a salt so uh um plus salt okay and that's what this and so this salt is sixty thousand and nine for diamonds and uh we'll go with it is sixty thousand and eleven for swamp clay right and so we can see that diamond ore and swamp um clay are going to use roughly the same number in the same chunk but now it gets even better for us okay so i'm going to quickly remove this over here let's get into how we can determine the exact values to add to our clay coordinates on the seed and um why this thing works on every chunk so first we're going to show why it works in every chunk actually okay and this is because we can consider this whole formula uh 16 x f plus 16 z g x or w plus salt okay think about the bottom four bits of this green underlined portion of the expression in binary okay because this here is a 16 and because this is a 16 the bottom four bits right here are all going to look like zeros and then we're going to have some upper bits but the key thing to key point to remember is that this thing ends in zeros okay you got that and now check this out right because when we xor this with world seed right let's say that the world seed is equal to let's make up some bottom bits the example that i gave in the video earlier ended with one one one zero okay and not only that um and then also has some upper bits right so it's it's not it's not quite this small when written binary it's a 64-bit number of course so now with this knowledge let's take a look at what let's try and compute what this whole portion of the equation is going to be okay so we know our bottom bits of our world seed now it's going to end in dot dot dot why won't this let me draw dots 1 1 1 0 and we're going to xor it with all zeros and anything x squared by zero is that thing back so zero x or one is one zero x r one is one zero x or one is 1. and so we know that this blue part of our equation right this part up here this is going to end in 1 1 1 0 okay and we can go even further we can take our 6009 and we can compute the bottom four bits for that sixty thousand and nine and likewise we can compute the bottom four bits for that sixty thousand eleven and the key point to remember is that it we don't care what the values of x and z are because these bottom four bits are going to stay the same on every single chunk coordinate in the world now the only way that this can break is if when we're doing this adding of the salt um so let's say we do one one one zero plus um the diamond salt will be nine mod sixteen and we would get um one one one zero and we would get a carry right because one plus one is zero but you have to carry the one and if we add clay we're also going to get a carry and all that matters is that you get a carry with both salts or you don't get a carry with both salts as long as that happens you're golden and it will work everywhere on the seed if one salt gives you a carry while the other doesn't that means that your prediction is only going to work on half of the chunks because those are the half of the chunks where that carry then doesn't matter for changing the upper bits but uh in this case we're actually going to find that um plus um the clay salt will end with this and we're gonna find one zero one zero one one and we do have a carry okay and so the overall result is that um we have two things um both uh you know the clay salt is just the diamond salt plus two and we know the bottom four bits and whether or not both of them had a carry um for a given seed um well if you give me the number for the seed if you don't know the number for the seed again you have to just make measurements and guess what you think the last four digits are but that's really much easier than it sounds i showed you how to do that earlier um so let's see why this matters okay because now we have to unpack what how these numbers get put into java random itself okay so the first thing that i'm going to show you is that random itself is very simple um it just has an internal number which i'm going to call x here so let's draw x in a box so that's inside the java random object and it just it's called a linear congruential generator so it updates x as follows it multiplies x by a constant a it then at it then adds a constant b so in java a is equal to 0 x 5 d e e c e 6 6 d and b is equal to 0 x b in fact which is just 11 in decimal um so the key takeaway there is that b is very small um well that's not so key for this video but it angers me that they made b so small um a is also quite small too actually keep that in mind um oh yeah yeah this entire thing is mod 2 to the 48 so the num x here is only ever 48 bits if when multiplied by a x grows to be larger than 48 bits the upper bits of x will just be chopped off so x is never more than 48 binary bits so okay um let us if if random just took the number that you gave it and then used that to do the randomness then this trick would be much easier so i think it's informative if we pretend like that's the case so okay looks like i have some room in the upper right so let's pretend up here okay so remember diamonds use output some number s so this is the diamond seed in a given chunk okay and the clay seed in that chunk will be s plus two because diamonds are something plus six thousand and sixty thousand and nine and clay something plus sixty thousand and eleven okay so now if these were the numbers that java random used um then we would have a times s plus b as the first number that java random spits out whereas the clay would get a times 2s plus b okay and we'll notice that if we expand this out we get a s plus b plus an error term of 2s um 2a 2a actually it's very important does that say um to a and the key thing is that we already know the value of a right it's in java random i've already shown it to you we already know the value of two so if java random just use these numbers we could just add 2a to the number that we measure for the diamonds and understand the clay and it goes the opposite way too we could subtract that we could we could um sorry we can um subtract the 2a from the clay and get the diamonds right um so that means that the clay uh the clay seed number one is equal to diamond seed one um plus two a and so this would be and so what you would then do is you figure out okay what seeds put the clay block at this coordinate and then you just subtract 2a off of that set of seeds and you get the set of possible seeds the diamond seed could have been which in turn corresponds to just one coordinate on the map well really it's kind of like two coordinates because this this 2a error term might not be an integer value in game however if you remember we actually got very lucky here because if you remember earlier when i mentioned that clay was small it turns out that the very first seed out of these generators which does the x-coordinate um the error is usually about this small so about 2a or sometimes 3a4a you know whatever whatever it is it's very small in comparison to 48 bits so the result is the x chord will be the same almost always like 99.9 99.6 of the time or something um so this is incredible it means that we only need to care about the z coordinate and to care about the z coordinate you would calculate the error term the same way so you then take the output of this formula so you then take the outputs of the two formulas right here and you do a second call and so that second call would be the seed corresponding with the z coordinate z coordinate so you'd you'd compute like a times this plus b and a times this plus b and you'd come out again with that the clay stuff is some constant plus the diamond seed and then you can just subtract off um that difference you know you subtract off that error that you know will be there and you get the difference in seeds and that's how i calculated the um six blocks movement on the seed that you saw me doing earlier um but of course we're not quite so lucky like this would be a utopia right if this was how java random was fed random numbers um because this would make this work on any seed right like the seeds could be different by 20 billion and you could as long as you knew the difference between the seeds going in you could predict their differences on every call in the future and we're not quite so lucky because java random pranks us java random pranks us um by if you if you call right if you call if you call this the actual seed used by random which we'll just call real is equal to the original seed x or this uh five dec constant again so this is they reuse this it's both the sort of initial scramble um for the seeds and it's um and it is the um [Music] multiplier in the lcg um and so this is the actual seed that is used okay um and so uh if we look at what this is gonna look like so six so this is going to end this is gonna be a bunch of bits and then it's going to end with what 0 1 1 0 1 1 1 0 i think and so um we're going to xor our seed which let's see we have said ends for diamonds we have said ends in 0 1 1 1 and it has some bits up here and the key thing is that we know that these upper bits besides the bottom four we know that these upper bits will be the same between diamonds and clay and that's why that arithmetic carry that i mentioned before is really important um which is that if if um one seed has a carry of zero and the other has a carry a one um then that's going to interfere with this xor because that one could potentially like carry more all the way up here and then all of a sudden you're flipping a bit like i don't know maybe you flip this bit and then um suddenly after you do this xor a bit is flipped um uh that wasn't what you would expect and suddenly your seeds aren't different by two anymore but instead they're different different by like 34 or something and so that that um that's always terrible um but in this case as long as we know that that carry didn't happen um we can compute what the xor will be on both seeds and then we can find out what the with the real difference in seeds used by the generator will be and in this case it does come out to still be two on other seeds sometimes at least i think it still comes out to be two um i haven't 100 confirmed that um on other seeds um if you were to do this um on other seeds if you were to do this um there's a potential that um yeah that this carry just ruins your day um and there's potential that um some of these bottom four bits would have flipped but all in a predictable manner so you'd be fine because you know what the bottom four bits are everywhere on the seed and so the seeds which only work 50 percent of the time they've got some nasty carry problems so they've got one carry different than the other so sometimes this bit down here is different from what you expect but if you just assume that if you assume that no further carries happen which happens in 50 of chunks in a checkerboard pattern um then you're fine again so it's sort of acceptable to me to have only 50 of chunks working but yeah um that's the explanation um thank you for watching um you know please if you watched this long and you made it and you felt like you're understanding you know even a little bit please consider subscribing um i find stuff like this a lot um i have a lot of videos that i should be making that i'm not making because i'm lazy i'm trying to be better uh you know maybe maybe subscribe motivate me to publish the cool stuff because i promise i still have cool stuff and yeah thank you
Info
Channel: Matthew Bolan
Views: 972,721
Rating: undefined out of 5
Keywords:
Id: 5Icj5TNmBUI
Channel Id: undefined
Length: 41min 21sec (2481 seconds)
Published: Mon Mar 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.