KubeJS Sanity: Scriptable Sanity Control for Minecraft

Expanding Minecraft Sanity Systems with KubeJS Integration Minecraft modding constantly pushes the boundaries of what is possible within the blocky world, and few systems are as immersive as sanity mechanics. Inspired by games that track mental stability, mods like Sanity introduce a whole new la...

Download SanityJS for Minecraft 1.20.1, 1.19.2

Original name: SanityJS

Minecraft: 1.19.2, 1.20.1

Loaders: Forge, NeoForge

FileVersionLoaderSize
SanityJS-1.1.3.jar1.19.2Forge330 КБDownload
SanityJS-1.2.0-1.19.2.jar1.19.2Forge392 КБDownload
SanityJS-1.1.0.jar1.20.1Forge204 КБDownload
SanityJS-1.1.1.jar1.20.1Forge204 КБDownload
SanityJS-1.2.0.jar1.20.1Forge266 КБDownload
SanityJS-1.0.1.jar1.20.1NeoForge200 КБDownload
SanityJS-1.1.2.jar1.20.1NeoForge204 КБDownload

Expanding Minecraft Sanity Systems with KubeJS Integration

Minecraft modding constantly pushes the boundaries of what is possible within the blocky world, and few systems are as immersive as sanity mechanics. Inspired by games that track mental stability, mods like Sanity introduce a whole new layer of survival. But what if you want to tweak those rules, create custom reactions, or completely overhaul how sanity behaves? That is where KubeJS Sanity steps in, bridging the gap between complex mod internals and the accessible scripting power of KubeJS.

This integration is not just a simple wrapper. It opens up the Sanity mod’s core functionality to script-based manipulation, allowing server administrators and pack developers to craft truly unique experiences. Instead of being limited to configuration files, you can now use JavaScript to react to sanity changes in real time, apply custom potion effects, cancel rendering, and even create your own sanity sources.

How KubeJS Sanity Puts You in Control

The primary appeal of this mod lies in its event-driven architecture. By listening to sanity events, you can intercept every fluctuation and inject your own logic. Imagine a scenario where a player’s sanity drops below a certain threshold: you might not just apply nausea, but also trigger a custom advancement, spawn a phantom creature, or alter the world’s ambient sounds. All of this becomes possible with a few lines of KubeJS script.

For those who prefer a more streamlined modding setup, getting started with these scripts is remarkably easy. The mod can be easily installed via the foxygame.net launcher, a convenient and modern Minecraft launcher where you can download mods directly from the menu, ensuring that dependencies like KubeJS and Sanity are handled without hassle.

Core Features and Scripting Capabilities

The mod provides a robust set of methods and events, neatly divided into categories that make sense for any developer. Here is what you can immediately leverage in your scripts:

Sanity Change Events

The heart of the integration is the SanityEvents.change event. It fires whenever a player’s sanity value is about to be modified. Inside the callback, you can access both the old and new sanity levels, and then decide what happens next.

  • event.getSanity() – Retrieves the new sanity value after the change.
  • event.getPreviousSanity() – Returns the sanity value before the modification occurred.
  • event.getEntity() – Gets the player entity, allowing you to apply potion effects, send messages, or run any other player-specific logic.

A common use case is applying debuffs when sanity drops critically low. For example, you might add a mining fatigue effect or temporarily disable natural regeneration. The flexibility to cancel or modify the change itself gives you total authority over the sanity system.

Another powerful event is SanityEvents.indicatorRender. By calling event.cancel(), you can completely hide the default sanity indicator and replace it with your own custom HUD element. This is perfect for modpacks that want a unique visual identity or need to integrate sanity into a larger custom UI.

Direct Sanity Manipulation Methods

Beyond reacting to changes, you often need to set or adjust sanity values directly. KubeJS Sanity offers a clean set of methods for this purpose:

  • setSanity(value) – Instantly sets the player’s sanity to a specific number between 0 and 100.
  • addSanity(value) – Increases (or decreases, with a negative value) the current sanity by a specified amount.
  • player.getSanity() – A convenient way to fetch the current sanity directly from a player object.

These methods are invaluable for creating custom items, block interactions, or dimension-specific sanity rules. For instance, you could script a special totem that restores sanity when held, or make standing near certain blocks gradually drain mental stability.

Utility Functions for Precision

Working with sanity values often requires normalization or precise rounding. The integration includes three utility functions that simplify mathematical operations:

  • clampNorm(value) – Normalizes a number to a value between 0 and 1, useful for scaling effects.
  • unclampNorm(normalizedValue) – Converts a normalized value back to its original range.
  • approximation(value, n) – Truncates a number to n significant decimal places, ensuring accurate calculations when dealing with floating-point sanity values.

These tools help you create smooth, gradual effects that scale precisely with the player’s mental state, avoiding sudden jumps that might break immersion.

Areas for Improvement and Future Potential

While the current feature set is already impressive, the developer has outlined clear paths for expansion. The most requested addition is more events to fully control the tickPlayer method, which governs how sanity updates over time. This would allow scripters to override the default passive drain or regeneration entirely.

Additional rendering events are also on the horizon, giving modpack creators finer control over visual effects like screen distortion, color shifts, or custom overlays. Another exciting possibility is the introduction of passive sanity sources that could be hot-reloaded, enabling dynamic changes without a full game restart.

Looking further ahead, the ability to modify visible rules based on a player’s sanity could lead to truly adaptive gameplay. Imagine a world where the recipe book, tooltips, or even the in-game map change depending on how stable your character feels. Such enhancements would cement KubeJS Sanity as an essential tool for narrative-driven modpacks.

Getting Started and Community Support

Setting up the integration is straightforward. You need the Sanity mod, KubeJS, and the KubeJS Sanity bridge. Once installed, you can place your scripts in the kubejs/server_scripts folder and immediately start experimenting. The event-driven nature means you can test changes quickly, reloading scripts without restarting the entire server.

For any questions or troubleshooting, the mod’s Discord server is the best place to connect with other developers and the creator. The community is active and often shares script snippets that demonstrate creative uses of the sanity system.

Why KubeJS Sanity Matters for Modpack Creators

Minecraft modding thrives on customization, and sanity mechanics are one of the most expressive systems to play with. KubeJS Sanity removes the technical barriers that previously kept many creators from diving into this area. Instead of learning Java and compiling a separate mod, you can now use familiar JavaScript to weave complex sanity interactions into your pack.

Whether you are designing a horror-themed adventure, a psychological survival challenge, or simply want to add a new layer of consequence to player actions, this integration provides the building blocks. The combination of precise control, easy scripting, and future-proof expandability makes it a standout addition to any modded environment. As the mod continues to evolve, the line between what is a script and what is a full-fledged mod will blur even further, empowering a new wave of creative storytelling in Minecraft.