-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some bugs, improve mod compatibility
- Loading branch information
Showing
11 changed files
with
123 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
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
18 changes: 15 additions & 3 deletions
18
src/main/java/eu/pb4/styledchat/mixin/MessageTypeMixin.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 |
---|---|---|
@@ -1,16 +1,28 @@ | ||
package eu.pb4.styledchat.mixin; | ||
|
||
import eu.pb4.styledchat.StyledChatMod; | ||
import net.minecraft.network.message.MessageType; | ||
import net.minecraft.text.Decoration; | ||
import net.minecraft.util.registry.BuiltinRegistries; | ||
import net.minecraft.util.registry.Registry; | ||
import net.minecraft.util.registry.RegistryEntry; | ||
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.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(MessageType.class) | ||
public class MessageTypeMixin { | ||
@ModifyArg(method = "initialize", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/message/MessageType;<init>(Ljava/util/Optional;Ljava/util/Optional;Ljava/util/Optional;)V"), index = 0) | ||
private static Optional styledChat_replace(Optional<MessageType.DisplayRule> optional) { | ||
return optional.isPresent() && optional.get().decoration().isPresent() ? Optional.of(MessageType.DisplayRule.of()) : optional; | ||
@Inject(method = "initialize", at = @At("TAIL")) | ||
private static void styledChat_replace(Registry<MessageType> registry, CallbackInfoReturnable<RegistryEntry<MessageType>> cir) { | ||
|
||
BuiltinRegistries.add(registry, StyledChatMod.MESSAGE_TYPE, | ||
new MessageType(Optional.of(new MessageType.DisplayRule(Optional.of(Decoration.ofChat("%s")))), | ||
Optional.empty(), | ||
Optional.of(MessageType.NarrationRule.of(Decoration.ofChat("%s"), MessageType.NarrationRule.Kind.CHAT))) | ||
); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/eu/pb4/styledchat/mixin/ServerMessageEventsMixin.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,45 @@ | ||
package eu.pb4.styledchat.mixin; | ||
|
||
import eu.pb4.placeholders.api.PlaceholderContext; | ||
import eu.pb4.styledchat.StyledChatUtils; | ||
import eu.pb4.styledchat.other.WrappedEvent; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ServerMessageEvents.class) | ||
public class ServerMessageEventsMixin { | ||
@Mutable | ||
@Shadow @Final public static Event<ServerMessageEvents.AllowChatMessage> ALLOW_CHAT_MESSAGE; | ||
|
||
@Mutable | ||
@Shadow @Final public static Event<ServerMessageEvents.AllowCommandMessage> ALLOW_COMMAND_MESSAGE; | ||
|
||
@Mutable | ||
@Shadow @Final public static Event<ServerMessageEvents.ChatMessage> CHAT_MESSAGE; | ||
|
||
@Mutable | ||
@Shadow @Final public static Event<ServerMessageEvents.CommandMessage> COMMAND_MESSAGE; | ||
|
||
@Inject(method = "<clinit>", at = @At("TAIL")) | ||
private static void styledChat_replaceEvents(CallbackInfo ci) { | ||
ALLOW_CHAT_MESSAGE = new WrappedEvent<>(ALLOW_CHAT_MESSAGE, | ||
e -> (message, sender, typeKey) -> e.invoker().allowChatMessage(StyledChatUtils.toEventMessage(message, PlaceholderContext.of(sender)), sender, typeKey)); | ||
|
||
ALLOW_COMMAND_MESSAGE = new WrappedEvent<>(ALLOW_COMMAND_MESSAGE, | ||
e -> (message, sender, typeKey) -> e.invoker().allowCommandMessage(StyledChatUtils.toEventMessage(message, PlaceholderContext.of(sender)), sender, typeKey)); | ||
|
||
CHAT_MESSAGE = new WrappedEvent<>(CHAT_MESSAGE, | ||
e -> (message, sender, typeKey) -> e.invoker().onChatMessage(StyledChatUtils.toEventMessage(message, PlaceholderContext.of(sender)), sender, typeKey)); | ||
|
||
COMMAND_MESSAGE = new WrappedEvent<>(COMMAND_MESSAGE, | ||
e -> (message, sender, typeKey) -> e.invoker().onCommandMessage(StyledChatUtils.toEventMessage(message, PlaceholderContext.of(sender)), sender, typeKey)); | ||
|
||
} | ||
} |
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,19 @@ | ||
package eu.pb4.styledchat.other; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
|
||
import java.util.function.Function; | ||
|
||
public final class WrappedEvent<T> extends Event<T> { | ||
public final Event<T> event; | ||
|
||
public WrappedEvent(Event<T> event, Function<Event<T>, T> argModifier) { | ||
this.event = event; | ||
this.invoker = argModifier.apply(event); | ||
} | ||
|
||
@Override | ||
public void register(T listener) { | ||
this.event.register(listener); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
], | ||
|
||
"depends": { | ||
"minecraft": ">=1.18-rc.1" | ||
"minecraft": "1.19" | ||
}, | ||
"custom": { | ||
"modmenu": { | ||
|
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