From ae23785d79bb9cc52c75c1599758d2577e08ddbd Mon Sep 17 00:00:00 2001 From: Nincodedo Date: Mon, 14 Jun 2021 15:09:01 -0500 Subject: [PATCH] Initial working version --- README.md | 11 +--- gradle.properties | 4 +- .../McServerDescription.java | 51 +++++++++++++++++++ .../java/net/fabricmc/example/ExampleMod.java | 14 ----- .../fabricmc/example/mixin/ExampleMixin.java | 15 ------ src/main/resources/fabric.mod.json | 9 ++-- src/main/resources/modid.mixins.json | 14 ----- 7 files changed, 58 insertions(+), 60 deletions(-) create mode 100644 src/main/java/dev/nincodedo/mcserverdescption/McServerDescription.java delete mode 100644 src/main/java/net/fabricmc/example/ExampleMod.java delete mode 100644 src/main/java/net/fabricmc/example/mixin/ExampleMixin.java delete mode 100644 src/main/resources/modid.mixins.json diff --git a/README.md b/README.md index fd96346..10e28e5 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,2 @@ -# Fabric Example Mod - -## Setup - -For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using. - -## License - -This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. +# MC Server Description +Updates the server's MOTD with the day count, time of day, and weather. diff --git a/gradle.properties b/gradle.properties index 2bb5a4d..5b37572 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,8 +9,8 @@ org.gradle.jvmargs=-Xmx1G # Mod Properties mod_version = 1.0.0 - maven_group = com.example - archives_base_name = fabric-example-mod + maven_group = dev.nincodedo + archives_base_name = mc-server-description # Dependencies fabric_version=0.34.9+1.17 diff --git a/src/main/java/dev/nincodedo/mcserverdescption/McServerDescription.java b/src/main/java/dev/nincodedo/mcserverdescption/McServerDescription.java new file mode 100644 index 0000000..413875d --- /dev/null +++ b/src/main/java/dev/nincodedo/mcserverdescption/McServerDescription.java @@ -0,0 +1,51 @@ +package dev.nincodedo.mcserverdescption; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.minecraft.text.LiteralText; +import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; + +public class McServerDescription implements ModInitializer { + + @Override + public void onInitialize() { + ServerTickEvents.END_SERVER_TICK.register(server -> { + if (server.isRemote()) { + String motd = server.getServerMotd(); + World overworld = server.getOverworld(); + if (overworld != null) { + long dayCount = overworld.getTimeOfDay() / 24000; + String timeString = getTimeString(overworld.getTimeOfDay()); + String weatherStatus = getWeatherStatus(overworld.isRaining(), overworld.isThundering()); + + String stringBuilder = motd + + "\n§fCurrent Day: " + + dayCount + + " - " + + "Time: " + + timeString + + " - " + + "Weather: " + + weatherStatus; + + server.getServerMetadata().setDescription(new LiteralText(stringBuilder)); + } + } + }); + } + + @NotNull + private String getTimeString(long serverTimeOfDay) { + long currentTime = serverTimeOfDay % 24000; + int hour = (int) (currentTime / 1000 + 6); + int minute = (int) (currentTime % 1000 * 60 / 1000); + String ampm = hour >= 12 ? "PM" : "AM"; + hour = hour >= 12 ? hour - 12 : hour; + return hour + ":" + String.format("%02d", minute) + " " + ampm; + } + + private String getWeatherStatus(boolean isRaining, boolean isThundering) { + return isThundering ? "Thundering" : isRaining ? "Raining" : "Clear"; + } +} diff --git a/src/main/java/net/fabricmc/example/ExampleMod.java b/src/main/java/net/fabricmc/example/ExampleMod.java deleted file mode 100644 index e5ed082..0000000 --- a/src/main/java/net/fabricmc/example/ExampleMod.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.fabricmc.example; - -import net.fabricmc.api.ModInitializer; - -public class ExampleMod implements ModInitializer { - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - System.out.println("Hello Fabric world!"); - } -} diff --git a/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java b/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java deleted file mode 100644 index 83ee1a8..0000000 --- a/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.fabricmc.example.mixin; - -import net.minecraft.client.gui.screen.TitleScreen; -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; - -@Mixin(TitleScreen.class) -public class ExampleMixin { - @Inject(at = @At("HEAD"), method = "init()V") - private void init(CallbackInfo info) { - System.out.println("This line is printed by an example mod mixin!"); - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a0bfabb..6218683 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,8 +3,8 @@ "id": "modid", "version": "${version}", - "name": "Example Mod", - "description": "This is an example description! Tell everyone what your mod is about!", + "name": "MC Server Description", + "description": "Updates the server's MOTD with the day count, time of day, and weather.", "authors": [ "Me!" ], @@ -19,12 +19,9 @@ "environment": "*", "entrypoints": { "main": [ - "net.fabricmc.example.ExampleMod" + "dev.nincodedo.mcserverdescption.McServerDescription" ] }, - "mixins": [ - "modid.mixins.json" - ], "depends": { "fabricloader": ">=0.11.3", diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/modid.mixins.json deleted file mode 100644 index 9cf7e06..0000000 --- a/src/main/resources/modid.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "net.fabricmc.example.mixin", - "compatibilityLevel": "JAVA_16", - "mixins": [ - ], - "client": [ - "ExampleMixin" - ], - "injectors": { - "defaultRequire": 1 - } -}