Skip to content

Commit ae23785

Browse files
committed
Initial working version
1 parent 9042f50 commit ae23785

7 files changed

Lines changed: 58 additions & 60 deletions

File tree

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
# Fabric Example Mod
2-
3-
## Setup
4-
5-
For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using.
6-
7-
## License
8-
9-
This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.
1+
# MC Server Description
2+
Updates the server's MOTD with the day count, time of day, and weather.

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ org.gradle.jvmargs=-Xmx1G
99

1010
# Mod Properties
1111
mod_version = 1.0.0
12-
maven_group = com.example
13-
archives_base_name = fabric-example-mod
12+
maven_group = dev.nincodedo
13+
archives_base_name = mc-server-description
1414

1515
# Dependencies
1616
fabric_version=0.34.9+1.17
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package dev.nincodedo.mcserverdescption;
2+
3+
import net.fabricmc.api.ModInitializer;
4+
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
5+
import net.minecraft.text.LiteralText;
6+
import net.minecraft.world.World;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class McServerDescription implements ModInitializer {
10+
11+
@Override
12+
public void onInitialize() {
13+
ServerTickEvents.END_SERVER_TICK.register(server -> {
14+
if (server.isRemote()) {
15+
String motd = server.getServerMotd();
16+
World overworld = server.getOverworld();
17+
if (overworld != null) {
18+
long dayCount = overworld.getTimeOfDay() / 24000;
19+
String timeString = getTimeString(overworld.getTimeOfDay());
20+
String weatherStatus = getWeatherStatus(overworld.isRaining(), overworld.isThundering());
21+
22+
String stringBuilder = motd
23+
+ "\n§fCurrent Day: "
24+
+ dayCount
25+
+ " - "
26+
+ "Time: "
27+
+ timeString
28+
+ " - "
29+
+ "Weather: "
30+
+ weatherStatus;
31+
32+
server.getServerMetadata().setDescription(new LiteralText(stringBuilder));
33+
}
34+
}
35+
});
36+
}
37+
38+
@NotNull
39+
private String getTimeString(long serverTimeOfDay) {
40+
long currentTime = serverTimeOfDay % 24000;
41+
int hour = (int) (currentTime / 1000 + 6);
42+
int minute = (int) (currentTime % 1000 * 60 / 1000);
43+
String ampm = hour >= 12 ? "PM" : "AM";
44+
hour = hour >= 12 ? hour - 12 : hour;
45+
return hour + ":" + String.format("%02d", minute) + " " + ampm;
46+
}
47+
48+
private String getWeatherStatus(boolean isRaining, boolean isThundering) {
49+
return isThundering ? "Thundering" : isRaining ? "Raining" : "Clear";
50+
}
51+
}

src/main/java/net/fabricmc/example/ExampleMod.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/main/java/net/fabricmc/example/mixin/ExampleMixin.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/main/resources/fabric.mod.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"id": "modid",
44
"version": "${version}",
55

6-
"name": "Example Mod",
7-
"description": "This is an example description! Tell everyone what your mod is about!",
6+
"name": "MC Server Description",
7+
"description": "Updates the server's MOTD with the day count, time of day, and weather.",
88
"authors": [
99
"Me!"
1010
],
@@ -19,12 +19,9 @@
1919
"environment": "*",
2020
"entrypoints": {
2121
"main": [
22-
"net.fabricmc.example.ExampleMod"
22+
"dev.nincodedo.mcserverdescption.McServerDescription"
2323
]
2424
},
25-
"mixins": [
26-
"modid.mixins.json"
27-
],
2825

2926
"depends": {
3027
"fabricloader": ">=0.11.3",

src/main/resources/modid.mixins.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)