Transcript for:
Understanding Minecraft Mob Spawning Mechanics

mob spawning is perhaps the single most important game mechanic in Minecraft and while almost everyone has made a mob farm have you ever wondered how different design decisions impact the Farm's efficiency like how much does elevation actually affect mob spawning how does a mock cap really work or why do so many farms have this weird outer roof around them these are some of the questions that I had so I decided to find out I also wanted to understand the particular Dynamics behind mob spawning how these Dynamics connect to all mob farms and how to use these Dynamics to find the most efficient way to design any type of mob farm in the end this journey gave me an understanding of the fundamental principles behind mom spawning that is applicable to a huge number of Minecraft arm and I wanted to share that with you so my goal for this video is that after watching it you will have a detailed understanding of the mechanics behind mob spawning you will be able to understand the real game impact of different design decisions and finally you will be be able to apply these principles to any mob farm you can design your own custom Farms that fit your particular need I do want to note here that this is a massive topic that can be applied to many different types of farms so the focus of this video will be the common mechanics behind all mops awning not the particulars of any specific type of mob farm only the universal mechanics but with all that out of the way let's start with the very basic the Minecraft Wiki defines a mob as an AI driven game entity resembling a living creature so hostile mobs like zombies creepers and skeleton but also passive mobs like chickens interactive mobs like villagers and even ambient mobs like that when talking about spawning we are not referring to mobs that generate as part of a structure like villagers in a village or vindicators in Woodland Mansions nor are we discussing breeding or or spawning like a Wither Warden or Raid additionally we are not discussing special rules like Pikmin spawning in Portals or zombie reinforcement spawning in this video we are talking about the natural spawn cycle for mobs that just seemingly appear in the world as you play the game it can be hostile mobs ambient mobs animals or even location mobs like guardians or witches in a witch hut these are all part of the natural spawning cycle behind the natural spawn cycle is the spawning algorithm which is what this video is really about and while it's quite simple in the basics it also has a significant number of little details that are important to understand when maximizing Farm efficiency so for the basics of spawning all spawning happens around players between 0 and 24 blocks away from the player mobs will not spawn inside of 32 blocks mobs will not despawn if a mob has been more than 32 blocks away from a player for 30 seconds or more it has a one in 800 chance of despawning every game tick at over 128 blocks away mobs will despawn immediately this does not apply to animals or special moms like villagers the very basic flow of mob spawning is this the game first calculates the current state of the mock apps which is the max limit of mobs that can exist in the game before the algorithm will stop spawning for each mob category then if it finds their space within the mob cap it will start the spawning attempt process this is a multi-step process with a lot of consideration but to simplify it the attempt will either result in successful spawns or a failed spawn attempt finally the game will run the despawning portion of the algorithm which will despawn mobs that meet the despawn criteria at this level it's pretty simple but there are a lot of details to fill in let's start with the mob cap this is at the end of the day one of the biggest factors when talking about optimizing mob farm so it's important to understand and also luckily a pretty easy concept essentially there there's a limit to the amount of mobs that can spawn in the world at one time the mob cap is not a hard limit as it is possible for more mobs to exist than the mob cap but once a mob cap has been reached the game will stop naturally spawning mobs of that category it should be noted that this is only applicable to the Natural spawning cycle there are other ways in which mobs spawn regardless of the mob cap even so the mob cap is split into eight different categories called spawn groups with a different mod cap each each of these are independent and evaluated separately each spawning cycle the workflow is like this the algorithm identifies every loaded entity in the game then it looks at every entity in that list and determines if it should be counted towards the moth app and if this is true it increases its spawn group mod cap count if the mob cap for a spawn group is exceeded the game will stop spawning mobs for that category the implications for this are pretty simple to understand if we want to maximize the amount of mop spawning we should prevent the mob cap from ever being reached the best way to do this well murder and quickly at that we quote unquote kill the mobs after they spawn the time it takes to kill the mobs is called the time to kill kill is in quotes it's really time to remove from the mall cap which can be through killing the mob moving them through Dimensions name tagging them having them pick up an item or picking them up with a minecart or both all which count for quote-unquote killing in time to kill in general having a short time to kill is better because each time a mob is cleared from the mob cap another mob can spawn which means that the time to kill is a base limiting factor or mob spawning rates that said there is a common misconception here the mob cap has no influence on how often mobs spawn when below the cap the mom's spawning rate with for example Hostile Mobs it's the same when there are zero mobs counted toward the Gap as if there are 69 moms counted towards the cap which is one less than the mob cap so the difference between the actual mobs and the cap has no influence on the efficiency of the farm until you are exceeding the mob cap then the efficiency will drop what this means is that if you have a farm with a long time to kill but the amount of mobs counted towards the cap Never hits the cap then decreasing the time to kill will not have any impact on the farm efficiency unlike with say iron Farms where the time to kill is inarguably the most important factor mob Farms are a bit of a balancing act if you have a high spawn rate time to kill is very important and the mob cap will be the limiting factor to how fast the farm can actually go but if you don't have a high spawn rate then the time to kill only has to be fast enough to maintain a non full mob cap so those are the basics but there are a couple of things to clarify here first each Dimension has its own mop yeah so moving mobs between Dimensions is a good way to quote-unquote kill a mall it is actually faster to clear the mock cap in the origin Dimension than actually killing it this is because the mob will count towards the cap during the death animation which takes 20 game tick and portals only take two game ticks this is one of the reasons why portal Farms are so overpowered in addition to each Dimension having its own mob cap each player also has its own mob cap there's actually two types of mock app the player mod cap and the global mob cap before we continue an important concept to understand is the importance of chunks chunks are 16 by 16 block areas which go from World Bottom to world top the world is loaded and updated in terms of chunks at a time which then updates the individual blocks and entities within a chunk the local mob cap counts just the mobs within a 17 by 17 chunk area centered on the player sports that player's mob cap the global mob capping contrast will count all chunks within a 17 by 17 chunk area centered on any player on a server and take the total number of chunks from all players divided by 289 which is just 17 by 17 and multiply that resulting number by the single player mod cap which will then give us the global mob app the detail here is that chunks are only counted once during this calculation even if they're within the range of two player so if two chunks are close enough to each other that they're 17 by 17 chunk areas are overlapping then the overlapping chunks will result in a lower Global mob ah but players who are in the same Dimension but far away from each other will essentially add their independent mob caps to each other for the global mod cap this doesn't mean that either player will have more spawning because they will be restricted by their local mop app but they will be playing with a single player mod app unless one player is exceeding their personal mod app then they will essentially be stealing mob app's face from the other players so how do we apply the concept of mob caps to Farms well the first most important thing to know is the importance of mold proofing as discussed earlier the despawn sphere around a player is 128 law so all potential spawning spaces outside of a farm that are within 128 blocks of a player need to be spawned through if not the mob cap can become filled and greatly impact the farm efficiency often spawn proofing is minimized by AFK high in the air to lift the spawning sphere away from surfaces mini HUD is a great mod to use when spawn proofing as you can draw a despawning sphere which helps a lot with Farm design placement and troubleshooting in general there's nothing magic with spawn proofing just make sure it's done properly or the farm will suffer but assuming the farm has been properly spawn proofed how does a mod cap impact the efficiency of spawning Farm well as mentioned this mostly relates to time to kill we can demonstrate this with nimble Enderman arm which has a very high spawn rate for reasons which we will cover later but for now we can just run a little experiment this is a manual kill Farm without softening the mom's fur so we can adjust the time to kill by adjusting our weapon I ran two tests one with an OP netherrite sword with full enchantments and another with an iron sword and here are the results the netherright sword can clear the mob up much faster which will allow for more spawning the correlation is very clear the lifetime is about three times longer when using an iron sword and as a result the spawning is about three times lower than the op netherride sword it's almost a direct correlation which highlights the importance of reducing time to kale but this is only for Farms that have such a high spawning rate and nimbum knew this so for instance with its General mob farm he designed it to be easily built but with a longer time to kill because the mob cap is never reached anyway so there is no benefit to having a shorter time to kill but that brings us on to our topic the algorithm I just want to mention really quickly that these videos take a lot of effort for example to get into the level of detail that I desired for this video I had to teach myself to decompile and read the Minecraft source code from never having even touched Java before so if you like this type of content please show your support you can like comment subscribe or share with a friend it really helps us smaller creators I really appreciate it now back to the video optimizing mob Farms takes a balancing act between the mob cap and spawning rate but how do we boost spawning rates well here's what I call the bulk of the algorithm in my mind the mob cap and despawning portions are auxiliary functions to the algorithm but are of course very important the algorithm itself is where the magic happens so there are a couple of Parts here that are important the basic flow is as follows the very first thing the game checks is if the world is divisible by 4 400 if not all animals spawning a skip if so animal spawning continues for this tick this is why animal spawning is so slow it's intentionally 400 times lower than all others on next the mobs that can count towards them up are counted this happens before any spawn attempts but is updated when a successful spawn takes place the algorithm then takes a list of each valid spawning chunk within range of a player and iterates through it within each chunk the algorithm iterates through each spawn group and checks several conditions but most consequently it checks both the global and local mob cap and if there is space in both of these it will continue in the spawning attempts then we get into the actual attempt for each chunk the game selects one random position to originate its spawn attempts from the x and z coordinates are both completely random from within the chunk the elevation selection is based on a concept called a height map a random elevation is selected below and including the height map plus one to select the y coordinate we will get into this more in a little bit once the position has been selected the game will attempt up to three back spawning attempts for that position once four mobs spawn or the spawn attempt fails the backspawn attempt is completed the game continues to iterate through all the chunks in the same way until they all have been processed this process happens every single game tick there are a lot more details of course and we won't get into all of them in this video but there are two portions that deserve a bit more attention the concept of the hype map impacts spawning when discussing elevation and spawning the main topic revolves around the concept in the Minecraft code called the height map there are a couple of different types but we are concerned with the world surface height map if we take any random x and z coordinate in the world the height map is the highest block in that column when the algorithm finds a spawning location it will select a random location between the world bottom and the high map plus one the plus one is there so the spawn can actually happen at the error block above the top Block in the column which would be the blocks off Surface so let's look at an example for ease we will use the N the world bottom is y zero if we have a block at y10 then the spawnable elevations go up to ten plus one meaning we have 11 valid spawning spaces and this is true except that the game is a little bit weird the game picks a random spawning elevation between World bottom and height map plus one meaning here between 0 and 11. but inclusive of both 0 and 11 meaning that there are actually 12 spawning elevations to select from so an elevation of zero can be selected but it will fail because you would have to have a platform one block under the bottom built limit which is impossible the implications of this algorithm are quite straightforward the less potential elevations the less potential locations the game from the higher probability that the game picks a desirable location the only way to reduce the amount of potential elevations is to reduce the elevation of the top Block in the XD column I.E build the farm as low as possible building the farm low alone won't work though the farm has to have Sky access over the entire Farm because the height map is based on the top Block in that the column so any blocks over a arm will make the height map increase and decrease the probability of spawning so there is an easy way to calculate the probability of selecting any one elevation it is just one divided by the amount of potential spawn attempt elevation so the height map plus one minus the world bottom elevation plus one or more easily expressed one divided by the highest block plus two minus the world bottom elevation simplifying for all Dimensions we get the we can then plot them and see the result it is clear that having the top block elevation as low as possible is very important to boosting spawning rate as there will be a sharp decline for any elevation above the minimum elevation going from the lowest possible elevation to just one block higher will decrease the spawn probability by 0.17 which is a huge decree but even at the very bottom block we see that the probability is 0.5 meaning 50 failure this is because of the possibility of selecting the world bottom as an elevation which will always fail so when we are looking at for instance building farms in the Overworld that means the removal of Bedrock is necessary to get the absolute highest spawning rates because Bedrock generates up to five blocks from the world bottom in the nether it would require removing Bedrock from both the world bottom and the world ceiling as the Bedrock roof lifts the height map or the whole dimension but of course I mean it's sucks to remove bedrock and in fact it sucks to build farms so low so is there anything else we can do to boost spray well yeah this equation is for the probability of selecting any one elevation in the column but what if we increase the number of Platforms in that column now we can swap that 1l with n for a number of platforms and that y out for y map or actually I prefer to use the bottom platform elevation since this is typically the determining Factor rather than the top elevation so for a two block Gap the total height including the platform is three block so the spawn probability equation would be bit when we plot this for around y zero in the Overworld we see that at the beginning the function is quite linear but it flattens off and there is a diminishing return around 20-ish platform if we extend the equation out forever it will approach one third since we are essentially trying to fill one third of the height map with spawning spaces but of course we will never quite reach one third and in the actual game there is a height limit and building very tall farms for little gain isn't usually worth it so to get a good cost benefit ratio maybe up to 10 spawning platforms is reasonable let's say for a drop kill Farm landing at sea level like this one and this is actually the very famous nembomb General mob arm that is just simply one of the best Minecraft farms ever made but this Farm was designed before a 1.18 so the world bottom was Zero rather than negative 64. its bottom platform elevation is at 96 block and it has 10 platforms lesser this gives a probability of picking a valid elevation of about eight percent which is equivalent to a single platform at y a in the Overworld prior to 1.18 but it's much easier to build this Farm has been nerfed in 1.18 and above because the world bottom was lower but you can still get these rate you just need to build 17 platforms instead of 10 or you can lower the whole farm so that the top is at sea level but then you have to dig quite a bit so you can see it's a bit of a balancing act for instance absolute best spawning rates will be at World Bottom breaking bedrock with one layer as was done with end of light Farm but this is a lot of work but this is why knowing the Dynamics is important to be able to customize for your particular case in summary build very low with Sky access or build lots of platforms with Sky access and adjust with some simple math not too bad right but this is just the probability of getting a ballot y elevation so at the end of the day it's just a small art of puzzle Now we move on to a topic that I believe a lot of people are unfamiliar with which is very interesting and is most of the rest of the puzzle that is mobs on it attack spawning pack spawning is very interesting but it also can be a little bit confusing when people think of spawning they often think of one mob spawning in one location and for good reason because well it's logical but that's not the way the game actually spawns more moms are spawned in groups of quote-unquote packs which attempt to spawn near each other when the game picks a location for a spawn attempt that location is not actually where mobs themselves spawn but rather it is the center of the packed spawning attempt I will call this the spawn attempt origin so let's go back a little bit the game runs the algorithm it passes all check and gets to a chunk to attempt a back spawn it chooses random x and z coordinates then a y coordinate based on the height map and we now have our spawn attempt origin now from this location we do our pack spawning attempt the algorithm does up to three pack spawning attempts for each attempt the algorithm selects a random mob that is valid for the bio each Mall and biome has a minimum and maximum packed size and a random pack size is selected between these two numbers most mobs just have a pack size of four which will be selected every time once the mob type and pack size is selected the algorithm makes up to a pack size number of attempts to spawn them off there are a number of failure cases here like colliding with other entities not having a spawnable location or being out of range but we won't go into too many details in this video if that pack spawning attempt is completed before mobs haven't spawned then another pack spawn attempt will take place and then another for up to three total back spawning attempts for the same spawn attempt origin location which can spawn up to 4 mobs total these can be different mob types for each pack attempt from the same location but the facts themselves always have to have the same mob type what is perhaps most interesting here is how the actual spawn attempt locations or individual moms are selected mode Chang has implemented a technique called a triangular distribution to distribute the members of the pack a triangular distribution looks like this there is a much higher spawn probability near the spawn attempt origin and less further away triangular distribution sounds fancy right well in practice it's very simple the algorithm just takes two random numbers between 0 and 5 inclusive of both and subtracts them from each other then it adds the resulting number to the spawn attempt origin coordinate it does this for both x and z coordinate the y-coordinate does not chain the resulting coordinate is where the actual individual spawn attempt will happen for that particular mom whether or not the spawn attempt is successful the algorithm will continue with further back spawning attempt but the starting location is now the location that the previous spawn attempt occurred so this gives us a displacement between negative 5 and 5 for both x and z coordinates each individual spawn attempt within a packed spawning attempt as mentioned this method means that packs will have a higher likelihood of being clustered closely together near the Pax spawn attempt origin to illustrate the impact I've made a simple JavaScript program that runs this algorithm and outputs a heat map so the colors represent a probability of one of the four attempts of trying to spawn a mob on that particular location with brighter being a higher probability in the start it's kind of random but we can see that the probability is higher around the origin point if we jump forward a hundred thousand tick the heat map comes to steady state and we find our final heat map for a single spawn attempt origin an actual spawn can happen up to 20 blocks away from the actual spawn attempt to origin in both x and z directions that being said about 85 percent of spawns will happen within five blocks of the spawn attempt origin and about 99 within 10 block so what if we apply this to a whole Channel well here is our result we see that this is a little little bit strange right there's some bleed over into the chunks around it and the corners have slightly less probability but I mean it makes sense the corner blocks have less probability because they are surrounded by less potential spawn attempt origins in this calculation since the spawn attempts are originating just from the chunk itself it might seem like an issue but if we surround the chunk with other Chunk we see that the map flattens out completely and the locational distribution of mobs in the game is even albeit they should be clustered in the small group on average which is exactly what we see in game but the real question is why does pack spawning matter well in this case there is an immediate and impactful application for pack spawning to explain let's take a small step back when picking an elevation the game uses the height map plus one right so let's assume the game chooses this XC column here we have the stone block with only air under it the game will select a random position between World bottom and one block over the stone law here we might assume the only place that there will be a ballot spawn attempt origin is the top of the stone block which itself is a valid spawn location but this is wrong spawn attempt Origins do not need to originate from a spawnable location so if the game picks this AIR block in the column it will then be the location of up to three pack spawning a tent which as we know can spawn even quite far from the origin so potentially on the blocks around that selected AIR block at the same elevation even up to 20 blocks away in the x and z directions so without the pack spawning roof the game will never pick elevations up here since the height map is only extended to the top Block in the column which would be these grass blocks down here the spawn roof basically allows spawn attempt Origins to occur up to one block over the roof for the coordinates that the roof is covering which then can be the origin for mobs that will spawn in the farm itself through the pack spawning portion of the algorithm the impact of this can be quite significant I tested this in game with a chunk size platform then increase the pack spawning roof by one block at a time here are the results of a series of 10 hour tick boards in the equation that approximately follows the data series we see that even just one block increases the spawning by 20 which is massive for almost no work five blocks gives a gain of about 70 percent and the max gain of about 84 percent is achieved at 15 block the gains start to diminish pretty rapidly after about seven blocks this is a really solid increase and for quite little effort it's perhaps one of the best way to improve most mob Farms cheaply and easily I have to add a caveat here though as the amount of gain will be based on the platform's side with larger platforms having more benefit not every Farm can achieve a 84 gain but it is still worth it in almost every situation so adding the roof is one thing but there is also an important detail here if the spawn attempt origin will location as a solid block at its position the game will skip attack spawning attempts at that location so you want to make sure that the blocks that are on the same elevation as foot level are not solid blocks or you will not gain any benefit from the packed spawning route so the general recommendation is build a pack spawning roof with air blocks at the foot level of each platform the roof should be built at the same elevation as the top spawning platform or higher and 5 or 10 blocks is probably enough depending on the application so really that's it for the main topics there are certainly more details to dig into but this video would end up being hours long and I really wanted to focus on the main mechanics that would give returns to all mob spawning based Farm I guess the last thing to do here is go through an example of how we apply these mechanics to a real arm like this one this is kind of like nembomb's General moth Farm but worse there are a lot of tutorials like this on YouTube with people who want to quote-unquote improve numbs Farm but don't quite understand all of the Dynamics so to start we have mob cap logging and see that we are easily under the mob app at this point we want to push the spawning right the first thing we can do is open the farm up the benefit is twofold both which we just cover the spawn roof will boost spawns and removing the solid blocks next to the platform will allow these locations to back spawn also the benefit ends up being about 25 more spawning you might wonder why it's not that 80 four percent listed earlier but it's pretty simple with that example we had 256 spawning spaces per y elevation and here we have 112 spawning spaces so the likelihood of benefiting from the pack spawn roof is much less it's not a linear drop but this is expected as fact spawning favors larger platform continuing on we still aren't pushing the mob cap because we are at such a high elevation but we don't have to dig to push spawning further we can achieve more spawning by increasing the amount of spawning platforms building up is certainly an option but as the returns are diminishing it's maybe not the most effective more effective is just to build more platform power with four columns we are pushing pretty hard against mob cap now we have increased our mob spawning rates by 2.7 times more than the single Tower without changing the elevation but I have to say I kind of hate it we have four Towers copy and pasting more Farms is not very exciting in my mind and as we can see there are diminishing return we did four times the work for only 2.7 times the rate which doesn't feel great so let's try to push and optimize a little bit more we know the elevation has a huge impact so that is the obvious thing to do so we can bring the farm down to bedrock level to improve spawning and the change increases spawning by 2.4 times the same farm at sea level which is huge as expected the thing is here is where The Balancing Act comes into play I may hate the option to have four Towers at sea level but those four towers are actually giving us a little bit higher spawning rates than the single Tower at Bedrock level and going to bedrock is much harder than just building four easy to build towers so while I hate the copy and paste game for most people it will be easier to build Four Towers if it fits into your build but in this exercise we're not going to live with that so we are already at Bedrock what more can we do well there are two ways to improve this Farm now one is to push it towards the mob app even though we are already hitting the cap the goal is to have a mob spawn as soon as there is any space in the cap the second way is by decreasing the time to kill which reduces impact of pushing against the mob cap we can improve the time to kill by lowering the water platform down a little bit and then adding some portals to where the hole was which will let us replace our drop kill with a portal quote-unquote kill and maintain a light level of zero on the platform the average time to kill here decreases by 57 game ticks which is a 20 Improvement this Arrangement also allows the farm to be lowered further which then improves the spawning rates and further pushes against the mob cap the benefit over the drop kill is about nine percent which while not massive is a pretty solid game but if we want to push further there's one last thing we need to do and that's to squish the farm these columns are very nice for ease of building but when getting in high efficiency designs the short that Farms are much better to reduce the overall elevation sure we are pushing against them all cap by law already with the column Farm but it can be pushed further right now the mobs are populating when there is Mob cap space but ideally they should spawn as soon as possible we can do something like this where we have one spawning elevation and multiple collection and now we have pushed against the mob cap to near the maximum for the style Farm it's a 60 improvement over the last design and 5.1 times the rates of the very first farm this is where we can see that the mob cap while it's not hard to push against isn't going to be an absolute hard stop until we get into extremely efficient farm with very high spawning rates with spawn tracking we can actually see that we get over 69 mobs alive per tick meaning that we are constantly pushing against the mob cap which means that at this point we have pushed this Farm to near the max for this particular style but it's also like kind of a pain to build and it's not very elegant actually I personally don't really like this Farm much at all but it does help illustrate how to apply the concepts in this video even if it's not a super amazing farm design if we want to push the farm further the time to kill needs to be reduced further this is where you need to get creative and hopefully a bit more elegant like the methods creeper Farm which can also be a general mob farm which uses boats to phase mobs and a portal this is an elegant design it's short and fat and has a very short time to kill or even better the ultimate mob farm the end of light Farm which uses update suppression and update skipping to slice portals and suppress light until it was patched out of existence I mean this Farm applies all the concepts in this video perfectly it's built at the minimum elevation requiring Bedrock braking it uses pack spawning promotion in places it won't spawn the time to kill is two game tick which is the fastest possible you might wonder why they don't use all the spawning spaces but that's because they're constantly pushing up against mob cap even with the shortest time to kill possible it really is perfect but too perfect as Mojang patch did in 1.19 and then again in 1.20 and clearly want to remove it from the game completely so at this point you might have been hoping for some new OP farm that you can build and a tutorial and all that if so I am sorry to say that this video will not provide anything new in terms of arm unless you really want to build this ugly thing but for me as explained at the beginning of the video the goal and hope is that anyone who has gone this far in the video will have a deeper understanding of the mob spawning algorithm and will better understand the implications of why Farms are designed how they are and how to modify and design your own Farms so I hope that this video has helped you on your journey and will hopefully motivate you to empower yourself to experiment and play with these mechanics yourself there is no new Farm but my hope is that perhaps one of you can maybe design the next overpowered end of light replacement I'd like to give a huge thank you to a number of people who helped make this video possible with various forms of support and also a big thank you to my patreon supporters I really appreciate the support particularly Ayanna Arch rep Anning kotanuki and Carl who are all at my top tier if you aren't a supporter please consider supporting as it really helps us small creators but with that said the biggest thank you of all goes out to you the viewer if you made it this far you are a total rock star I really appreciate all the support thank you so much for watching and good bye foreign [Music]