-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ClientJoinWorldCallback event
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
1 parent
19dbd8e
commit 17586d5
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/dev/cbyrne/compactchat/event/ClientJoinWorldCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/dev/cbyrne/compactchat/mixin/MinecraftClientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters