Skip to content
These docs are a work in progress and may be incomplete or contain inaccuracies. (Or be for a newer unreleased version of the mod)

Matthiesen Core - Platform Events

Matthiesen Core provides a robust event system that allows mod developers to hook into various platform events. This enables mods to respond to specific actions or changes within the game environment, enhancing interactivity and functionality.

Matthiesen Core defines several server-side events that mods can listen to. These events are crucial for managing server behavior and responding to changes in the game state.

ExampleModServerEvents.java
package com.example.mymod;
import dev.matthiesen.matthiesen_core.common.api.events.PlatformEvents;
import dev.matthiesen.matthiesen_core.common.api.events.EventObservable;
import dev.matthiesen.matthiesen_core.common.api.events.server.ServerEvent;
import net.minecraft.server.MinecraftServer;
public class ExampleModServerEvents {
private static volatile EventObservable<ServerEvent.Started> serverStartedObservable;
private static volatile EventObservable<ServerEvent.Stopping> serverStoppingObservable;
public static void registerEvents() {
serverStartedObservable = PlatformEvents.SERVER_STARTED.subscribe((MinecraftServer server) -> {
// Logic to execute when the server is starting
});
serverStoppingObservable = PlatformEvents.SERVER_STOPPING.subscribe((MinecraftServer server) -> {
// Logic to execute when the server is starting
});
}
public static void teardownEvents() {
if (serverStartedObservable != null) {
serverStartedObservable.unsubscribe(ExampleModServerEvents::onServerStarted);
serverStartedObservable = null;
}
if (serverStoppingObservable != null) {
serverStoppingObservable.unsubscribe(ExampleModServerEvents::onServerStopping);
serverStoppingObservable = null;
}
}
}

Events that occur during the server’s lifecycle, allowing mods to respond to server state changes.

Triggered when the server is starting up, before it has fully initialized.

ServerStartingEvent.java
PlatformEvents.SERVER_STARTING.subscribe((MinecraftServer server) -> {
// Logic to execute when the server is starting
});

Triggered when the server has fully started and is ready to accept connections.

ServerStartedEvent.java
PlatformEvents.SERVER_STARTED.subscribe((MinecraftServer server) -> {
// Logic to execute when the server has started
});

Triggered when the server is in the process of stopping, allowing for cleanup or saving state.

ServerStoppingEvent.java
PlatformEvents.SERVER_STOPPING.subscribe((MinecraftServer server) -> {
// Logic to execute when the server is stopping
});

Triggered when the server has fully stopped, allowing for final cleanup or resource deallocation.

ServerStoppedEvent.java
PlatformEvents.SERVER_STOPPED.subscribe((MinecraftServer server) -> {
// Logic to execute when the server has stopped
});

Triggered when the server is reloading its configuration or resources, allowing for dynamic updates without a full restart.

ServerReloadEvent.java
PlatformEvents.SERVER_RELOAD.subscribe(() -> {
// Logic to execute when the server is reloading
});

Events that occur on each server tick, allowing for periodic updates or checks.

Triggered at the start of each server tick, allowing for periodic updates or checks.

ServerStartTickEvent.java
PlatformEvents.SERVER_START_TICK.subscribe((MinecraftServer server) -> {
// Logic to execute at the start of each server tick
});

Triggered at the end of each server tick, allowing for periodic updates or checks.

ServerEndTickEvent.java
PlatformEvents.SERVER_END_TICK.subscribe((MinecraftServer server) -> {
// Logic to execute at the end of each server tick
});

Events related to player connections, allowing for custom behavior when players join or leave the server.

Triggered when a player joins the server, allowing for welcome messages or initialization logic.

PlayerJoinEvent.java
PlatformEvents.PLAYER_JOIN.subscribe((ServerPlayer player) -> {
// Logic to execute when a player joins the server
});

Triggered when a player leaves the server, allowing for cleanup or saving player state.

PlayerLeaveEvent.java
PlatformEvents.PLAYER_LEAVE.subscribe((ServerPlayer player) -> {
// Logic to execute when a player leaves the server
});

Events related to player interactions with items and blocks, allowing for custom behavior or effects.

Triggered when a player uses an item, allowing for custom behavior or effects.

PlayerUseItemEvent.java
import net.minecraft.world.InteractionResult;
PlatformEvents.PLAYER_USE_ITEM.subscribe((ServerPlayer player, Level level, InteractionHand hand) -> {
return InteractionResult.PASS; // Logic to execute when a player uses an item
});

Triggered when a player interacts with a block, allowing for custom behavior or effects.

PlayerUseBlockEvent.java
import net.minecraft.world.InteractionResult;
PlatformEvents.PLAYER_USE_BLOCK.subscribe((ServerPlayer player, Level level, InteractionHand hand, BlockPos pos) -> {
return InteractionResult.PASS; // Logic to execute when a player interacts with a block
});

Events that occur on the client side, allowing for custom behavior or effects in response to client actions.

Similar to server events, client events can be subscribed to in order to execute logic when certain client-side actions occur. These events are part of the PlatformClientEvents class.

Example Import for Client Events Class
import dev.matthiesen.matthiesen_core.common.api.events.PlatformClientEvents;

Triggered when the client is stopping, allowing for cleanup or saving state.

ClientStoppingEvent.java
PlatformClientEvents.CLIENT_STOPPING.subscribe(() -> {
// Logic to execute when the client is stopping
});

Triggered at the end of each client tick, allowing for periodic updates or checks.

ClientEndTickEvent.java
PlatformClientEvents.CLIENT_END_TICK.subscribe(() -> {
// Logic to execute at the end of each client tick
});

Triggered when the HUD is being registered, allowing for custom HUD elements to be added.

HudRegistrationEvent.java
import dev.matthiesen.matthiesen_core.common.api.client.hud.HudRegistrar;
PlatformClientEvents.HUD_REGISTRATION.subscribe((HudRegistrar registrar) -> {
// Logic to execute when the HUD is being registered
});

There is two dedicated methods for registering HUD elements, which are:

Registering HUD Elements
import dev.matthiesen.matthiesen_core.common.api.PlatformClientEvents;
/**
* Registers a HUD layer above all others.
*/
PlatformClientEvents.registerHudLayer(ResourceLocation key, LayerDraw.layer layer);
/**
* Registers a HUD layer with explicit ordering metadata.
*/
PlatformClientEvents.registerHudLayer(HudOrdering ordering, ResourceLocation other,
ResourceLocation key, LayeredDraw.Layer layer);

Triggered when a block is highlighted, allowing for custom behavior or effects.

BlockHighlightEvent.java
import dev.matthiesen.matthiesen_core.common.api.client.BlockOutlineContext;
import net.minecraft.world.InteractionResult;
PlatformClientEvents.BLOCK_HIGHLIGHT.subscribe((BlockOutlineContext context) -> {
// Logic to execute when a block is highlighted
return InteractionResult.PASS; // Return the appropriate InteractionResult based on your logic
});

Triggered when resource packs are being registered, allowing for custom resource packs to be added.

ResourcePackRegistrationEvent.java
import dev.matthiesen.matthiesen_core.common.api.client.ResourcePackRegistrar;
PlatformClientEvents.RESOURCE_PACK_REGISTRATION.subscribe((ResourcePackRegistrar registrar) -> {
// Logic to execute when resource packs are being registered
});

There is three dedicated methods for registering resource packs, which are:

Registering Resource Packs
import dev.matthiesen.matthiesen_core.common.api.PlatformClientEvents;
import dev.matthiesen.matthiesen_core.common.api.platform.registry.ResourcePackDef;
import dev.matthiesen.matthiesen_core.common.api.platform.registry.ResourcePackActivationBehaviour;
import net.minecraft.network.chat.Component;
PlatformClientEvents.registerResourcePack(ResourcePackDef resourcePackDef);
PlatformClientEvents.registerResourcePack(String modId, String id, String displayName,
ResourcePackActivationBehaviour activationBehaviour);
PlatformClientEvents.registerResourcePack(String modId, String id, Component displayName,
ResourcePackActivationBehaviour activationBehaviour);