1

I am currently making a Legend of Zelda themed adventure map. I am struggling to make it, so enemies spawn every few minutes but not spawn large amounts over time. I have tried using things like hopper clocks to time when enemies spawn but after a while it turns into a large swarm of unwanted enemies. I am looking to make it so if an enemy has already spawned another will not spawn.

Example: if there are 5 enemies in a room, there will never be more than 5. So even if a few are killed, a few minutes later more will respawn, but no more than 5 in total.

2
  • 1
    Years ago I was watching Vechs talk about making his maps and how Mojang had included spawner options. They could spawn NBT-adjusted monsters like charged creepers, from farther away, with little to no spin-up. If such a thing still exists and hasn't been merged into commands, you may be able to use a spawner, which will not spawn more than X creatures, with a stupidly large radius. Leaving this as a comment because I don't have enough useful info. Commented Jan 27, 2023 at 20:08
  • @FinAndTonic is making a good point, I've added the spawner method to my answer.
    – Plagiatus
    Commented Jan 30, 2023 at 7:09

1 Answer 1

1

using commands

You can store the result of the execute if entity subcommand to count how many entities there are and then execute based on that.

You will need a dummy scoreboard objective (let's say count) and a fakeplayer to store the amount in (let's say $zombies).

Now we can count the amount of zombies and only summon another one if there are 4 or less zombies in total:

execute store result score $zombies count if entity @e[type=zombie]
execute if score $zombies count matches ..4 run summon zombie

using a spawner block

As @FindAndTonic points out correctly, there is a block in the game that is build for this specific purpose, and we can modify said block to do what we want it to do. It's the spawner block.

It can be set up in a number of ways, the only important limitation to keep in mind is that all values are centered around the spawner block itself and that the spawn location is 1 block below to 1 block above the spawner.

Here is an example command that creates a zombie spawner that activates when the player gets in a 16 block radius of it, spawns one zombie every 5 seconds (100 ticks) in a 4 block (square) radius until there are 5 zombies max.

/setblock ~ ~ ~ spawner{SpawnCount:1,SpawnRange:4,MinSpawnDelay:100,MaxSpawnDelay:100,MaxNearbyEntities:5,RequiredPlayerRange:16,SpawnData:{entity:{id:"minecraft:zombie"}}} replace

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .