So as the title says, I'm trying to implement the old passive mob (sheep, cow, chicken, pig) spawning system from the alpha and beta until b1.7.3 into Minecraft release 1.12. And I fail.
------------------------------------------------------------------------
1. Why do I want this?
Nostalgia. And because in newer minecraft versions passive mob spawns are so rare, the whole world just feels empty except at night. I just recently played both b1.7.2 and release 1.12 and 1.7.2 had this fantastic charme to it, no matter how many animals you killed, a few minutes later they were back again! While in 1.12 you kill some animals and your world is practically empty.
2. What are the differences between the spawn systems?:
Well in the beta & alpha, passive mob spawning worked almost the same as aggressive mob spawning. The game checks if the block is grass, if there aren't any entities blocking it from spawning ,if the light level on that block is above 9 and if the passive mob limit is reached. If those conditions were met there was a chance of a passive mob spawning in a certain radius around the player, but also within a certain distance from the player (don't know the exact values), this happend every 20-40 seconds I think. Now in the newer versions the passive mobs are only spawned while chunk generation is running, meaning once you kill them, they're gone.
3. What I already did:
I decompiled Minecraft's code from version b1.7.3 and from release 1.12 both using MCP.
I spent around 2 days searching through the files for some sort of spawning system, but all I could find is the mob limit, and in which group sizes they spawn. Also their spawn weigh, which didn't seem to do much. I found a WorldentitySpawner which didn't seem to contain anything important.
4. Help
I just can't seem to find anything related to the per chunk spawn system of the passive mobs, I would really apreciate any push into the right direction! Or just someone telling me in which file the spawn algorithms are!
Okay, well I think you just need to do two steps: (a) prevent the current spawning which you should be able to achieve with events like the LivingSpawnEvent.CheckSpawn event and (b) do your own periodic spawning according to whatever rules you want (I think you could just do it in the same CheckSpawn handling event but could also just do it in a something like ServerTickEvent event).
Alternatively you could use Java reflection and replace the entitySpawner field with your own instance of a custom class that extends WorldEntitySpawner.
Anyway, I would start by creating an event handler for the LivingSpawnEvent.CheckSpawn event and setting the result to DENY. Then I would create an event handler for ServerTickEvent and implement whatever I wanted to do, probably by copyinging some of the vanilla code from 1.7.2 regarding the spawn weights and such. You could even just come up with your own spawning system that does whatever you want.
Well in the beta & alpha, passive mob spawning worked almost the same as aggressive mob spawning. The game checks if the block is grass, if there aren't any entities blocking it from spawning ,if the light level on that block is above 9 and if the passive mob limit is reached. If those conditions were met there was a chance of a passive mob spawning in a certain radius around the player, but also within a certain distance from the player (don't know the exact values), this happend every 20-40 seconds I think. Now in the newer versions the passive mobs are only spawned while chunk generation is running, meaning once you kill them, they're gone.
You are actually describing the current spawning system when you describe the Alpha system - the game currently does try to spawn passive mobs once every 20 seconds but the problem is that the mob cap is only 10 and this includes mobs in all loaded chunks, including the spawn chunks (the game simply counts all loaded entities of each class without checking their locations), and mobs spawned during world generation easily far exceed this (a 10% chance of a pack of 4 mobs per chunk means that the 576 chunks populated around the spawn point averages 230 mobs if all the biomes are suitable). You can see this if you create a Superflat world, which does not spawn mobs during world generation, but you'll find that they do in fact spawn naturally and if you teleport away from the spawn chunks before any spawn they will continue spawning wherever you go:
The easiest way to replicate the old system is to increase the passive mob cap, say to the hostile mob cap (70, which is actually still rather low as I've seen as many as 300 passive mobs and usually 200 or so, all from world generation, in loaded chunks when adding a printout of the current mob caps while modifying mob spawning in my own mod (non-Forge, so if you are using Forge I can't help much; conversely, using just MCP makes it far easier to modify things like this and without the significant overhead of Forge itself. You'd just need to edit EnumCreatureType (assuming 1.12 still uses the same class name as 1.6.4) to change the passive mob cap).
Also, the biggest difference between Beta and now is that passive mobs naturally despawned just like hostile mobs, avoiding many of the issues mentioned above (e.g. they would despawn from the spawn chunks as you left them so they would not fill the cap, which would only need to account for mobs in chunks around the player. Otherwise, you'd need to avoid the spawn chunks since regardless of the cap they would fill it up when you are in them unless it was entire unsuitable for spawning). This would make farming impractical though, unless that is what you want (as they would just respawn), or added code to prevent them from despawning when fenced in (this was actually done in older Console editions) or somehow "tamed" (as with ocelots, requiring a new NBT tag).
I actually raised the passive mob cap from 10 to 100 but it didn't seem to change much, I killed most of the animals in the surrounding chunks and let the game run for a few ingame days, but none respawned
Okay nevermind I'm stupid, I raised it to 500 and saw animals spawning. Guess I'll enable despawning, and try to implement a anti despawn flag once you breed them to get some sort of hybrid. Btw read through your world mod and the "did the terrain become boring" thread, I agree, new world gen sucks
------------------------------------------------------------------------
1. Why do I want this?
Nostalgia. And because in newer minecraft versions passive mob spawns are so rare, the whole world just feels empty except at night. I just recently played both b1.7.2 and release 1.12 and 1.7.2 had this fantastic charme to it, no matter how many animals you killed, a few minutes later they were back again! While in 1.12 you kill some animals and your world is practically empty.
2. What are the differences between the spawn systems?:
Well in the beta & alpha, passive mob spawning worked almost the same as aggressive mob spawning. The game checks if the block is grass, if there aren't any entities blocking it from spawning ,if the light level on that block is above 9 and if the passive mob limit is reached. If those conditions were met there was a chance of a passive mob spawning in a certain radius around the player, but also within a certain distance from the player (don't know the exact values), this happend every 20-40 seconds I think. Now in the newer versions the passive mobs are only spawned while chunk generation is running, meaning once you kill them, they're gone.
3. What I already did:
I decompiled Minecraft's code from version b1.7.3 and from release 1.12 both using MCP.
I spent around 2 days searching through the files for some sort of spawning system, but all I could find is the mob limit, and in which group sizes they spawn. Also their spawn weigh, which didn't seem to do much. I found a WorldentitySpawner which didn't seem to contain anything important.
4. Help
I just can't seem to find anything related to the per chunk spawn system of the passive mobs, I would really apreciate any push into the right direction! Or just someone telling me in which file the spawn algorithms are!
Okay, well I think you just need to do two steps: (a) prevent the current spawning which you should be able to achieve with events like the LivingSpawnEvent.CheckSpawn event and (b) do your own periodic spawning according to whatever rules you want (I think you could just do it in the same CheckSpawn handling event but could also just do it in a something like ServerTickEvent event).
Alternatively you could use Java reflection and replace the entitySpawner field with your own instance of a custom class that extends WorldEntitySpawner.
Anyway, I would start by creating an event handler for the LivingSpawnEvent.CheckSpawn event and setting the result to DENY. Then I would create an event handler for ServerTickEvent and implement whatever I wanted to do, probably by copyinging some of the vanilla code from 1.7.2 regarding the spawn weights and such. You could even just come up with your own spawning system that does whatever you want.
You are actually describing the current spawning system when you describe the Alpha system - the game currently does try to spawn passive mobs once every 20 seconds but the problem is that the mob cap is only 10 and this includes mobs in all loaded chunks, including the spawn chunks (the game simply counts all loaded entities of each class without checking their locations), and mobs spawned during world generation easily far exceed this (a 10% chance of a pack of 4 mobs per chunk means that the 576 chunks populated around the spawn point averages 230 mobs if all the biomes are suitable). You can see this if you create a Superflat world, which does not spawn mobs during world generation, but you'll find that they do in fact spawn naturally and if you teleport away from the spawn chunks before any spawn they will continue spawning wherever you go:
https://minecraft.gamepedia.com/Spawn#Java_Edition
The easiest way to replicate the old system is to increase the passive mob cap, say to the hostile mob cap (70, which is actually still rather low as I've seen as many as 300 passive mobs and usually 200 or so, all from world generation, in loaded chunks when adding a printout of the current mob caps while modifying mob spawning in my own mod (non-Forge, so if you are using Forge I can't help much; conversely, using just MCP makes it far easier to modify things like this and without the significant overhead of Forge itself. You'd just need to edit EnumCreatureType (assuming 1.12 still uses the same class name as 1.6.4) to change the passive mob cap).
Also, the biggest difference between Beta and now is that passive mobs naturally despawned just like hostile mobs, avoiding many of the issues mentioned above (e.g. they would despawn from the spawn chunks as you left them so they would not fill the cap, which would only need to account for mobs in chunks around the player. Otherwise, you'd need to avoid the spawn chunks since regardless of the cap they would fill it up when you are in them unless it was entire unsuitable for spawning). This would make farming impractical though, unless that is what you want (as they would just respawn), or added code to prevent them from despawning when fenced in (this was actually done in older Console editions) or somehow "tamed" (as with ocelots, requiring a new NBT tag).
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?
I actually raised the passive mob cap from 10 to 100 but it didn't seem to change much, I killed most of the animals in the surrounding chunks and let the game run for a few ingame days, but none respawned
Okay nevermind I'm stupid, I raised it to 500 and saw animals spawning. Guess I'll enable despawning, and try to implement a anti despawn flag once you breed them to get some sort of hybrid. Btw read through your world mod and the "did the terrain become boring" thread, I agree, new world gen sucks