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

Solution 1:

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=<lowerX>,y=-64,z=<lowerZ>,dx=<xSize>,dy=383,dz=<zSize>] 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.