generated from FabricMC/fabric-example-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
58 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/dev/nincodedo/mcserverdescption/McServerDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/main/java/net/fabricmc/example/mixin/ExampleMixin.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.