Reasons for spawners
Spawners are a great way to introduce a way that players can farm XP and items from mobs. It is also a reason for players to explore the large map extensively, since it could be possible to find two spawners next to each other, allowing for a very effective farm of items and XP. XP will be used to enchant items, with some randomness in enchanting, meaning players will want to continue collecting XP in hopes of getting better enchantments. Additionally, mobs will drop some items that can't be obtained anywhere else.
The mob types that I have added so far are zombies, skeletons, and spiders. They do similar things to what they do in Minecraft. The zombie slowly follows you, the skeleton goes to a fixed distance and makes sure it has a clear shot before shooting at you, and the spider follows you more quickly, while throwing webs at you. These webs slow you down, but they do not slow spiders down. These mobs also drop some very useful things. Zombies will drop occasional iron and gold, and, very rarely, an item called a Zombie Disguise, which, when held, makes your player looks like a zombie. Mobs do not notice you when you have the Zombie Disguise, and it can be an awesome way to trick players. Skeletons drop bones, which can instantly grow farmable items, much like bone meal in Minecraft. Spiders drop and use spider webs, which will be used to craft bows and other special items.
Spawners are placed randomly within the world. Spawners can have a maximum of around 6 mobs within a small range of them, at which point they stop spawning new mobs. This limits the ability of players to have AFK XP farms, though that would be a dangerous thing anyway since you could get found and killed by other players. The maximum mob spawn also makes it easier for players to deal with a spawner when they find it, since it is though to handle a spawner that is overflowing with mobs. If the 5x5 area around the spawner is surrounded by blocks, mobs will not be able to spawn. If you don't want mobs spawning, that is how you should handle such a situation.
Ticking Spawners in Big Worlds
One surprising difficulty is that there can actually be a huge number of spawners in a map, when the map is large. To combat server lag, a maximum of one spawner is updated with every server tick. This means that an individual spawner only checks if it should place a mob every few seconds, given that there are a lot of spawners in the map. Spawners only spawn mobs when a player is within a certain range as well, preventing pointless mobs that simply expend server space. Similar to how spawners only tick occasionally, mobs also only handle updates occasionally. Not they are not always moving, but they will only change direction and check for nearby players once in a while, preventing pointless searching on the server. This two methods above are key in preventing server lag.
Other Items Needed for Effective Spawner Use
A key item that I plan to add for effective spawner use is called the Barrier. This Barrier allows projectiles and sword hits to pass through it. However, it does not let players or mobs go through. This allows for players to trap mobs in to a point where they can hit them, but not to a point where the mobs can get them. In typical Minecraft, water would be used to channel mobs in a spawner. I decided that water flow would be a difficult mechanic to visualize in 2D, so I instead went with this barrier idea.
I struggled with the decision of whether to make spawners breakable or not. Since players could be filtering in and out of the server over time, without a restart, I decided to make spawners unbreakable, for now. This is because I don't want players to mindlessly remove spawners from the map, eliminating chances for other players to find useful spawners. Of course, there will still be map regeneration, as I will talk about later, since the map will be reused as players log in and out without a restart. However, for now, spawners will not be breakable.
Want to learn more? Join the Cavegame.io Discord to chat!