generated from KessokuTeaTime/Example-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
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
8 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/net/krlite/knowledges/api/proxy/LocalizationProxy.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,49 @@ | ||
package net.krlite.knowledges.api.proxy; | ||
|
||
import net.krlite.equator.math.algebra.Theory; | ||
import net.krlite.knowledges.KnowledgesClient; | ||
import net.minecraft.text.MutableText; | ||
import net.minecraft.text.Text; | ||
|
||
public class LocalizationProxy { | ||
public enum TimeUnit { | ||
MILLISECONDS("ms"), | ||
SECONDS("s"), | ||
MINUTES("m"), | ||
HOURS("h"); | ||
|
||
private final String path; | ||
|
||
TimeUnit(String path) { | ||
this.path = path; | ||
} | ||
|
||
public MutableText localize(double duration) { | ||
return Text.translatable( | ||
Theory.looseEquals(duration, 1) | ||
? KnowledgesClient.localizationKey("time_unit", path) | ||
: KnowledgesClient.localizationKey("time_unit", path, "plural"), | ||
String.format(duration % 1.0 == 0 ? "%.0f" : "%.2f", duration) | ||
); | ||
} | ||
|
||
public static MutableText fitAndLocalize(double milliseconds) { | ||
if (Math.abs(milliseconds) < 1000) { | ||
return MILLISECONDS.localize(milliseconds); | ||
} | ||
|
||
double seconds = milliseconds / 1000; | ||
if (Math.abs(seconds) < 60) { | ||
return SECONDS.localize(seconds); | ||
} | ||
|
||
double minutes = seconds / 60; | ||
if (Math.abs(minutes) < 60) { | ||
return MINUTES.localize(minutes); | ||
} | ||
|
||
double hours = minutes / 60; | ||
return HOURS.localize(hours); | ||
} | ||
} | ||
} |
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 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 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 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 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 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 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