Skip to content

Commit

Permalink
more utils
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Mar 13, 2024
1 parent 43ad6e3 commit 62c41aa
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 11 deletions.
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static class Crosshair {
public boolean textsRightEnabled = true;
public boolean textsLeftEnabled = true;
public boolean subtitlesEnabled = true;
public long spareDelayMilliseconds = 200;
public double primaryOpacity = 0.72;
public double secondaryOpacity = 0.5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.krlite.knowledges.KnowledgesClient;
import net.krlite.knowledges.api.component.Knowledge;
import net.krlite.knowledges.api.proxy.LayoutProxy;
import net.krlite.knowledges.api.proxy.LocalizationProxy;
import net.krlite.knowledges.api.proxy.RenderProxy;
import net.krlite.knowledges.api.representable.base.Representable;
import net.krlite.knowledges.config.modmenu.KnowledgesConfigScreen;
Expand Down Expand Up @@ -205,6 +206,18 @@ public boolean requestsConfigPage() {

KnowledgesConfigScreen.emptyEntryBuilder(),

entryBuilder.startLongSlider(
localizeForConfig("spare_delay"),
KnowledgesClient.CONFIG.get().components.crosshair.spareDelayMilliseconds,
0, 2000
)
.setDefaultValue(KnowledgesClient.DEFAULT_CONFIG.components.crosshair.spareDelayMilliseconds)
.setTooltip(localizeTooltipForConfig("spare_delay"))
.setSaveConsumer(value -> KnowledgesClient.CONFIG.get().components.crosshair.spareDelayMilliseconds = value)
.setTextGetter(LocalizationProxy.TimeUnit::fitAndLocalize),

KnowledgesConfigScreen.emptyEntryBuilder(),

entryBuilder.startIntSlider(
localizeForConfig("primary_opacity"),
KnowledgesClient.CONFIG.get().components.crosshair.primaryOpacityAsInt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Optional<MutableText> blockInformation(BlockRepresentable representable)

if (available > 2) {
return Text.translatable(
localizationKey("more_patterns"),
localizationKey("pattern", "more"),
name.getString(),
available - 1,
// Counts the rest of the patterns. Use '%2$d' to reference.
Expand All @@ -43,7 +43,7 @@ public Optional<MutableText> blockInformation(BlockRepresentable representable)
);
} else if (available > 1) {
return Text.translatable(
localizationKey("one_more_pattern"),
localizationKey("pattern", "one_more"),
name.getString()
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ public class BlockInformationDataProvider implements DataProvider<BlockInformati
@Override
public @NotNull List<Class<? extends BlockInformationData>> provide() {
return List.of(
NoteBlockData.class,
BannerData.class,
BeehiveData.class,
BrewingStandData.class,
ComposterData.class,
RedstoneWireData.class,
CropData.class,
SaplingData.class,
BeehiveData.class
NoteBlockData.class,
RedstoneWireData.class,
SaplingData.class
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class EntityInformationDataProvider implements DataProvider<EntityInforma
@Override
public @NotNull List<Class<? extends EntityInformationData>> provide() {
return List.of(
PaintingData.class,
ItemFrameData.class,
PaintingData.class,
VillagerData.class
);
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/resources/assets/knowledges/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@

"util.knowledges.date_and_time": "§7Day %1$s, §r%2$s:%3$s",

"time_unit.knowledges.ms" : "%1$s millisecond",
"time_unit.knowledges.ms.plural": "%1$s milliseconds",
"time_unit.knowledges.s" : "%1$s second",
"time_unit.knowledges.s.plural" : "%1$s seconds",
"time_unit.knowledges.m" : "%1$s minute",
"time_unit.knowledges.m.plural" : "%1$s minutes",
"time_unit.knowledges.h" : "%1$s hour",
"time_unit.knowledges.h.plural" : "%1$s hours",



"knowledges:component/knowledges:crosshair:name" : "Crosshair",
Expand All @@ -97,6 +106,9 @@
"knowledges:component/knowledges:crosshair:config/subtitles" : "Subtitles",
"knowledges:component/knowledges:crosshair:config/subtitles.tooltip": "Whether to display the descriptive texts that are above or below the crosshair texts",

"knowledges:component/knowledges:crosshair:config/spare_delay" : "Spare Delay",
"knowledges:component/knowledges:crosshair:config/spare_delay.tooltip": "Determines how long the cursor waits before appearing to be visible",

"knowledges:component/knowledges:crosshair:config/primary_opacity" : "Primary Opacity",
"knowledges:component/knowledges:crosshair:config/primary_opacity.tooltip": "Controls the display opacity of primary information around the cursor",

Expand Down Expand Up @@ -166,8 +178,8 @@
"knowledges:data/knowledges:info/block//block_information/banner:tooltip": "Provides information about banners",

"knowledges:data/knowledges:info/block//block_information/banner:pattern" : "%1$s",
"knowledges:data/knowledges:info/block//block_information/banner:more_patterns" : "§r%1$s §7and %2$d More",
"knowledges:data/knowledges:info/block//block_information/banner:one_more_pattern": "§r%1$s §7and 1 More",
"knowledges:data/knowledges:info/block//block_information/banner:pattern.more" : "§r%1$s §7and %2$d More",
"knowledges:data/knowledges:info/block//block_information/banner:pattern.one_more": "§r%1$s §7and 1 More",

"knowledges:data/knowledges:info/block//block_information/composter:name" : "Composter Information",
"knowledges:data/knowledges:info/block//block_information/composter:tooltip": "Provides information about composters' composition levels",
Expand Down
16 changes: 14 additions & 2 deletions src/main/resources/assets/knowledges/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
"ring_shape.knowledges.diamond.tooltip": "看起来棱角分明,渲染速度更快",

"util.knowledges.date_and_time": "§7第%1$s天,§r%2$s:%3$s",

"time_unit.knowledges.ms" : "%1$s毫秒",
"time_unit.knowledges.ms.plural": "%1$s毫秒",
"time_unit.knowledges.s" : "%1$s秒",
"time_unit.knowledges.s.plural" : "%1$s秒",
"time_unit.knowledges.m" : "%1$s分钟",
"time_unit.knowledges.m.plural" : "%1$s分钟",
"time_unit.knowledges.h" : "%1$s小时",
"time_unit.knowledges.h.plural" : "%1$s小时",



Expand All @@ -99,6 +108,9 @@
"knowledges:component/knowledges:crosshair:config/subtitles" : "副标题",
"knowledges:component/knowledges:crosshair:config/subtitles.tooltip": "显示位于准心文本上方或下方的描述性文本",

"knowledges:component/knowledges:crosshair:config/spare_delay" : "空闲延迟",
"knowledges:component/knowledges:crosshair:config/spare_delay.tooltip": "决定准心组件在变为可见状态前的延迟等待时间",

"knowledges:component/knowledges:crosshair:config/primary_opacity" : "主要透明度",
"knowledges:component/knowledges:crosshair:config/primary_opacity.tooltip": "控制准心处主要信息的显示透明度",

Expand Down Expand Up @@ -167,8 +179,8 @@
"knowledges:data/knowledges:info/block//block_information/banner:name" : "旗帜信息",
"knowledges:data/knowledges:info/block//block_information/banner:tooltip": "提供有关旗帜的信息",

"knowledges:data/knowledges:info/block//block_information/banner:more_patterns" : "§r%1$s§7等%3$d个样式",
"knowledges:data/knowledges:info/block//block_information/banner:one_more_pattern": "§r%1$s§7等2个样式",
"knowledges:data/knowledges:info/block//block_information/banner:pattern.more" : "§r%1$s§7等%3$d个样式",
"knowledges:data/knowledges:info/block//block_information/banner:pattern.one_more": "§r%1$s§7等2个样式",

"knowledges:data/knowledges:info/block//block_information/composter:name" : "堆肥桶信息",
"knowledges:data/knowledges:info/block//block_information/composter:tooltip": "提供有关堆肥桶的堆肥等级的信息",
Expand Down

0 comments on commit 62c41aa

Please sign in to comment.