MiniBossBarsPerf - performance override for "Mini-boss Boss Bars 1.21.1 1.0.35.jar"
==================================================================================

WHAT AND WHY
The mod is a datapack. bossbar_setup/main runs every tick (#minecraft:tick) and tick_per_second runs
every 22 ticks. Most of its lines are "tag @e[type=X,tag=!miniboss_bossbars__bossbar_haver] add ..."
whose only job is to label NEW boss mobs, but each one is a pass over every loaded entity in every
dimension. Lines with nbt= or "if data entity" also save an entity's full NBT for every test.

Cost of the jar files that actually load here (read from the files and the 2026-10-17 log):
  every tick      61 full-entity scans (main 5, mutant_monsters 26, ice_and_fire 30), plus a full NBT save
                  of every boss-bar mob twice, every mutant zombie 9 times and every Ice and Fire dragon 4 times
  every 22 ticks  238 more scans (tick_per_second's mod files), plus mob_champions: a full NBT save of
                  EVERY loaded entity, three times, for a mod that is not installed
  every 40 ticks  apotheosis: a full NBT save of EVERY loaded entity, plus 2 scans per newly seen entity
This pack overrides the same function ids. Boss bars, colours, styles and names, HP updates, how bars are
deleted, /trigger mbbbforceshowbossbars and mutant zombie life changes all behave as before.
After: about 6 scans per tick in steady state (main 2, mutant_monsters 2, ice_and_fire 2, plus 4 every
22 ticks and about 6 every 40 ticks). No full-NBT pass over every entity remains: each entity is
NBT-checked for Health once in its lifetime.

FILES OVERRIDDEN (data/mini_boss_boss_bars/function/)
  bossbar_setup/main      Jar lines 1, 2, 4 and 6 run per boss-bar mob from one scan (mbbbperf:main/haver_tick).
                          The Owner NBT check skips mobs already exempt. The HurtTime NBT check only runs for a
                          bar-less, non-exempt mob whose attacker is a player: checkifattackedbyplayerbeforecreatingbossbar
                          does nothing for any other mob. The other lines are copied verbatim.
  tick_per_second         4 scans plus a per-mob dispatch replace ~240 scans. The jar's lines run per mob from
                          mbbbperf:classify/<jar file> (one file per jar file, so one bad id breaks only that mod,
                          as before). The calls to files that fail to load today are kept.
                          It reschedules itself on its first line instead of its last, so a run cut short by
                          maxCommandChainLength cannot end the 22-tick loop. battle_towers, fishing_expansion,
                          the_harvester and dungeons_and_taverns are dispatched only to mobs with a boss tag their
                          lines need, so ordinary drowned, wither skeletons, phantoms, cave spiders, shulkers and
                          breezes skip them.
  mutant_monsters         One per-tick label scan and one Lives scan. Lives is read once per zombie instead of 9
                          times. Load guard: the file fails to load without the mod, like the jar's file.
  ice_and_fire            One per-tick label scan and one dragon scan. At most 2 NBT reads per dragon instead of 4.
                          Load guard as above.
  apotheosis              Health is probed once per entity lifetime instead of every 40 ticks. limit=1 on the
                          existence test.
  extras/apotheosis/detect_boss_entity_p1, _p2
                          p2's last two lines (tag every iamanapotheoticboss mob with styled_progress and haver)
                          run once per p1 pass instead of once per newly seen entity.
  mob_champions           Empty. Mob Champions is not installed, so its effect id cannot exist and the lines never matched.
New namespace mbbbperf: classify/*, dispatch/*, main/haver_tick, mutant_monsters/*, ice_and_fire/dragon_state,
apotheosis/health_probe, and the entity type tags candidates/<jar file>, per_second_early, per_second_late.
Every tag entry is "required": false, so a missing mod cannot break a tag.
Everything else in the jar is untouched: create/setup/delete/deleter_tick/live_modify/load and the rest.
The 48 files that fail to load today because their mod is not installed are also untouched and still fail.
The line-by-line map is in the staging folder: lagfix-1021/bossbar_line_map.tsv.

WHY IT IS THE SAME (the reasoning, in case the jar is updated)
- Labels are added once. Candidates are scanned only while they lack miniboss_bossbars__bossbar_haver, and
  nothing in the jar ever removes that tag or any colour/style/name label. The only tags it removes are
  has_bossbar, boss_exception_byforce and temporary selection tags. Every label line already skipped havers.
  The scans run at the jar's times: every tick for mutant_monsters and ice_and_fire (a boss must be labelled
  before its first hit, because bar creation keys off HurtTime 9, which lasts one tick), and every 22 ticks
  for the rest.
- Each mob meets the jar's files in the jar's order. The 22-tick scans are split around wasd_random_bosses
  and moar_bosses because those two select by tag on any mob type.
- tick_per_second's reschedule moved from its last line to its first. Both target the same game time (schedule
  replaces the pending entry and both run in the same tick). The difference: a run stopped at maxCommandChainLength
  (65,536 commands) drops everything still queued, and it would have dropped a last-line reschedule with it.
- Every line of battle_towers needs bt_baller, of fishing_expansion fishing_expansion.mob.boss.elder_drowned, of
  the_harvester harvester, and of dungeons_and_taverns one of its nine boss tags (shulker_miniboss ... cave_spider_boss_ominous).
  A mob without them could not match any of those lines, so the dispatch now tests the tag before calling the file.
  Without that, every ordinary mob of those types re-ran the whole file on every 22-tick pass for as long as it was loaded.
- born_in_chaos lines 46-52 (the mobmergedid tags) used to run on havers too. They now run until the mob is
  labelled. That tag is only read by lines that skip havers.
- Main line 1 tagged every entity of type #minibossbossbars:boss_exception. No jar or datapack in this pack
  defines that tag, and the exception tag is only read on havers, so it is now applied to each haver at the
  start of main.
- The HurtTime check is skipped for a mob whose attacker is not a player. checkifattackedbyplayerbeforecreatingbossbar
  only creates a bar through "execute on attacker as @s[type=player]", so for such a mob it only added and removed
  its own temporary tag.
- Owner and HurtTime still run every tick. The exemption must land before the HurtTime check, and
  deleter_tick drops a newly tamed boss's bar on the same tick.
- Mutant zombies: the jar's line 35 tests mutantzombie2lives where it means 0lives. Because of that, a
  zombie that went 3 -> 2 -> 1 -> 0 lives re-ran create_bossbar every tick of its last life, and each run
  summoned another deleter marker (about 600 markers in a 30 s last life, each doing about 6 full scans a
  tick). The typo is kept, so the bar is still re-applied every tick. A deleter that is already standing on
  the zombie is reused instead of summoning a new one, so the visible result is the same.

NEW STATE THIS PACK LEAVES IN THE WORLD (all harmless)
- Entity tag mbbbperf.no_health on non-living entities (arrows, item frames, markers, ...), so they are
  probed only once. Living mobs, items and XP orbs get the jar's own ihashealthy tag, as before.
- Data storage mbbbperf:tmp, which is emptied after each use.
- Fake players #mbbbperf_hit, #mbbbperf_id and #mbbbperf_reuse in the jar's miniboss_bossbars__bossbar_stuff objective.
- Install note: on the first 40-tick apotheosis slot, every entity already loaded is probed once. That costs
  the same as one run of the jar's old line 3, and only happens once.

IF THINGS CHANGE
- If Mob Champions is added to the pack, delete mob_champions.mcfunction from this pack.
- If a mod whose jar file fails today is added (Friends & Foes, Occultism, ...), its jar file starts loading
  and runs unoptimised, exactly as it would without this pack.
- If Mini-boss Boss Bars is updated, diff the new jar's files against these overrides (they copy 1.0.35's lines).

HOW TO TEST (dev instance, singleplayer)
- Spawn a boss (e.g. /summon cataclysm:ender_golem). Within about 1 s it should have the haver and colour tags
  (/data get entity @e[type=cataclysm:ender_golem,limit=1,sort=nearest] Tags). Hit it, and a purple bar named
  Ender Golem should appear and track HP. Walk away beyond 60 blocks and the bar should disappear. Kill it
  and the bar should go.
- /summon mutantmonsters:mutant_zombie, then fight it through all three lives. The bar should come back
  after each revive. During its last life the deleter count should stay at 3 or 4 instead of growing:
  /execute store result score #n miniboss_bossbars__bossbar_stuff if entity @e[tag=miniboss_bossbars__bossbardeleter]
- /trigger mbbbforceshowbossbars near an unhit boss should show its bar.
- Ice and Fire dragon: the bar should drop when it sleeps or dies.
- Boss-tag gates: /summon cave_spider ~ ~ ~ {Tags:["cave_spider_boss"]}, /summon drowned ~ ~ ~ {Tags:["fishing_expansion.mob.boss.elder_drowned"]}
  and /summon wither_skeleton ~ ~ ~ {Tags:["bt_baller"]} should each get the haver tag and a name label within about 1 s.
  A plain /summon cave_spider should not.
- Cost check: /debug start, wait, then /debug stop, or use spark. Compare against the jar alone:
  /schedule clear mini_boss_boss_bars:tick_per_second stops the 22-tick half.

HOW TO REMOVE
Delete this folder (config/paxi/datapacks/MiniBossBarsPerf), then restart (on the live server, avoid
/reload: it freezes about 44 s). The jar's own files take over again. The leftover tags, storage and fake
players listed above are inert.
