Skip to content

Commit

Permalink
feat: initial implementation.
Browse files Browse the repository at this point in the history
still missing metadata stuff like credits, icon, and description, but it's working
  • Loading branch information
Jamalam360 committed Mar 17, 2024
1 parent 187f6f1 commit 36929a7
Show file tree
Hide file tree
Showing 38 changed files with 225 additions and 371 deletions.
File renamed without changes.
20 changes: 0 additions & 20 deletions .github/workflows/test-server

This file was deleted.

69 changes: 0 additions & 69 deletions .github/workflows/test-template.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ build
eclipse
run
.architectury-transformer

backup
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 {{ author }}
Copyright 2024 Jamalam

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
22 changes: 3 additions & 19 deletions build.gradle.easytemplate → build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
{{#if unified_publishing}}
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
{{/if}}
{{#if github_publish}}
id "com.github.breadmoirai.github-release" version "2.4.1"
{{/if}}
}
{{#if github_publish}}

if (System.getenv("GITHUB_TOKEN") != null) {
githubRelease {
token(System.getenv("GITHUB_TOKEN"))
owner("{{ github_owner }}")
repo("{{ github_repo }}")
owner("JamCoreModding")
repo("wake-up-time")
tagName("${project.version}")
releaseName("V${project.version}")
body(project.rootProject.file("CHANGELOG.md").text)
Expand All @@ -25,7 +20,6 @@ if (System.getenv("GITHUB_TOKEN") != null) {
}
}
}
{{/if}}

subprojects {
apply plugin: "dev.architectury.loom"
Expand All @@ -34,10 +28,6 @@ subprojects {
silentMojangMappingsLicense()
}

base {
archivesName = "{{mod_id}}"
}

jar {
manifest {
attributes([
Expand All @@ -47,7 +37,7 @@ subprojects {
'Implementation-Version' : project.jar.archiveVersion,
'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
'Built-On-Minecraft' : minecraft_version,
'JamLib-File-Name' : "jamlib-${project.base.archivesName.get()}-${rootProject.version}.jar",
'JamLib-File-Name' : "wake_up_time-${project.base.archivesName.get()}-${rootProject.version}.jar",
])
}
}
Expand Down Expand Up @@ -90,18 +80,12 @@ allprojects {
java {
withSourcesJar()
}
{{#ifCond github_publish '||' unified_publishing}}

tasks.publish {
{{#if github_publish}}
dependsOn(":githubRelease")
{{/if}}
{{#if unified_publishing}}
dependsOn("fabric:publishUnified")
dependsOn("quilt:publishUnified")
dependsOn("forge:publishUnified")
dependsOn("neoforge:publishUnified")
{{/if}}
}
{{/ifCond}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package io.github.jamalam360.wake_up_time;

import dev.architectury.event.events.client.ClientTickEvent;
import dev.architectury.platform.Platform;
import dev.architectury.registry.client.keymappings.KeyMappingRegistry;
import io.github.jamalam360.jamlib.JamLib;
import io.github.jamalam360.jamlib.JamLibPlatform;
import io.github.jamalam360.jamlib.config.ConfigManager;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.network.chat.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;

import static org.lwjgl.glfw.GLFW.GLFW_KEY_V;

//TODO: make this only execute on client
public class WakeUpTime {
public static final String MOD_ID = "wake_up_time";
public static final String MOD_NAME = "Wake Up Time";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
public static final ConfigManager<Config> CONFIG = new ConfigManager<>(MOD_ID, Config.class);
private static final KeyMapping sendStatusToActionBar = new KeyMapping("key.wake_up_time.status", GLFW_KEY_V, "category.wake_up_time");
private static boolean enabled = false;

public static void init() {
LOGGER.info("Initializing Wake Up Time on " + JamLibPlatform.getPlatform().name());

if (JamLibPlatform.getPlatform() == JamLibPlatform.Platform.FABRIC || JamLibPlatform.getPlatform() == JamLibPlatform.Platform.QUILT) {
Path configFolder = Platform.getConfigFolder();
Path oldConfig = configFolder.resolve("wake_up_time.json");
Path newConfig = configFolder.resolve("wake_up_time.json5");

if (oldConfig.toFile().exists()) {
LOGGER.info("Found an legacy config file, recovering it");

if (newConfig.toFile().exists()) {
LOGGER.warn("Found a new config file, not recovering the legacy config");
} else {
if (oldConfig.toFile().renameTo(newConfig.toFile())) {
LOGGER.info("Recovered the legacy config file");
} else {
LOGGER.error("Failed to recover the legacy config file");
}
}

}
}

JamLib.checkForJarRenaming(WakeUpTime.class);
KeyMappingRegistry.register(sendStatusToActionBar);
ClientTickEvent.CLIENT_LEVEL_POST.register((level) -> {
if (sendStatusToActionBar.consumeClick()) {
enabled = !enabled;
sendStatusToActionBar(level);
}

if (CONFIG.get().persistent && enabled) {
sendStatusToActionBar(level);
}
});
}

private static void sendStatusToActionBar(ClientLevel level) {
if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.displayClientMessage(Component.translatable("text.wake_up_time.status", getStageComponent(level)), true);
}
}

private static Component getStageComponent(ClientLevel level) {
long time = level.getDayTime();
while (time > 24000) time = time - 24000;

if (time < 9000 && time >= 2000) {
return Component.translatable("text.wake_up_time.working", "§a" + (9000 - time) / 20);
}

Component status = Component.translatable("text.wake_up_time.wandering");
if (time >= 12000 || time < 10) status = Component.translatable("text.wake_up_time.sleeping");
if (time >= 9000 && time < 11000) status = Component.translatable("text.wake_up_time.gathering");

final long timeUntilWork = time > 9000 ? 26000 - time : 2000 - time;

return Component.translatable("text.wake_up_time.lazy_bums", "§a" + status.getString(), "§a" + timeUntilWork / 20);
}

public static class Config {
public boolean persistent = false;
}
}

This file was deleted.

This file was deleted.

13 changes: 13 additions & 0 deletions common/src/main/resources/assets/wake_up_time/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"config.wake_up_time.title": "Wake Up Time Config",
"config.wake_up_time.persistent": "Persistent notification",
"config.wake_up_time.persistent.tooltip": "If enabled, pressing the keybind will toggle the message on and off. If disabled, the message will only be displayed for a short time.",
"category.wake_up_time.": "Wake Up Time",
"key.wake_up_time.send_status": "Send villager clock status",
"text.wake_up_time.status": "§bEmployed villagers are currently %s",
"text.wake_up_time.lazy_bums": "%s§b; %s§a seconds§b until working time",
"text.wake_up_time.working": "§aworking§b; %s§a seconds§b until workday ends",
"text.wake_up_time.sleeping": "§asleeping",
"text.wake_up_time.gathering": "§agathering",
"text.wake_up_time.wandering": "§awandering"
}
13 changes: 13 additions & 0 deletions common/src/main/resources/assets/wake_up_time/lang/ru_ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"config.wake_up_time.title": "Wake Up Time Config",
"config.wake_up_time.persistent": "Persistent notification",
"config.wake_up_time.persistent.tooltip": "If enabled, pressing the keybind will toggle the message on and off. If disabled, the message will only be displayed for a short time.",
"category.wake_up_time.": "Wake Up Time",
"key.wake_up_time.send_status": "Показать статус жителей",
"text.wake_up_time.status": "§bСтатус жителей - %s",
"text.wake_up_time.lazy_bums": "%s§b; %s§a секунды§b до рабочего времени",
"text.wake_up_time.working": "§aработа§b; %s§a секунды§b до окончания рабочего дня",
"text.wake_up_time.sleeping": "§aсон",
"text.wake_up_time.gathering": "§aсбор",
"text.wake_up_time.wandering": "§aсвободное время"
}
16 changes: 0 additions & 16 deletions common/src/main/resources/{{ mod_id }}.mixins.json

This file was deleted.

Loading

0 comments on commit 36929a7

Please sign in to comment.