From ec005072264960e405ca03aafaec0622f3a002e0 Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 21 Dec 2023 01:40:07 +0100 Subject: [PATCH] Added fancy MOTDs. --- README.md | 2 +- gradle.properties | 2 +- src/main/java/net/flashii/mcexts/RNG.java | 11 +++++ .../mcexts/mixin/ServerMetadataMixin.java | 42 +++++++++++++++++++ src/main/resources/fabric.mod.json | 2 +- .../resources/flashii-extensions.mixins.json | 3 +- 6 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/flashii/mcexts/RNG.java create mode 100644 src/main/java/net/flashii/mcexts/mixin/ServerMetadataMixin.java diff --git a/README.md b/README.md index aa95b99..005ceaa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is a [Fabric](https://fabricmc.net/) mod that can run on both clients and servers. Because the mod is relatively simple, Fabric API is not required and just having Fabric Loader works fine. -On servers it functions as an authentication provider while running on Offline Mode by RPCing with the [Mince](https://git.flash.moe/flashii/mince) project. +On servers it functions as an authentication provider while running on Offline Mode by RPCing with the [Mince](https://patchii.net/flashii/mince) project. On clients it enables skins while the server connected to is running in Offline Mode, it is not required but strongly recommended. This mod is not meant to enable or otherwise facilitate piracy, rather as an alternative for players who have previously purchased the game and are dissatisfied with Microsoft's handling of the property. diff --git a/gradle.properties b/gradle.properties index 6898acc..65dcd5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ yarn_mappings=1.20.1+build.10 loader_version=0.14.22 # Mod Properties -mod_version=1.0.0 +mod_version=1.0.1 maven_group=net.flashii.mcexts archives_base_name=flashii-extensions diff --git a/src/main/java/net/flashii/mcexts/RNG.java b/src/main/java/net/flashii/mcexts/RNG.java new file mode 100644 index 0000000..af4432f --- /dev/null +++ b/src/main/java/net/flashii/mcexts/RNG.java @@ -0,0 +1,11 @@ +package net.flashii.mcexts; + +import java.util.Random; + +public class RNG { + public static final Random rng = new Random(); + + public static int nextInt(int max) { + return rng.nextInt(max); + } +} diff --git a/src/main/java/net/flashii/mcexts/mixin/ServerMetadataMixin.java b/src/main/java/net/flashii/mcexts/mixin/ServerMetadataMixin.java new file mode 100644 index 0000000..a6ce2bc --- /dev/null +++ b/src/main/java/net/flashii/mcexts/mixin/ServerMetadataMixin.java @@ -0,0 +1,42 @@ +package net.flashii.mcexts.mixin; + +import java.util.StringJoiner; +import net.flashii.mcexts.Config; +import net.flashii.mcexts.RNG; +import net.minecraft.server.ServerMetadata; +import net.minecraft.text.MutableText; +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.CallbackInfoReturnable; + +@Mixin(ServerMetadata.class) +public abstract class ServerMetadataMixin { + @Inject(method = "description()Lnet/minecraft/text/Text;", at = @At("TAIL"), cancellable = true) + public void description(CallbackInfoReturnable cir) { + String linesRaw = Config.getValue("MOTDLines.txt"); + if(linesRaw == null || linesRaw.isBlank()) + return; + + String[] lines = linesRaw.split("\n"); + int linesCount = lines.length; + int lineNo = linesCount < 2 ? 0 : RNG.nextInt(linesCount); + String line = lines[lineNo].trim(); + + String original = cir.getReturnValue().getString(); + int originalSpace = original.indexOf(" "); + + String purple = originalSpace < 0 ? original : original.substring(0, originalSpace); + String white = originalSpace < 0 ? "" : original.substring(originalSpace); + + MutableText motd = Text.literal("") + .append(Text.literal(purple).styled(style -> style.withColor(0x9475B2).withBold(true))) + .append(Text.literal(white).styled(style -> style.withColor(0xFFFFFF))) + .append("\n ") + .append(line); + + cir.setReturnValue(motd); + cir.cancel(); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f4fcb95..7c3d804 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -9,7 +9,7 @@ ], "contact": { "homepage": "https://mc.flashii.net/", - "sources": "https://git.flash.moe/flashii/mcexts" + "sources": "https://patchii.net/flashii/mcexts" }, "license": "BSD-3-Clause-Clear", "icon": "assets/flashii-extensions/icon.png", diff --git a/src/main/resources/flashii-extensions.mixins.json b/src/main/resources/flashii-extensions.mixins.json index e52792b..46b07ae 100644 --- a/src/main/resources/flashii-extensions.mixins.json +++ b/src/main/resources/flashii-extensions.mixins.json @@ -9,7 +9,8 @@ "YggdrasilMinecraftSessionServiceMixin" ], "server": [ - "PlayerManagerMixin" + "PlayerManagerMixin", + "ServerMetadataMixin" ], "injectors": { "defaultRequire": 1