Is there a way in 1.18 to limit/kill mobs in forceloaded chunks (with a goal to minimize active entities and server lag)?



  • BACKGROUND: I have a minecart rail line that services a few farms which are good distance from spawn (1400 blocks), picking things up and returning them to my storage (sorter). I've done /forceload on all the chunks comprising the minecart line which works great. The line runs continuously no matter where players are. However, I've noticed that the active entity count seems to me to be high (2.3K-2.6K) for just 1-2 players online, and also seeing some "can't keep up" messages on the Spigot 1.18 server. I've done all the server lag prevention I can find online short of using a plugin (e.g. composters on top of hopers, etc.). I think that I need to find a way to reduce the number of active entities in all those forceloaded chunks. Here is a recent Spigot timings paste with just 1 player online: https://www.spigotmc.org/go/timings?url=anitidizit . But still, I could be wrong on the cause of the lag, but the high entity count and related ticks in the timings jumped out at me.

    OPTIONS I'M EXPLORING: I could run a command block every so often along the line that kills entities within a certain radius, but with a chunk now delving down to Y=-64, and my rail line being at Y=67, I would need to use a kill radius of something like 131 to get everything, which is quite a ways out on X,Z axis from the rail line, which is not very desirable. I'm also considering trying to ensure there are no dark caves or areas in the chunks to limit mob spawning, but that will be very time intensive given the large area.

    QUESTION: I'm wondering if there is a way to either kill only mobs in a certain chunk, from the very top to the very bottom, or some other way to control/reduce the number of mobs along the rail line and in other chunks I've forceloaded (e.g. automated farms). I prefer a command block or configuration option, but I'm not completely opposed to a Spigot plugin.

    Thanks.



  • To kill all entities in a certain rectangular area (like a chunk), you could run something like this in a repeat command block:

    /execute as @e[type=!minecraft:player,type=!minecraft:minecart,x=,y=-64,z=,dx=,dy=383,dz=] run kill @s
    

    To kill all entities that are not player or minecart from x, y, z: (lowerX, -64, lowerZ) to (lowerX + xSize + 1, 320, lowerZ + zSize + 1), that is a rectangular box from bedrock to sky limit.


    Additional Info:

    You should consider other options as it is not a good practice to use /forceload. consider this options:

    1. Better item transport instead of a line of hoppers.
    2. Local storage system, instead of transporting a long distance.
    3. What is your farm exactly? Maybe optimizing the farm efficiency could decrease the load a lot.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2