Kill-Switches
How binary kill-switches work in configs/apis.yml, the internal FeatureRegistry engine, and NullPointerException safety guarantees.
Kill-Switches in configs/apis.yml let you turn off any subsystem you do not need (mob AI, natural spawning, redstone, chunk ticks, recipes, or advancements) with a single false flag without breaking plugin compatibility.
Here is how the internals work under the hood for server admins and plugin developers.
How FeatureRegistry Works
Section titled “How FeatureRegistry Works”Phase 1: Bitmask Packing (applyEarly)
Section titled “Phase 1: Bitmask Packing (applyEarly)”All 77 boolean engine flags live in the Feature enum (MAX_SUPPORTED_FEATURES = 128). During early startup in ApisConfig.loadEarly, FeatureRegistry.applyEarly(config) packs them into two volatile long fields:
public static boolean isDisabled(final Feature feature) { return feature.word == 0 ? (disabledMask0 & feature.bit) != 0L : (disabledMask1 & feature.bit) != 0L;}- A bit is set to
1when its value inconfigs/apis.ymlisfalse(kill-switch active). - Numeric limits from
packet-range-clamping(projectileTrackingRange,particleBroadcastRangeSq,armorEquipmentRange) are cached alongside the bitmasks.
Phase 2: Registry Resolution (resolveRegistries)
Section titled “Phase 2: Registry Resolution (resolveRegistries)”Once RegistryAccess exists (inside DedicatedServer.initServer() and on /apis reload), FeatureRegistry.resolveRegistries(...) resolves runtime sets:
- String keys from
dimensions.enabled,dimensions.always-ticking,dimensions.never-ticking, andentities.ai.type-filterare converted into immutableReferenceOpenHashSetinstances (enabledDimensions,alwaysTickingDimensions,neverTickingDimensions,aiTypeFilterTypes). - Runtime lookups use fast identity comparisons (
==/ identity hash) in memory. minecraft:overworldis always protected and force-added toenabledDimensions, even if removed from YAML.- Dynamic dimension ticking (
isWorldTickDisabled) checks in order:never-ticking->always-ticking-> active players in world (empty worlds outsidealways-tickingdo not tick).
Switch Groups & Code Behavior
Section titled “Switch Groups & Code Behavior”1. Mob AI (entities.ai)
Section titled “1. Mob AI (entities.ai)”entities: ai: enabled: false type-filter: - minecraft:villager sub-features: goal-selector: false brain: false pathfinding: false sensors: false- Master switch (
entities.ai.enabled: false) andtype-filter:- Skips
this.registerGoals()in theMobconstructor (Mob.java.patch). - Returns immediately in
Mob#inactiveTick()andMob#serverAiStep().
- Skips
- Sub-features (applied when
entities.ai.enabled: true):goal-selector: false- earlyreturninGoalSelector#tick()andGoalSelector#tickRunningGoals(boolean).brain: false- earlyreturninBrain#tick(...)and skipsBrainNBT deserialization inLivingEntity#readAdditionalSaveData.pathfinding: false- earlyreturninPathNavigation#tick().sensors: false- earlyreturninBrain#tickSensors(...)andSensing#tick().
2. Natural Spawning (spawning.natural)
Section titled “2. Natural Spawning (spawning.natural)”spawning: natural: enabled: false sub-features: monsters: false animals: false custom-spawners: falsespawning.natural.enabled: false: setsdoMobSpawning = falseandspawningCategories = List.of()inServerChunkCache#tickChunks, and passesCollections.emptyList()for custom spawners inMinecraftServer#createLevel.monsters: false/animals: false: dropsMobCategory.MONSTERor the remaining categories inNaturalSpawner#getFilteredSpawningCategories, and zeros spawn counts per category inServerChunkCache#tickChunks.custom-spawners: false: skips registeringPhantomSpawner,PatrolSpawner,CatSpawner,VillageSiege, andWanderingTraderSpawnerwhen initializing the Overworld.
3. Chunk, Block, Fluid & Physics Ticks
Section titled “3. Chunk, Block, Fluid & Physics Ticks”chunks.ticking.enabled: false: skipstickChunkscompletely inServerChunkCache#tick(random-ticks,block-ticks,fluid-ticks, andpoi-tickingare bypassed).random-ticks: false: skips random block ticks inServerLevel#tickChunk.block-ticks: false/fluid-ticks: false: disablesblockTicks.tickandfluidTicks.tickinServerLevel#tick.poi-ticking: false: skipsPoiManager#tickspatial index updates inChunkMap.block-entities.ticking.enabled: false: earlyreturninLevel#tickBlockEntities()(stops furnaces, beacons, hoppers, etc.);hoppers: falsetargetsHopperBlockEntity#pushItemsTick.blocks-and-physics:redstone: false-> earlyreturninupdateSurroundingRedstone,onPlace, andneighborChangedonRedstoneWireBlock.block-gravity: false-> earlyreturninFallingBlock#tick.leaf-decay: false-> earlyreturninLeavesBlock#randomTick.fire-spread: false-> earlyreturninFireBlock#tick.item-physics: false->ItemEntity#tickrunsthis.inactiveTick(); return;(keeps pickup and despawn timers running, skips gravity, movement, and collisions).block-events: false-> skipsServerLevel#blockEventandrunBlockEvents, clearingblockEvents.clear().
4. World Environment & Entities (world-environment, entities)
Section titled “4. World Environment & Entities (world-environment, entities)”world-environment:world-border-tick: false- skips per-tickWorldBorder#tickinServerLeveland clientCraftWorldBorderupdates.environment-attributes: false- skipsinvalidateTickCache()inEnvironmentAttributeSystem.game-events: false- skips vibration broadcasts inServerLevel#gameEvent(GameEventDispatcher#post).
entities:despawn-checks: false- skips per-tickEntity#checkDespawn()inServerLevel.inside-block-checks: false- skipscheckInsideBlocksandinsideEffectCollector(cobwebs, portals, berry bushes).fluid-interaction: false- skipsupdateFluidInteraction()andupdateSwimming()inEntity#baseTick, forcingwasEyeInWater = false.sprint-particles: false- skipsEntity#spawnSprintParticle().
5. Player Mechanics & Progression (players, gameplay.advancements)
Section titled “5. Player Mechanics & Progression (players, gameplay.advancements)”players.locator-bar: false: early exit inServerWaypointManager(trackWaypoint,updateWaypoint,addPlayer,updatePlayer) and disablesWAYPOINT_TRANSMIT_RANGE/isReceivingWaypoints()tracking inServerPlayer.players.inventory-special-item-updates: false: skips per-tick inventory slot scans insynchronizeSpecialItemUpdates(maps, compasses).players.vanilla-scoreboard-criteria: false: skips updating vanilla scoreboard criteria inupdateScoreForCriteria.players.floating-kick: false: disables hover kick counters (aboveGroundTickCountandaboveGroundVehicleTickCount) inServerGamePacketListenerImpl.players.statisticsandgameplay.advancements: criteria triggers (CriteriaTriggers.TICK,LEVITATION,LOCATION) followgameplay.advancementsexclusively, whileplayers.statistics: falseonly blocksawardStat,resetStat,checkRidingStatistics, and movement stat counters (causeFoodExhaustionstill works ifplayers.hunger: true).players.data-saving: falseorstorage.world-saving: false: unifiedisPlayerDataSavingDisabled()check blocksServerStatsCounter#save,PlayerAdvancements#save, and legacy migration (<name>.json -> <uuid>.json), guaranteeing0disk writes understats/andadvancements/(even empty folders are never created).
6. Periodic Autosave (storage.periodic-autosave)
Section titled “6. Periodic Autosave (storage.periodic-autosave)”storage.periodic-autosave: falsedisables background tick-time saving inMinecraftServer(autoSave(), incrementalplayerList.saveAll,saveGlobalData,saveIncrementally) andChunkMap(chunkHolderManager.autoSave()).- Chunk unloads,
/save-all, and shutdown saves still run normally. Settingstorage.world-saving: falsedisables this automatically too.
7. Datapack Registry Pruning (Pre-Disk Pruning)
Section titled “7. Datapack Registry Pruning (Pre-Disk Pruning)”When gameplay.recipes, gameplay.advancements, gameplay.loot-tables, chunks.structures, chunks.biome-decoration, or startup.test-registries are set to false, ResourceManagerRegistryLoadTask.load and TagLoader skip scanning the filesystem (listMatchingResources) and skip JSON parsing altogether for those registries. When chunks.structures: true and chunks.biome-decoration: false, only Registries.CARVER is pruned while FEATURE / PLACED_FEATURE remain intact for structure generation (ChunkGenerator still skips chunk decoration).
If gameplay.advancements: true while chunks.structures: false or gameplay.recipes: false, recipes use a read-only lookup and any dependent advancements (plus their parent children) are softly skipped with a single startup WARN. Remaining vanilla and custom advancements keep working, while real broken datapack JSON files still report normal load errors.
Safety Guarantees & NullPointerException Protection
Section titled “Safety Guarantees & NullPointerException Protection”Disabling systems in Apis never leaves internal Minecraft fields null or breaks Bukkit/Paper API contracts:
| Subsystem | Safety Mechanism (Fallback Objects & Contracts) |
|---|---|
| Mob AI | goalSelector, targetSelector, navigation, sensing on Mob, plus default Brain on LivingEntity, are built before checking isAiDisabled. Calling API methods on an empty GoalSelector is safe. |
| Mob Spawning | ServerChunkCache#tickChunks and MinecraftServer#createLevel work with non-null empty lists (List.of(), Collections.emptyList()). |
| Pruned Datapack Registries | RegistryLoadTask#freezeRegistry calls bindAllTagsToEmpty() and ApisHooks.bindPrunedFallbackHolders, binding dangling Holder.Reference entries to safe stubs (LootTable.EMPTY, AllOfCondition, SequenceFunction, EmptySlotSource). MappedRegistry#get(TagKey) returns a lazy empty HolderSet.Named backed by prunedFallbackTags. |
| Recipes & Advancements | RecipeManager initializes RecipeMap.EMPTY and List.of(); ServerAdvancementManager builds ImmutableMap.of() and new AdvancementTree(). |
DFU (startup.datafixers: false) |
DATA_FIXER and FILE_FIXER are never null: DataFixers#createFixerUpper builds an empty schema 0 (createEmptyDataFixerSchema using ConcurrentHashMap<> and DSL.remainderType()) with a no-op DataFix. Loading a world with an older DataVersion prints a single startup WARN. |
| Structures & Portals | ServerLevel#findNearestMapStructure returns @Nullable BlockPos (null), EndPortalBlock / NetherPortalBlock#getPortalDestination return @Nullable TeleportTransition (null), and FlatLevelGeneratorSettings returns Optional.empty() and List.of(). |
| Lazy Block Caches | BlockBehaviour.BlockStateBase initializes Shapes.empty() / EMPTY_OCCLUSION_SHAPES, and all 15 public and Moonrise getters call thread-safe ensureCacheInitialized() with reentrancy protection via cacheInitializing. |
| Spark & KeyPair | Every method in SparksFly guards with if (this.spark == null) return;. When network.generate-keypair: false, MinecraftServer#getKeyPair() generates keys lazily on first actual access. |
| Leak & State Reset Protection | block-events: false clears the blockEvents queue (blockEvents.clear()); fluid-interaction: false resets wasEyeInWater = false; statistics: false with hunger: true preserves causeFoodExhaustion. |