Skip to main content

Java API

Midnight Thoughts fires five events. Other mods can listen to them to react to sleep, or to change how comfortable a place is considered before the mod acts on it.

Who this page is for

Java mod developers. If you just want to script behaviour without writing a mod, use KubeJS — it exposes the same five events.

All events live in the mt.api.event package.

note

On Forge and NeoForge these are event bus classes, named ...Event. On Fabric the same five hooks are Fabric API callbacks, named ...Callback, each with a static EVENT field. The data they carry is identical; only the way you subscribe differs.


Events

EventFires whenCancellable
WellRestedAppliedEventThe Rested effect is granted
WellRestedExpiredEventThe Rested effect is removed
NightmareEventA player falls asleep in nightmare conditions
MvpDeterminedEventThe night's MVP is chosen
ComfortCalculatedEventComfort is calculated for a playermutable result
public class WellRestedAppliedEvent extends Event {
public ServerPlayer getPlayer();
public int getLevel(); // 1..5
public boolean isMvp();
public int getDurationTicks();
}

Fired after waking up, from the wellrested grant command, and from the KubeJS binding.


Listening

@EventBusSubscriber
public class SleepHooks {
@SubscribeEvent
public static void onRested(WellRestedAppliedEvent event) {
LOGGER.info("{} woke up rested at level {}",
event.getPlayer().getName().getString(), event.getLevel());
}
}
note

Every event is fired on the server side only. There is no client-side counterpart — the client is told the result over the network, not through events.


Overriding comfort

ComfortCalculatedEvent is the extension point worth knowing about. The mod reads the level back out of the event after posting it, so whatever a listener leaves there becomes the real comfort level — driving the Rested level, nightmares, and the sleep block.

@SubscribeEvent
public static void onComfort(ComfortCalculatedEvent event) {
ServerPlayer player = event.getPlayer();
if (player.level().dimension() == Level.NETHER) {
event.setLevel(-5);
}
}
tip

This lets another mod add its own comfort sources — a "cosy campfire" block, a biome modifier, a magic ward — without touching the tag system at all. Read the current value, adjust it, write it back.

warning

Results are cached per player and position for a short window, so the event does not fire on every tick. Do not rely on it as a polling mechanism — treat it as "the mod is about to make a decision, last chance to influence it".


Data pack alternative

If all you want is to add blocks that make a bedroom cosier, you do not need Java at all — the comfort system is driven by block tags, and a data pack can extend them in a few lines of JSON.