Skip to content

Commit

Permalink
Added a message informing the player of a new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Aug 20, 2023
1 parent 4af1875 commit dad3553
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ neo_version=47.1.63
mappings_channel=parchment
mappings_version=2023.08.06-1.20.1

mod_version=1.0.2
mod_version=1.0.3

# Deps
mixin_version=0.8.5
Expand Down
49 changes: 32 additions & 17 deletions src/main/java/mods/railcraft/client/ClientManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.VersionChecker;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.loading.FMLLoader;

Expand Down Expand Up @@ -203,28 +205,41 @@ static void handleClientLoggedOut(ClientPlayerNetworkEvent.LoggingOut event) {

@SubscribeEvent
static void handleClientLoggedIn(ClientPlayerNetworkEvent.LoggingIn event) {
if (!Railcraft.BETA && FMLLoader.isProduction()) {
return;
var modInfo = ModList.get().getModFileById(Railcraft.ID).getMods().get(0);
var versionStatus = VersionChecker.getResult(modInfo).status();

if (versionStatus.shouldDraw()) {
var message = Component.literal("Railcraft Reborn: ").withStyle(ChatFormatting.GREEN)
.append(Component.literal("A new version is available to download.")
.withStyle(style -> style
.withColor(ChatFormatting.WHITE)
.withUnderlined(true)
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
"https://www.curseforge.com/minecraft/mc-mods/railcraft-reborn"))));
event.getPlayer().displayClientMessage(message, false);
}
var type = !FMLLoader.isProduction() ? "development" : "beta";
var message = CommonComponents.joinLines(
Component.literal("You are using a " + type + " version of Railcraft.")
.withStyle(ChatFormatting.RED),

if (Railcraft.BETA || !FMLLoader.isProduction()) {
var type = FMLLoader.isProduction() ? "beta" : "development";
var message = CommonComponents.joinLines(
Component.literal("You are using a " + type + " version of Railcraft Reborn.")
.withStyle(ChatFormatting.RED),
/*Component.literal("- World saves are not stable and may break between versions.")
.withStyle(ChatFormatting.GRAY),*/
Component.literal("- Features might be missing or only partially implemented.")
.withStyle(ChatFormatting.GRAY),
Component.literal("- Features might be missing or only partially implemented.")
.withStyle(ChatFormatting.GRAY),
/*Component.literal("You have been warned.")
.withStyle(ChatFormatting.RED, ChatFormatting.ITALIC),*/
Component.literal("Bug reports are welcome at our issue tracker.")
.withStyle(style -> style
.withColor(ChatFormatting.GREEN)
.withUnderlined(true)
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
"https://github.com/railcraft-reborn/railcraft/issues"))),
Component.literal("- Sm0keySa1m0n, Edivad99")
.withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC));
event.getPlayer().displayClientMessage(message, false);
Component.literal("Bug reports are welcome at our issue tracker.")
.withStyle(style -> style
.withColor(ChatFormatting.GREEN)
.withUnderlined(true)
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
"https://github.com/railcraft-reborn/railcraft/issues"))),
Component.literal("- Sm0keySa1m0n, Edivad99")
.withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC));
event.getPlayer().displayClientMessage(message, false);
}
}

@SubscribeEvent
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ issueTrackerURL = "https://github.com/railcraft-reborn/railcraft/issues"
modId = "railcraft"
version = "${mod_version}"
displayName = "Railcraft Reborn"
updateJSONURL = "https://api.modrinth.com/updates/railcraft-reborn/forge_updates.json"
logoFile = "pack.png"
credits = "Created by CovertJaguar and other contributions at Github"
authors = "Sm0keySa1m0n, Edivad99"
Expand Down

0 comments on commit dad3553

Please sign in to comment.