Skip to content

Commit

Permalink
Initial working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Nincodedo committed Jun 14, 2021
1 parent 9042f50 commit ae23785
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 60 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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";
}
}
14 changes: 0 additions & 14 deletions src/main/java/net/fabricmc/example/ExampleMod.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/net/fabricmc/example/mixin/ExampleMixin.java

This file was deleted.

9 changes: 3 additions & 6 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
],
Expand All @@ -19,12 +19,9 @@
"environment": "*",
"entrypoints": {
"main": [
"net.fabricmc.example.ExampleMod"
"dev.nincodedo.mcserverdescption.McServerDescription"
]
},
"mixins": [
"modid.mixins.json"
],

"depends": {
"fabricloader": ">=0.11.3",
Expand Down
14 changes: 0 additions & 14 deletions src/main/resources/modid.mixins.json

This file was deleted.

0 comments on commit ae23785

Please sign in to comment.