Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
refactor: Minecraft 1.19
Browse files Browse the repository at this point in the history
seems to work fine with Styled Chat
  • Loading branch information
Giggitybyte committed Jun 20, 2022
1 parent d50969b commit 7ba050d
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 54 deletions.
8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.6.0'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.7.2'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -28,10 +28,6 @@ tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}

java {
withSourcesJar()
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3
minecraft_version=1.19
yarn_mappings=1.19+build.4
loader_version=0.14.8

mod_version=1.2.1
mod_version=1.3.0
maven_group=me.thegiggitybyte
archives_base_name=chathistory
4 changes: 3 additions & 1 deletion src/main/java/me/thegiggitybyte/chathistory/ChatHistory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.thegiggitybyte.chathistory;

import com.google.common.collect.EvictingQueue;
import me.thegiggitybyte.chathistory.message.Message;
import me.thegiggitybyte.chathistory.message.PlayerMessage;
import net.darktree.simpleconfig.SimpleConfig;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.api.EnvType;
Expand All @@ -10,7 +12,7 @@

@Environment(EnvType.SERVER)
public class ChatHistory implements DedicatedServerModInitializer {
public static Queue<ChatMessage> MESSAGE_CACHE;
public static Queue<Message> MESSAGE_CACHE;

@Override
public void onInitializeServer() {
Expand Down
30 changes: 0 additions & 30 deletions src/main/java/me/thegiggitybyte/chathistory/ChatMessage.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.thegiggitybyte.chathistory.message;

import net.minecraft.network.message.MessageType;
import net.minecraft.text.Text;
import net.minecraft.util.registry.RegistryKey;

public class GameMessage extends Message {
private final Text message;

public GameMessage(Text message, RegistryKey<MessageType> typeKey) {
super(typeKey);

this.message = message;
}

public Text getTextMessage() {
return message;
}
}
16 changes: 16 additions & 0 deletions src/main/java/me/thegiggitybyte/chathistory/message/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.thegiggitybyte.chathistory.message;

import net.minecraft.network.message.MessageType;
import net.minecraft.util.registry.RegistryKey;

public abstract class Message {
private final RegistryKey<MessageType> typeKey;

protected Message(RegistryKey<MessageType> typeKey) {
this.typeKey = typeKey;
}

public RegistryKey<MessageType> getTypeKey() {
return typeKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.thegiggitybyte.chathistory.message;

import net.minecraft.network.message.MessageSender;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.util.registry.RegistryKey;

public class PlayerMessage extends Message {
private final SignedMessage message;
private final MessageSender sender;

public PlayerMessage(SignedMessage message, MessageSender sender, RegistryKey<MessageType> typeKey) {
super(typeKey);

this.message = message;
this.sender = sender;
}

public SignedMessage getSignedMessage() {
return message;
}

public MessageSender getSender() {
return sender;
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
package me.thegiggitybyte.chathistory.mixin;

import me.thegiggitybyte.chathistory.ChatHistory;
import me.thegiggitybyte.chathistory.ChatMessage;
import me.thegiggitybyte.chathistory.message.GameMessage;
import me.thegiggitybyte.chathistory.message.PlayerMessage;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.MessageType;
import net.minecraft.network.message.MessageSender;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SignedMessage;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.registry.RegistryKey;
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;

import java.util.UUID;
import java.util.function.Function;

@Mixin(PlayerManager.class)
public class PlayerManagerMixin {

@Inject(method = "broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V", at = @At("HEAD"))
public void cacheMessage(Text content, Function<ServerPlayerEntity, Text> messageFactory, MessageType type, UUID sender, CallbackInfo ci) {
ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender));
@Inject(method = "broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/util/registry/RegistryKey;)V", at = @At("HEAD"))
public void cacheGameMessage(Text message, Function<ServerPlayerEntity, Text> playerMessageFactory, RegistryKey<MessageType> typeKey, CallbackInfo ci) {
ChatHistory.MESSAGE_CACHE.add(new GameMessage(message, typeKey));
}
@Inject(method = "broadcast(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V", at = @At("HEAD"))
public void cacheMessage(Text content, MessageType type, UUID sender, CallbackInfo ci) {
ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender));

@Inject(method = "broadcast(Lnet/minecraft/network/message/SignedMessage;Ljava/util/function/Function;Lnet/minecraft/network/message/MessageSender;Lnet/minecraft/util/registry/RegistryKey;)V", at = @At("HEAD"))
public void cachePlayerMessage(SignedMessage message, Function<ServerPlayerEntity, SignedMessage> playerMessageFactory, MessageSender sender, RegistryKey<MessageType> typeKey, CallbackInfo ci) {
ChatHistory.MESSAGE_CACHE.add(new PlayerMessage(message, sender, typeKey));
}

@Inject(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;onSpawn()V"))
public void sendCachedMessages(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
for (var message : ChatHistory.MESSAGE_CACHE) {
player.sendMessage(message.getContent(), message.getType(), message.getSender());
if (message instanceof PlayerMessage playerMessage) {
player.sendChatMessage(playerMessage.getSignedMessage(), playerMessage.getSender(), playerMessage.getTypeKey());
} else if (message instanceof GameMessage gameMessage) {
player.sendMessage(gameMessage.getTextMessage(), gameMessage.getTypeKey());
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
],
"depends": {
"fabricloader": ">=0.9.3+build.207",
"minecraft": "1.18.x"
"minecraft": ">=1.19"
}
}

0 comments on commit 7ba050d

Please sign in to comment.