Simple Anti-Mob Lag [1.9-1.14] 2.0.0

Reduce the performance impact of mobs and farms without affecting gameplay.

  1. froobynooby
    Native Minecraft Version:
    1.14
    Tested Minecraft Versions:
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    • 1.13
    • 1.14
    Source Code:
    https://github.com/froobynooby/Simple-Anti-Mob-Lag
    Contributors:
    froobynooby
    Simple Anti-Mob Lag
    A plugin for reducing the performance impact of mobs and farms

    On many servers, the main source of lag is ticking mobs; especially those in large farms. This plugin aims to reduce the impact of mobs and mob farms on your server by removing unnecessary components of their AI. It also aims to do this without having any significant effect on gameplay.

    The plugin can do one of two things to a mob to achieve this: 'freeze' them or 'nerf' them. A frozen mob has no AI whatsoever; they don't move, they're not affected by gravity, water cannot push them and they don't perform several entity-specific functions (such as sheep regrowing their wool). A nerfed mob will just be missing some of its pathfinding goals; the goals it loses and the goals it keeps are completely configurable.

    By default the plugin will passively nerf all animal farms. All this does, by default, is remove the 'random stroll' pathfinding goal from animals in farms, i.e. it just stops animals from walking around randomly. If the farms aren't too densely packed this causes the animals to stop bumping into each other constantly (example), and this can significantly reduce their performance impact on the server. By default we will also freeze mobs in large groups when the TPS of the server drops below 18.5, and, in small increments, unfreeze mobs when the TPS rises above 19.5 and is sufficiently stable. Everything here is configurable.

    Installation and configuration
    Installation is very simple. Just put the jar file in your plugins folder and restart or reload the server. This will generate the configuration files for the plugin in the 'SAML' folder in your plugin directory.

    There's a lot for you to configure. Here's what the config file looks like:
    Code (YAML):

    # Don't change this!
    version
    : 8

    # !! Please do not edit the lines containing 'section-begin' or 'section-end'. These are for updating the config !!

    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Features                                                                                                          |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: features

    # Do you want a config file with more options to generate?
    #   * Most of the options in the advanced_config.yml just allow you to specify some of the settings in the 'Gameplay
    #     settings' section per entity type.
    use-advanced-config
    : false

    # Should we be running a freeze task at all times that will freeze mobs as specified in the ?
    #   * You can define in the 'Passive freeze parameters' section exactly what should or should not be frozen/nerfed.
    #   * This is intended to be used to freeze or nerf large animal farms in which the mobs don't really require AI.
    enable-passive-freeze-task
    : true

    # If the above is enabled, every how many ticks should we run this task?
    ticks-per-passive-freeze-task
    : 1200

    # Should we run a separate freeze task that will freeze certain mobs when the TPS drops below a certain threshold?
    #   * You can define in the 'TPS freeze parameters' section exactly what will be frozen/nerfed in this task and when it
    #     will activate.
    #   * The idea is that it should be more aggressive than the passive freezing task so that you are sacrificing mob AI
    #     to regain your TPS.
    enable-tps-freeze-task
    : true

    # If the above is enabled, every how many ticks should we run this task?
    ticks-per-tps-freeze-task
    : 1200

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Frozen chunk cache settings                                                                                       |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: frozen_chunk_cache_settings

    # Should we keep a list of chunks containing frozen mobs so that we may be able to unfreeze them if the plugin doesn't
    # shut down correctly?
    #   * Keep this as true if you think you'll uninstall this plugin at some point. This will allow you to unfreeze all the
    #     frozen mobs in your world easily.
    keep-frozen-chunk-cache
    : true

    # On startup, should we unfreeze mobs which were not unfrozen previously?
    #   * Warning: this operation loads chunks and therefore can cause a lot of lag.
    unfreeze-cached-chunks-on-startup
    : false

    # Every how many ticks should we unfreeze these mobs?
    ticks-per-cached-chunk-unfreeze
    : 5

    # Do you use Paper? If so, do you want the above task (the cache unfreezing task) to run in a more efficient manner?
    use-paper-get-chunk-async
    : false

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Passive freeze parameters                                                                                         |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: passive_freeze_parameters

    # Which groups of mobs should be frozen when we run a passive freeze task?
    passive-freeze-groups
    :
    #  - dense_animal_farm

    # Which groups of mobs should we never freeze when running a passive freeze task?
    passive-freeze-exclude-groups
    :

    # Which groups of mobs should be nerfed when we run a passive freeze task?
    passive-nerf-groups
    :
     - animal_farm

    # Which groups of mobs should we never nerf when running a passive freeze task?
    passive-nerf-exclude-groups
    :
    #  - dense_animal_farm

    # Should we unfreeze/unnerf mobs that were previously passively frozen/nerfed if they are no longer in the groups
    # specified above?
    #   * For example: if a cow was frozen because it was in a large mob farm, if the above is true it will be unfrozen if
    #     every other mob in that farm were to be killed.
    passive-do-cleanup
    : true

    # Should we send a message to the console when when starting/completing a passive freeze task?
    #   * The messages can be specified in the messages.yml file.
    passive-freeze-broadcast-to-console
    : false

    # Should we send a message to players with the permission 'saml.notify' when starting/completing a passive freeze task?
    #   * The messages can be specified in the messages.yml file.
    passive-freeze-broadcast-to-ops
    : false

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Tps freeze parameters                                                                                             |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: passive_freeze_parameters

    # Which groups of mobs should be frozen when we run a TPS freeze task?
    tps-freeze-groups
    :
     - default_group # <- see the 'Default group settings' section to tweak how this group works.
      - lag_causers
    #  - default_singular # <- just freeze everything!

    # Which groups of mobs should we never freeze when we run a TPS freeze task?
    tps-freeze-exclude-groups
    :

    # Which groups of mobs should be nerfed when we run a TPS freeze task?
    tps-nerf-groups
    :

    # Which groups of mobs should we never nerf when running a TPS freeze task?
    tps-nerf-exclude-groups
    :

    # When the server's TPS drops below this, we will start freezing mobs.
    tps-freezing-threshold
    : 18.5

    # When the server's TPS rises above this, we will begin unfreezing mobs again.
    #   * This should be higher than the tps-freezing-threshold!
    tps-unfreezing-threshold
    : 19.5

    # At least how many standard deviations should the tps be away from the tps-unfreezing-threshold before we start
    # unfreezing mobs?
    #   * The standard deviation of the TPS is effectively a measure of stability. This setting enables the plugin to only
    #     unfreeze mobs when the TPS is reasonably stable.
    #   * A higher confidence range means we require more stability.
    #   * It's best to keep this value in the range of 1 to 5.
    tps-unfreeze-confidence-range
    : 2.5

    # At most how many mobs should be unfrozen in any given operation?
    tps-unfreeze-limit
    : 40

    # How much should certain types of mobs contribute to the unfreeze limit above?
    #   * If not specified, a mob will contribute 1 to the unfreeze limit by default.
    #   * For an example of how this works: If pillagers have a weight of 10 and the unfreeze limit is 40, then at most 4
    #     pillagers will be unfrozen as 4 * 10 = 40.
    #   * The unfreeze limit will never be overshot; so if the unfreeze limit was 40, for example, and chickens had a weight
    #     of 41, then chickens would never be unfrozen.
    tps-unfreeze-weights
    :
      PILLAGER
    : 8
      VILLAGER
    : 4
      fish
    : 2

    # What is the minimum amount of time (in milliseconds) that we should wait after freezing a mob before unfreezing it?
    tps-minimum-freeze-time
    : 300000

    # Should we unfreeze/unnerf mobs that were previously affected by a TPS freeze, but in their current state would not be
    # affected?
    #   * This is less important than with the passive freeze task, as mobs frozen/nerfed by the TPS freeze task will be
    #     unfrozen/unnerfed when the TPS rises.
    tps-do-cleanp
    : false

    # Should we send a message to the console when when starting/completing a TPS freeze task?
    #   * The messages can be specified in the messages.yml file.
    tps-freeze-broadcast-to-console
    : true

    # Should we send a message to players with the permission 'saml.notify' when starting/completing a TPS freeze task?
    #   * The messages can be specified in the messages.yml file.
    tps-freeze-broadcast-to-ops
    : false

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  TPS calculator settings                                                                                           |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: tps_calculator_settings

    # Over how many ticks should we calculate the TPS?
    tps-sample-size
    : 900

    # We use a weighted average for the TPS such that it better reflects the current state of the server. What factor should
    # we use for scaling?
    tps-weighting-factor
    : 0.995

    # We average the TPS over some amount of time so it's not affected by momentary lag spikes. Over how many ticks should
    # we average the TPS?
    tps-smoothing-sample-size
    : 400

    # Should we use the built-in Minecraft TPS instead?
    #   * If set to true the tps-sample-size setting will not do anything. The sample size will be fixed to one minute (1200
    #     ticks).
    use-nms-tps
    : false

    # Every how many ticks should we take a sample of the TPS for calculating the standard deviation?
    tps-deviation-sample-rate
    : 50

    # How many samples of the TPS should we include in the calculation of the standard deviation?
    #   * It is recommended that this value is such that (tps-deviation-sample-rate)*(tps-deviation-sample-size) is roughly
    #     equal to 2*(ticks-per-operation).
    tps-deviation-sample-size
    : 24

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Generic freeze parameters                                                                                         |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: generic_freeze_parameters

    # How long (in milliseconds) should the freezing operation be allowed to take?
    #   * If this is set too high there may be noticeable lag spikes when we freeze mobs (unless you have use-async-grouping
    #     set to true).
    #   * If this is set too low it may not have enough time to group all the entities.
    #   * If you have use-async-grouping set to false it's best to set this below 500 to avoid noticeable lag spikes.
    maximum-operation-time
    : 5000

    # Should we run the mob grouping algorithm asynchronously?
    #   * Having this set to true will mean the server won't hang when running a freeze.
    #   * There's no real reason to have this set to false; the only reason this option is here is in case the async
    #     grouping is causing errors.
    use-async-grouping
    : true

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Default group settings                                                                                            |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: default_group_settings

    # If there are any more than the group-minimum-size number of mobs within group-maximum-radius of each other this will
    # constitute a group of mobs.
    group-minimum-size
    : 10
    group-maximum-radius
    : 8.0

    # Should we only group mobs of the same type?
    #   * If this is set to true then a collection consisting of 2 horses, 3 pigs and 4 cows won't constitute a group, but a
    #     collection of 10 chickens would.
    #   * This is a good option if you only really want farms to be frozen.
    group-require-same-type
    : false

    # Should we scale the maximum radius and minimum size required of a group depending on how much the server is lagging?
    group-use-smart-scaling
    : true

    # If we do scale the maximum radius and minimum size, what are the limits at which we should scale them no-further?
    group-minimum-scaled-size
    : 5
    group-maximum-scaled-radius
    : 20

    # At what ratio of the TPS freezing threshold to current TPS should the limits above be reached?
    #   * I.e. when the TPS reaches minimum-scale-tps-ratio * tps-freezing-threshold the minimum size and maximum radius of
    #     the groups will be the above values.
    group-minimum-scale-tps-ratio
    : 0.50

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Compatibility settings                                                                                            |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: compatibility_settings

    # We will never ignore mobs with metadata on this list.
    #   * Plugins can add metadata to entities that allows other plugins to identify them with that plugin.
    #   * If SAML interferes with some other plugin's entities, please ask that plugin's developer to add identifying
    #     metadata to them.
    ignore-metadata
    :
     - Elitemob  # This ignores elite mobs from the plugin EliteMobs.
      - Elitemobs_NPC # This ignores NPCs from the plugin EliteMobs.
      - infernalMetadata # This ignores infernal mobs from the plugin InfernalMobs.
      - NPC # This ignores NPCs from the plugin Citizens.
      - shopkeeper # This ignores shopkeepers from the plugin Shopkeepers.
      - mythicmob
    #  - Supermob  # This ignores super mobs from the plugin EliteMobs.

    # We will never run a freeze these worlds.
    ignore-world
    :
     - example_world_the_end

    # Should we only unfreeze mobs which have been tagged by SAML (i.e. mobs we are sure that we have frozen)?
    #   * Keep this option as true if you use another plugin that freezes mobs, or if you summon in mobs with the 'NoAI'
    #     tag.
    #   * Note that for versions before 1.14 there is no way of keeping metadata across server restarts, so if this option
    #     is set to true and some SAML-frozen entities remain frozen after a server restart, SAML will not unfreeze them.
    only-unfreeze-tagged
    : true

    # Should we unfreeze mobs when the chunk they are in is unloaded?
    unfreeze-on-unload
    : true

    # Should we unfreeze all the loaded mobs when the plugin shuts down?
    unfreeze-on-shutdown
    : true

    # section-end
    # +--------------------------------------------------------------------------------------------------------------------+
    # |  Gameplay settings                                                                                                 |
    # +--------------------------------------------------------------------------------------------------------------------+
    # section-begin: gameplay_settings

    # Should we stop mobs from targeting mobs that are frozen?
    #   * This is mostly concerned with preventing mobs from attacking frozen mobs.
    prevent-targeting-frozen
    : true

    # Should we stop mobs from being able to damage frozen mobs?
    prevent-damaging-frozen
    : true

    # Should we stop players from being able to damage frozen mobs?
    prevent-player-damaging-frozen
    : false

    # Should we unfreeze mobs when interacted with by a player?
    unfreeze-on-interact
    : true

    # Below what TPS should we ignore the option above and not unfreeze mobs that are interacted with?
    #   * Set to 0 to disable this option.
    unfreeze-on-interact-tps-threshold
    : 0

    # Should we unfreeze mobs when they take damage?
    unfreeze-on-damage
    : true

    # Below what TPS should we ignore the option above and not unfreeze mobs that take damage?
    #   * Set to 0 to disable this option.
    unfreeze-on-damage-tps-threshold
    : 0

    # Should tamed mobs (cats, dogs, horses, etc.) never be frozen?
    ignore-tamed
    : true

    # Below what TPS should we ignore the option above and start freezing mobs that are tamed?
    #   * Set to 0 to disable this option.
    ignore-tamed-tps-threshold
    : 0

    # Should we ignore mobs named with a name tag?
    ignore-named
    : true

    # Below what TPS should we ignore the option above and start freezing mobs that are named?
    #   * Set to 0 to disable this option.
    ignore-named-tps-threshold
    : 0

    # Should we ignore mobs that are leashed?
    ignore-leashed
    : true

    # Below what TPS should we ignore the option above and stop ignoring mobs that are leashed?
    #   * Set to 0 to disable this option.
    ignore-leashed-tps-threshold
    : 0

    # Should we ignore mobs that are in love mode (breeding mode)?
    ignore-love-mode
    : true

    # Below what TPS should we ignore the option above and stop ignoring mobs that are in love mode?
    #   * Set to 0 to disable this option.
    ignore-love-mode-tps-threshold
    : 0

    # At what distance (in blocks) should we ignore mobs that are within that distance of a player?
    #   * Note that this is quite an expensive check. If you have a lot of players it may make the freezing operation last
    #     significantly longer.
    #   * Set to 0 to disable this option.
    ignore-player-proximity
    : 0

    # Below what TPS should we ignore the option above and stop ignoring mobs that are close to players?
    #   * Set to 0 to disable this option.
    ignore-player-proximity-tps-threshold
    : 0

    # For what age in (in ticks) should we ignore mobs that are younger than that age?
    #   * This option effectively allows you to ignore recently spawned mobs. It is good for preventing certain types of
    #     farms or grinders clogging up.
    #   * Set to 0 to disable this option.
    ignore-younger-than-ticks
    : 600

    # Below what TPS should we ignore the option above and stop ignoring mobs of any given age?
    #   * Set to 0 to disable this option.
    ignore-younger-than-ticks-tps-threshold
    : 0

    # Should we ignore mobs that are targeting players (e.g. mobs attacking a player)?
    ignore-target-player
    : true

    # Below what TPS should we ignore the option above and stop ignoring mobs that are targeting a player?
    #   * Set to 0 to disable this option.
    ignore-target-player-tps-threshold
    : 0

    # We will ignore mobs whose type is on this list.
    #   * See https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html for a list of types.
    #   * This is CaSE SenSiTIVe!
    never-freeze
    :
     - PILLAGER
      - VINDICATOR
      - VEX
      - WITCH
      - RAVAGER
      - ILLUSIONER
      - EVOKER

    # Below what TPS should we ignore the option above and stop ignoring mobs with type on this list?
    #   * Set to 0 to disable this option.
    never-freeze-tps-threshold
    : 0

    # section-end
     

    Commands and permissions
    Commands:
    • /saml - Base command for the plugin, tells you the version.
    • /saml reload - Reloads the config files for the plugin.
    • /saml stats - Displays the total number of frozen mobs server-wide and per world.

    Permissions:

    • saml.saml - Gives access to the /saml command.
    • saml.notify - You will be notified when a freezing operation begins and ends (If enabled in config).

    Compatibility
    The plugin will run for versions between 1.9 and 1.14. However, not all features are available for lower versions. Below version 1.13 it is not possible to use the ignore-love-mode or use-paper-get-chunk-async options in the config. This is because it uses API which did not exist at the time. Unfortunately, 1.8 will never be able to be supported as the main API we use to 'freeze' mobs did not exist in 1.8.

    You will require Java 8 or higher to run this plugin.

    Villagers in 1.14
    If you are using 1.14.2+ you may be interested in the following plugin: Villager Optimiser. This can greatly improve the performance of villagers by forcing them to perform pathfinding operations less frequently. If you have a high 'tickEntity' reading in your timings reports, and nothing else is standing out, then give this a try - it may help!

    Planned features
    • Custom groups - better ability to decide which mobs should be frozen. E.g. things like villagers in iron farms, chicken farms, endermen grinders, etc.
    • Async entity grouping.
    • Ability to perform a freeze through a command - with lots of options available.
    • Passive freezing of mobs: ability to choose groups or types of mobs that should always be frozen, even when the TPS isn't low.
    • Option to use a 'soft' freeze which doesn't disable certain things, e.g. sheep eating grass.
    • Option to use more sensitive values of TPS to prevent a ping-pong effect where mobs are constantly frozen, unfrozen, frozen, ...
    • More options to reduce impact on gameplay.
    Feel free to leave any suggestions in the discussion thread.

    Please note: If you disable unfreeze-on-unload and unfreeze-on-shutdown in the config, frozen entities will be saved to your world. If you then uninstall the plugin these entities will not be unfrozen. If you don't want either of these options enabled, and if you think you're going to uninstall the plugin at some point, it is recommended to have the 'keep-frozen-chunk-cache' option in the config set to true.

    Metrics: We use bStats to collect some non-identifying information about servers using this plugin. You can opt-out by editing the config.yml in the 'bStats' directory of your plugins folder.
    [​IMG]
    nullizer, Harry0198, tensided and 3 others like this.

Recent Updates

  1. Simple Anti-Mob Lag 2.0.0
  2. Simple Anti-Mob Lag 1.3.5
  3. Simple Anti-Mob Lag 1.3.4

Recent Reviews

  1. dsjds1010
    dsjds1010
    5/5,
    Version: 2.0.0
    A very good optimized plugin that is constantly being fixed and improved upon, a huge vouch to minimize mob lag.
    1. froobynooby
      Author's Response
      Thanks for the review! Glad you like the plugin
  2. LoneDev
    LoneDev
    5/5,
    Version: 2.0.0
    Must have for every 1.14.4 server, forget about lag :D
    1. froobynooby
      Author's Response
      Thanks for the review! Glad it's working for you
  3. Appa117
    Appa117
    5/5,
    Version: 1.3.5
    Excellent plugin!

    Very nice plugin to reduce server workload.

    It is nicly active in the background and is only truely visible if you are farming large quantities of freindly mobs. But even then the mobs start moving again once you feed or damage them.

    I can really recommend this.

    Very nice work. Keep it up!
    1. froobynooby
      Author's Response
      Thanks very much for the review! Happy you like the plugin
  4. samo_lego
    samo_lego
    5/5,
    Version: 1.3.5
    Helped a lot, thanks man! Working like a charm, easy to setup ... great! Definetely recommending to others!
    1. froobynooby
      Author's Response
      Happy it's working! Thanks for the review
  5. HexedHero
    HexedHero
    5/5,
    Version: 1.3.5
    Amazing plugin, thank you froobynooby <3 Lifesaver for posting this and the villager plugin
    1. froobynooby
      Author's Response
      Thanks for the review! I'm happy that the plugins are helping people
  6. Gustavo_Player
    Gustavo_Player
    5/5,
    Version: 1.3.5
    Thank you! =)
    1. froobynooby
      Author's Response
      Thank you for the review!
  7. Jonidipp
    Jonidipp
    5/5,
    Version: 1.3.3
    MUST HAVE FOR 1.14.2

    Ive been haunted by high stagnant cpu usage for my server but now its fixed! THANKS!
    1. froobynooby
      Author's Response
      Glad that it's helped you out! Thanks for the review.
  8. alexeppy
    alexeppy
    5/5,
    Version: 1.3.2
    Great plugin, a good stacking plugin I've been waiting for, a must have and reliable and updated plugin!
    1. froobynooby
      Author's Response
      Thanks very much for the review! Glad you like the plugin.
  9. LogoCat
    LogoCat
    5/5,
    Version: 1.2.6
    This is effective against many kinds of situations based on server owner's setting. For example, for iron farm it need tens to hundreds of villagers. This plugin saved my TPS from 9 to 15, handing over 300 villagers. And it's open-sourced. Survival servers should use this plugin for for both efficiency and experience.
    1. froobynooby
      Author's Response
      Good to hear the plugin has worked for you. Thanks for the review!
  10. Richmold
    Richmold
    5/5,
    Version: 1.2.2
    Awesome! Lags are gone completely!
    I have suggestions for the plugin:
    Add your placeholders to scoreboard:
    The number of entities already frozen.
    The number of non-frozen entities.
    1. froobynooby
      Author's Response
      Thanks for the review! I'm glad the plugin is working for you.

      I'll definitely try to add placeholders in a future update.