Added fancy MOTDs.

This commit is contained in:
flash 2023-12-21 01:40:07 +01:00
parent 6ddd24bfad
commit ec00507226
6 changed files with 58 additions and 4 deletions

View file

@ -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.

View file

@ -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

View file

@ -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);
}
}

View file

@ -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<Text> 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();
}
}

View file

@ -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",

View file

@ -9,7 +9,8 @@
"YggdrasilMinecraftSessionServiceMixin"
],
"server": [
"PlayerManagerMixin"
"PlayerManagerMixin",
"ServerMetadataMixin"
],
"injectors": {
"defaultRequire": 1