summaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/ultranotifier/mixin/ChatHudMessageAdded.java
blob: a9323d79fd70128b407d4eb58ab3b52998cc7c17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package moe.nea.ultranotifier.mixin;

import moe.nea.ultranotifier.ChatLineAddedEvent;
import moe.nea.ultranotifier.UltraNotifierEvents;
import net.minecraft.client.gui.hud.ChatHud;
//#if MC > 11404
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.network.message.MessageSignatureData;
//#endif
import net.minecraft.text.Text;
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(
		ChatHud.class
)
public class ChatHudMessageAdded {
	@Inject(
//#if MC <= 11404
//#if FORGE
//$$			method = "printChatMessageWithOptionalDeletion",
//#else
//$$			method = "addMessage(Lnet/minecraft/text/Text;I)V",
//#endif
//#else
			method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V",
//#endif
			at = @At("HEAD"), cancellable = true)
	private void onAddMessage(
			Text message,
//#if MC <= 11404
//$$			int chatLineId,
//#else
			MessageSignatureData signatureData, MessageIndicator indicator,
//#endif
			CallbackInfo ci
	) {
		if (UltraNotifierEvents.post(new ChatLineAddedEvent()).isCancelled()) {
			ci.cancel();
		}
	}

}