From 67454fa7e3df7e84f67ce8f6ea51ad82eba9d900 Mon Sep 17 00:00:00 2001 From: Drex Date: Wed, 24 Jan 2024 20:27:01 +0100 Subject: [PATCH 1/3] Update to 24w04a --- build.gradle | 3 ++- gradle.properties | 10 +++++----- .../java/eu/pb4/styledchat/StyledChatStyles.java | 13 ++++++++++--- .../java/eu/pb4/styledchat/StyledChatUtils.java | 5 ++++- .../pb4/styledchat/mixin/RegistryLoaderMixin.java | 13 ++++++------- .../mixin/commands/MessageCommandMixin.java | 10 +++++----- .../mixin/commands/TeamMsgCommandMixin.java | 12 ++++++------ .../pb4/styledchat/other/StyledChatSentMessage.java | 10 +++++----- src/main/resources/fabric.mod.json | 2 +- src/main/resources/styledchat.accesswidener | 3 +++ 10 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 src/main/resources/styledchat.accesswidener diff --git a/build.gradle b/build.gradle index 0472b45..ff6c634 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.4.+' + id 'fabric-loom' version '1.5.+' id 'maven-publish' id "com.modrinth.minotaur" version "2.+" id 'com.matthewprenger.cursegradle' version '1.4.0' @@ -59,6 +59,7 @@ loom { interfaceInjection { enableDependencyInterfaceInjection = false } + accessWidenerPath = file("src/main/resources/styledchat.accesswidener") } processResources { diff --git a/gradle.properties b/gradle.properties index dd3a7ec..b87d688 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.20.3-rc1 -yarn_mappings=1.20.3-rc1+build.1 -loader_version=0.15.0 +minecraft_version=24w04a +yarn_mappings=24w04a+build.1 +loader_version=0.15.6 #Fabric api -fabric_version=0.91.1+1.20.3 +fabric_version=0.95.1+1.20.5 # Mod Properties - mod_version = 2.4.0+1.20.3 + mod_version = 2.4.0+1.20.5 maven_group = eu.pb4 archives_base_name = styled-chat diff --git a/src/main/java/eu/pb4/styledchat/StyledChatStyles.java b/src/main/java/eu/pb4/styledchat/StyledChatStyles.java index 26febd2..e875a50 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatStyles.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatStyles.java @@ -4,6 +4,7 @@ import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.styledchat.config.ConfigManager; import net.minecraft.entity.passive.TameableEntity; +import net.minecraft.network.message.MessageType; import net.minecraft.registry.RegistryKeys; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; @@ -178,7 +179,7 @@ public static Map getEmotes(ServerCommandSource source) { } - public static Text getCustom(Identifier identifier, Text displayName, Text message, @Nullable Text receiver, ServerCommandSource source) { + public static Text getCustom(Identifier identifier, Text displayName, Text message, Text receiver, ServerCommandSource source) { if (source.isExecutedByPlayer()) { var style = StyledChatUtils.getPersonalStyle(source.getPlayer()).getCustom(identifier, displayName, message, receiver, source); if (style != null) { @@ -192,18 +193,24 @@ public static Text getCustom(Identifier identifier, Text displayName, Text messa return out; } - var type = StyledChatMod.server.getRegistryManager().get(RegistryKeys.MESSAGE_TYPE).get(identifier); + var type = source.getRegistryManager().get(RegistryKeys.MESSAGE_TYPE).get(identifier); if (type == null) { return Text.empty(); } - var params = type.params(displayName); + var optional = source.getRegistryManager().get(RegistryKeys.MESSAGE_TYPE).getKey(type); + + if (optional.isEmpty()) { + return Text.empty(); + } + var params = MessageType.params(optional.get(), source.getRegistryManager(), displayName); if (receiver != null) { params = params.withTargetName(receiver); } + return type.chat().apply(message, params); } } diff --git a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java index e0d8122..b3582c3 100644 --- a/src/main/java/eu/pb4/styledchat/StyledChatUtils.java +++ b/src/main/java/eu/pb4/styledchat/StyledChatUtils.java @@ -27,8 +27,11 @@ import net.minecraft.network.message.MessageType; import net.minecraft.network.message.SignedMessage; import net.minecraft.network.packet.s2c.play.ChatSuggestionsS2CPacket; +import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.scoreboard.Team; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.*; @@ -471,6 +474,6 @@ public static ChatStyle createStyleOf(ServerPlayerEntity player) { } public static MessageType.Parameters createParameters(Text override) { - return new MessageType.Parameters(StyledChatMod.getMessageType(), override, null); + return MessageType.params(StyledChatMod.MESSAGE_TYPE_ID, StyledChatMod.server.getRegistryManager(), override); } } diff --git a/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java b/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java index db2948c..dfbfb9a 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java @@ -1,13 +1,12 @@ package eu.pb4.styledchat.mixin; -import com.mojang.datafixers.util.Pair; import eu.pb4.styledchat.StyledChatMod; import net.minecraft.network.message.MessageType; import net.minecraft.registry.*; -import net.minecraft.resource.ResourceManager; import net.minecraft.text.Decoration; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Coerce; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @@ -17,12 +16,12 @@ @Mixin(RegistryLoader.class) public class RegistryLoaderMixin { - @Inject(method = "load(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;", at = @At(value = "INVOKE", target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V", ordinal = 0, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private static void styledChat$injectMessageTypes(ResourceManager resourceManager, DynamicRegistryManager baseRegistryManager, List> entries, - CallbackInfoReturnable cir, Map _unused, List, Object>> list) { + @Inject(method = "load(Lnet/minecraft/registry/RegistryLoader$RegistryLoadable;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;", at = @At(value = "INVOKE", target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V", ordinal = 0, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION) + private static void styledChat$injectMessageTypes(@Coerce Object registryLoadable, DynamicRegistryManager baseRegistryManager, List> entries, CallbackInfoReturnable cir, Map map, + List> list, RegistryOps.RegistryInfoGetter registryInfoGetter) { - for (var pair : list) { - var reg = pair.getFirst(); + for (var entry : list) { + var reg = entry.registry(); if (reg.getKey().equals(RegistryKeys.MESSAGE_TYPE)) { Registry.register((Registry) reg, StyledChatMod.MESSAGE_TYPE_ID, new MessageType(Decoration.ofChat("%s"), Decoration.ofChat("%s"))); } diff --git a/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java index 5913b82..7b35d46 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/MessageCommandMixin.java @@ -38,7 +38,7 @@ private static void styledChat_noopFeedback(ServerCommandSource instance, SentMe private static void styledChat_formatText(ServerPlayerEntity instance, SentMessage message, boolean bl, MessageType.Parameters parameters, ServerCommandSource source) { if (message instanceof ExtendedSentMessage extSentMessage) { try { - var sent = StyledChatMod.getMessageType().params(StyledChatStyles.getPrivateMessageSent( + var sent = MessageType.params(StyledChatMod.MESSAGE_TYPE_ID, source.getServer().getRegistryManager(), StyledChatStyles.getPrivateMessageSent( source.getDisplayName(), instance.getDisplayName(), ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), instance.getCommandSource() @@ -47,10 +47,10 @@ private static void styledChat_formatText(ServerPlayerEntity instance, SentMessa source.sendChatMessage(message, bl, sent); - var rex = StyledChatMod.getMessageType().params(StyledChatStyles.getPrivateMessageReceived( - source.getDisplayName(), - instance.getDisplayName(), - ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), source + var rex = MessageType.params(StyledChatMod.MESSAGE_TYPE_ID, source.getServer().getRegistryManager(), StyledChatStyles.getPrivateMessageReceived( + source.getDisplayName(), + instance.getDisplayName(), + ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), source )); instance.sendChatMessage(message, bl, rex); diff --git a/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java b/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java index bcda3c8..eaf25c1 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/commands/TeamMsgCommandMixin.java @@ -38,16 +38,16 @@ private static void styledChat_replaceForSelf(ServerPlayerEntity instance, SentM if (message instanceof ExtendedSentMessage extSentMessage) { try { if (source.getPlayer() == instance) { - var sent = StyledChatMod.getMessageType().params(StyledChatStyles.getTeamChatSent( - ((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), - source.getDisplayName(), - ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), instance.getCommandSource() + var sent = MessageType.params(StyledChatMod.MESSAGE_TYPE_ID, source.getServer().getRegistryManager(), StyledChatStyles.getTeamChatSent( + source.getEntity().getScoreboardTeam().getFormattedName(), + source.getDisplayName(), + ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), instance.getCommandSource() )); source.sendChatMessage(message, bl, sent); } else { - var rex = StyledChatMod.getMessageType().params(StyledChatStyles.getTeamChatReceived( - ((Team) source.getEntity().getScoreboardTeam()).getFormattedName(), + var rex = MessageType.params(StyledChatMod.MESSAGE_TYPE_ID, source.getServer().getRegistryManager(), StyledChatStyles.getTeamChatReceived( + source.getEntity().getScoreboardTeam().getFormattedName(), source.getDisplayName(), ExtSignedMessage.getArg(extSentMessage.styledChat$message(), "base_input"), source )); diff --git a/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java b/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java index 8c95e49..b066535 100644 --- a/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java +++ b/src/main/java/eu/pb4/styledchat/other/StyledChatSentMessage.java @@ -44,7 +44,7 @@ public void send(ServerPlayerEntity receiver, boolean filterMaskEnabled, Message colorless.setValue(StyledChatUtils.removeColor(parameters)); } if (!signedMessage.isFullyFiltered()) { - var id = receiver.server.getRegistryManager().get(RegistryKeys.MESSAGE_TYPE).getId(params.type()); + var id = receiver.server.getRegistryManager().get(RegistryKeys.MESSAGE_TYPE).getId(params.type().value()); if (sourceType == null || Objects.equals(id, this.sourceType.getValue())) { receiver.networkHandler.sendChatMessage(signedMessage, color ? this.parameters : colorless.getValue()); @@ -56,13 +56,13 @@ public void send(ServerPlayerEntity receiver, boolean filterMaskEnabled, Message ? baseInput : signedMessage.getContent(); - var text = StyledChatStyles.getCustom(id, params.name(), input, params.targetName(), source != null ? source : StyledChatMod.server.getCommandSource()); + var text = StyledChatStyles.getCustom(id, params.name(), input, params.targetName().orElse(null), source != null ? source : StyledChatMod.server.getCommandSource()); if (!color) { text = StyledChatUtils.removeColor(text); } - receiver.networkHandler.sendChatMessage(signedMessage, StyledChatUtils.createParameters(text)); + receiver.networkHandler.sendChatMessage(signedMessage, MessageType.params(StyledChatMod.MESSAGE_TYPE_ID, receiver.server.getRegistryManager(), text)); } } } @@ -80,7 +80,7 @@ public Text content() { @Override public void send(ServerPlayerEntity receiver, boolean filterMaskEnabled, MessageType.Parameters params) { - var id = receiver.server.getRegistryManager().get(RegistryKeys.MESSAGE_TYPE).getId(params.type()); + var id = receiver.server.getRegistryManager().get(RegistryKeys.MESSAGE_TYPE).getId(params.type().value()); var color = ((ExtPlayNetworkHandler) receiver.networkHandler).styledChat$chatColors(); if (!color && colorless.getValue() == null) { colorless.setValue(StyledChatUtils.removeColor(parameters)); @@ -96,7 +96,7 @@ public void send(ServerPlayerEntity receiver, boolean filterMaskEnabled, Message ? baseInput : message.getContent(); - var text = StyledChatStyles.getCustom(id, params.name(), input, params.targetName(), source != null ? source : StyledChatMod.server.getCommandSource()); + var text = StyledChatStyles.getCustom(id, params.name(), input, params.targetName().orElse(null), source != null ? source : StyledChatMod.server.getCommandSource()); if (!color) { text = StyledChatUtils.removeColor(text); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ee4a686..fd43572 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,7 +12,7 @@ "homepage": "https://pb4.eu", "sources": "https://github.com/Patbox/StyledChat" }, - + "accessWidener": "styledchat.accesswidener", "license": "LGPLv3", "icon": "assets/icon.png", "environment": "*", diff --git a/src/main/resources/styledchat.accesswidener b/src/main/resources/styledchat.accesswidener new file mode 100644 index 0000000..b6ad4fa --- /dev/null +++ b/src/main/resources/styledchat.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named + +accessible class net/minecraft/registry/RegistryLoader$class_9158 \ No newline at end of file From 5f10e95312d221f448c926051d3de2955e7c0918 Mon Sep 17 00:00:00 2001 From: Drex Date: Sat, 20 Apr 2024 00:53:46 +0200 Subject: [PATCH 2/3] Update to 1.20.5-rc2 --- .github/workflows/build.yml | 4 ++-- .github/workflows/release.yml | 2 +- build.gradle | 16 ++++++++-------- gradle.properties | 15 +++++++-------- gradle/wrapper/gradle-wrapper.properties | 2 +- .../styledchat/mixin/RegistryLoaderMixin.java | 2 +- src/main/resources/styledchat.accesswidener | 2 +- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7478a9..2b4d272 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: matrix: # Use these Java versions java: [ - 17 # Minimum supported by Minecraft + 21 # Minimum supported by Minecraft ] # and run on both Linux and Windows os: [ubuntu-20.04, windows-latest] @@ -32,7 +32,7 @@ jobs: - name: build run: ./gradlew build - name: capture build artifacts - if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS + if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS uses: actions/upload-artifact@v2 with: name: Artifacts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae05f9d..b15acc4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/build.gradle b/build.gradle index ff6c634..94848cb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.5.+' + id 'fabric-loom' version '1.6.+' id 'maven-publish' id "com.modrinth.minotaur" version "2.+" id 'com.matthewprenger.cursegradle' version '1.4.0' @@ -7,8 +7,8 @@ plugins { var isStable = project.is_stable == "true" -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version @@ -41,12 +41,12 @@ dependencies { //modCompileOnly fabricApi.module("fabric-api-base", project.fabric_version) //modLocalRuntime fabricApi.module("fabric-api-base", project.fabric_version) - modImplementation include("eu.pb4:predicate-api:0.3.0+1.20.2") - modImplementation include("eu.pb4:placeholder-api:2.3.0+1.20.3") - modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT") + modImplementation include("eu.pb4:predicate-api:0.4.0+1.20.5") + modImplementation include("eu.pb4:placeholder-api:2.4.0-pre.1+1.20.5") + modImplementation include("me.lucko:fabric-permissions-api:0.3.1") modImplementation include("eu.pb4:player-data-api:0.4.0+1.20.3") - modCompileOnly("maven.modrinth:vanish:1.1.0") + modCompileOnly("maven.modrinth:vanish:1.5.2+1.20.4") //modLocalRuntime("fr.catcore:server-translations-api:1.4.17+1.19.2") //modRuntime "supercoder79:databreaker:0.2.7" @@ -78,7 +78,7 @@ tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" // Minecraft 1.17 (21w19a) upwards uses Java 16. - it.options.release = 17 + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index b87d688..81eea8a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,18 +3,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=24w04a -yarn_mappings=24w04a+build.1 -loader_version=0.15.6 +minecraft_version=1.20.5-rc2 +yarn_mappings=1.20.5-rc2+build.1 +loader_version=0.15.10 #Fabric api -fabric_version=0.95.1+1.20.5 +fabric_version=0.97.3+1.20.5 # Mod Properties - - mod_version = 2.4.0+1.20.5 - maven_group = eu.pb4 - archives_base_name = styled-chat +mod_version = 2.4.0+1.20.5 +maven_group = eu.pb4 +archives_base_name = styled-chat # Dependencies is_stable = true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586..48c0a02 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java b/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java index dfbfb9a..9d5fe14 100644 --- a/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java +++ b/src/main/java/eu/pb4/styledchat/mixin/RegistryLoaderMixin.java @@ -18,7 +18,7 @@ public class RegistryLoaderMixin { @Inject(method = "load(Lnet/minecraft/registry/RegistryLoader$RegistryLoadable;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;", at = @At(value = "INVOKE", target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V", ordinal = 0, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION) private static void styledChat$injectMessageTypes(@Coerce Object registryLoadable, DynamicRegistryManager baseRegistryManager, List> entries, CallbackInfoReturnable cir, Map map, - List> list, RegistryOps.RegistryInfoGetter registryInfoGetter) { + List> list, RegistryOps.RegistryInfoGetter registryInfoGetter) { for (var entry : list) { var reg = entry.registry(); diff --git a/src/main/resources/styledchat.accesswidener b/src/main/resources/styledchat.accesswidener index b6ad4fa..dd729c9 100644 --- a/src/main/resources/styledchat.accesswidener +++ b/src/main/resources/styledchat.accesswidener @@ -1,3 +1,3 @@ accessWidener v2 named -accessible class net/minecraft/registry/RegistryLoader$class_9158 \ No newline at end of file +accessible class net/minecraft/registry/RegistryLoader$Loader \ No newline at end of file From 201ee33279304d7377a033e4b8158c083a50c18e Mon Sep 17 00:00:00 2001 From: Drex Date: Sat, 20 Apr 2024 01:39:44 +0200 Subject: [PATCH 3/3] Bump minecraft dependency --- src/main/resources/fabric.mod.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index fd43572..ca7cbc4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,8 +29,8 @@ ], "depends": { - "minecraft": ">=1.20.3-", - "fabricloader": ">=0.15.0" + "minecraft": ">=1.20.5-", + "fabricloader": ">=0.15.10" }, "custom": { "modmenu": {