Skip to content

Commit

Permalink
feat: Add ClientJoinWorldCallback event
Browse files Browse the repository at this point in the history
This event gets fired whenever the client joins a new world (can be
internal, or external). This will soon be used for a new feature which
will allow you to clear the message counters when you join a new world.
  • Loading branch information
caoimhebyrne committed Jun 5, 2022
1 parent 19dbd8e commit 17586d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.cbyrne.compactchat.event;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

/**
* Fired whenever the client 'joins' a new world. This can be either an internal (single-player) or external (multiplayer) world.
* @see net.minecraft.client.MinecraftClient#joinWorld(net.minecraft.client.world.ClientWorld)
*/
public interface ClientJoinWorldCallback {
Event<ClientJoinWorldCallback> EVENT = EventFactory.createArrayBacked(ClientJoinWorldCallback.class,
(listeners -> () -> {
for (var listener : listeners) {
listener.onJoin();
}
})
);

void onJoin();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.cbyrne.compactchat.mixin;

import dev.cbyrne.compactchat.event.ClientJoinWorldCallback;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Inject(at = @At("HEAD"), method = "joinWorld")
private void compactChat$joinWorldHandler(CallbackInfo ci) {
ClientJoinWorldCallback.EVENT.invoker().onJoin();
}
}
3 changes: 2 additions & 1 deletion src/main/resources/CompactChat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
],
"client": [
"ChatHudMixin",
"KeyboardMixin"
"KeyboardMixin",
"MinecraftClientMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 17586d5

Please sign in to comment.