Is there a way to effectively prevent phantoms from spawning (1.14)?
Solution 1:
Another solution is to set game difficulty to Peaceful, either in Settings or with the command /difficulty peaceful
or /difficulty 0
. According to the Minecraft Wiki article on Difficulty:
No hostile mobs can spawn naturally [in Peaceful mode], except for evokers [Bedrock Edition only], vindicators [Bedrock Edition only], shulkers, hoglins, zoglins, piglins, piglin brutes [upcoming: BE 1.16.20], and the ender dragon. . . . When the difficulty is switched from any other setting to Peaceful, all mobs that are not allowed to spawn on Peaceful are removed from the world.
Since Phantoms are hostile mobs and not listed here as exceptions, they shouldn't be able to spawn naturally.
Of course, if you want to play in a non-Peaceful difficulty in Creative for some reason, you could always switch to Peaceful whenever a Phantom spawns to force it to be immediately removed from the world. However, this would obviously not achieve your stated goal of preventing Phantoms from spawning entirely.
Solution 2:
One solution is to keep it always day. Phantoms only spawn at night, according to the Minecraft Wiki article. Just toggle game rule doDaylightCycle
to false
while it is daytime. Note that this does come with the usual side effects of getting rid of the night.
And even if they do spawn, they are considered undead and will be set on fire in the sunlight.
Solution 3:
Repeating
/gamerule doInsomnia false
becomes laggy.
Gamerules don't need to be repeated. You just set it once and that's that.
Also, one single repeating /gamerule doInsomnia false
won't lag your server, unless you're running on severely underpowered hardware (and in that case, that's a whole different problem)
Basically: Just run /gamerule doInsomnia false
ONCE and you're done.