Skip to content

Commit

Permalink
v3.9.1 dev. progress
Browse files Browse the repository at this point in the history
Mob stat phrases...
  • Loading branch information
TheCSDev committed Feb 26, 2024
1 parent d2aa371 commit 30314ea
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.github.thecsdev.betterstats.api.client.gui.stats.widget;

import static io.github.thecsdev.betterstats.api.registry.BSRegistries.getEntityStatTypePhrase;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;

import java.util.Objects;

import org.jetbrains.annotations.Nullable;

import io.github.thecsdev.betterstats.BetterStats;
import io.github.thecsdev.betterstats.BetterStatsConfig;
import io.github.thecsdev.betterstats.api.registry.BSRegistries;
import io.github.thecsdev.betterstats.api.util.enumerations.MobStatType;
import io.github.thecsdev.betterstats.api.util.stats.SUMobStat;
import io.github.thecsdev.tcdcommons.api.client.gui.other.TEntityRendererElement;
import io.github.thecsdev.tcdcommons.api.client.gui.util.GuiUtils;
Expand All @@ -31,8 +30,8 @@
// --------------------------------------------------
public static final int SIZE = 55;
//
public static final Text TEXT_STAT_KILLS = translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.kills");
public static final Text TEXT_STAT_DEATHS = translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.deaths");
public static final Text TEXT_STAT_KILLS = MobStatType.KILLED.getText();
public static final Text TEXT_STAT_DEATHS = MobStatType.KILLED_BY.getText();
// --------------------------------------------------
protected final EntityType<?> entityType;
protected final TEntityRendererElement entityRenderer;
Expand Down Expand Up @@ -63,10 +62,9 @@ public MobStatWidget(int x, int y, int size, SUMobStat stat) throws NullPointerE
else
{
@SuppressWarnings("unchecked")
final var stVal = stat.getStatsProvider().getStatValue(
(StatType<EntityType<?>>)statType, stat.getEntityType());
final var stIdStr = Objects.toString(Registries.STAT_TYPE.getId(statType));
ttt.append("\n§e-§r ").append(stIdStr + " : " + stVal);
final var statTypeE = (StatType<EntityType<?>>)statType;
final var stVal = stat.getStatsProvider().getStatValue(statTypeE, stat.getEntityType());
ttt.append("\n§e-§r ").append(getEntityStatTypePhrase(statTypeE)).append(": " + stVal);
}
}
setTooltip(this.defaultTooltip = Tooltip.of(ttt));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.thecsdev.betterstats.api.registry;

import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand All @@ -13,6 +13,7 @@
import io.github.thecsdev.betterstats.BetterStats;
import io.github.thecsdev.betterstats.api.util.stats.SUMobStat;
import io.github.thecsdev.tcdcommons.api.registry.TRegistry;
import io.github.thecsdev.tcdcommons.api.util.TextUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -141,9 +142,32 @@ private BSRegistries() {}
*/
public static final Text getEntityStatTypePhrase(StatType<EntityType<?>> statType)
{
final @Nullable var p = ENTITY_STAT_PHRASE.get(statType);
if(p != null) return p;
else return literal(Objects.toString(Registries.STAT_TYPE.getId(statType)));
//first approach: look at the better-stats registry
do
{
final @Nullable var p = ENTITY_STAT_PHRASE.get(statType);
if(p == null) break;
return p;
}
while(false);

//alternative approach: look in the translation keys
do
{
final @Nullable var statTypeId = Registries.STAT_TYPE.getId(statType);
if(statTypeId == null) break;

final var stKey = statTypeId.toString().replace(':', '.');
final var tKey = "betterstats.stat_type_phrase." + stKey;
final var phrase = Text.translatable(tKey);

if(!Objects.equals(tKey, phrase.getString())) return phrase;
else return TextUtils.literal(statTypeId.toString());
}
while(false);

//last resort: null
return TextUtils.literal("null");
}
// ==================================================
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.thecsdev.betterstats.api.util.enumerations;

import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget.TEXT_STAT_DEATHS;
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget.TEXT_STAT_KILLS;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;

import java.util.Objects;
import java.util.function.Function;
Expand All @@ -16,8 +15,8 @@
public enum MobStatType implements ITextProvider
{
// ==================================================
KILLED( Stats.KILLED, TEXT_STAT_KILLS, s -> s.kills),
KILLED_BY(Stats.KILLED_BY, TEXT_STAT_DEATHS, s -> s.deaths);
KILLED(Stats.KILLED, translatable("betterstats.stat_type_phrase.minecraft.killed"), s -> s.kills),
KILLED_BY(Stats.KILLED_BY, translatable("betterstats.stat_type_phrase.minecraft.killed_by"), s -> s.deaths);
// ==================================================
private final StatType<?> statType;
private final Text text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"commands.statistics.query.output": "%s's stat value for %s is %s.",


"betterstats.stat_type_phrase.minecraft.killed": "Killed",
"betterstats.stat_type_phrase.minecraft.killed_by": "Died to",
"betterstats.stat_type_phrase.morestats.damaged": "Damage dealt (x10)",
"betterstats.stat_type_phrase.morestats.damaged_by": "Damage taken (x10)",
"betterstats.stat_type_phrase.morestats.totem_popped_by": "Totems popped by",


"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file": "File",
"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file.new": "New",
"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file.open": "Open",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.thecsdev.betterstats.api.client.gui.stats.widget;

import static io.github.thecsdev.betterstats.api.registry.BSRegistries.getEntityStatTypePhrase;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal;

import java.util.Objects;

import org.jetbrains.annotations.Nullable;

import io.github.thecsdev.betterstats.BetterStats;
Expand Down Expand Up @@ -63,10 +62,9 @@ public MobStatWidget(int x, int y, int size, SUMobStat stat) throws NullPointerE
else
{
@SuppressWarnings("unchecked")
final var stVal = stat.getStatsProvider().getStatValue(
(StatType<EntityType<?>>)statType, stat.getEntityType());
final var stIdStr = Objects.toString(Registries.STAT_TYPE.getId(statType));
ttt.append("\n§e-§r ").append(stIdStr + " : " + stVal);
final var statTypeE = (StatType<EntityType<?>>)statType;
final var stVal = stat.getStatsProvider().getStatValue(statTypeE, stat.getEntityType());
ttt.append("\n§e-§r ").append(getEntityStatTypePhrase(statTypeE)).append(": " + stVal);
}
}
setTooltip(this.defaultTooltip = Tooltip.of(ttt));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.thecsdev.betterstats.api.registry;

import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;

import java.util.HashMap;
Expand All @@ -14,6 +13,7 @@
import io.github.thecsdev.betterstats.BetterStats;
import io.github.thecsdev.betterstats.api.util.stats.SUMobStat;
import io.github.thecsdev.tcdcommons.api.registry.TRegistry;
import io.github.thecsdev.tcdcommons.api.util.TextUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -142,9 +142,32 @@ private BSRegistries() {}
*/
public static final Text getEntityStatTypePhrase(StatType<EntityType<?>> statType)
{
final @Nullable var p = ENTITY_STAT_PHRASE.get(statType);
if(p != null) return p;
else return literal(Objects.toString(Registries.STAT_TYPE.getId(statType)));
//first approach: look at the better-stats registry
do
{
final @Nullable var p = ENTITY_STAT_PHRASE.get(statType);
if(p == null) break;
return p;
}
while(false);

//alternative approach: look in the translation keys
do
{
final @Nullable var statTypeId = Registries.STAT_TYPE.getId(statType);
if(statTypeId == null) break;

final var stKey = statTypeId.toString().replace(':', '.');
final var tKey = "betterstats.stat_type_phrase." + stKey;
final var phrase = Text.translatable(tKey);

if(!Objects.equals(tKey, phrase.getString())) return phrase;
else return TextUtils.literal(statTypeId.toString());
}
while(false);

//last resort: null
return TextUtils.literal("null");
}
// ==================================================
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public enum MobStatType implements ITextProvider
{
// ==================================================
KILLED(Stats.KILLED, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.kills"), s -> s.kills),
KILLED_BY(Stats.KILLED_BY, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.deaths"), s -> s.deaths);
KILLED(Stats.KILLED, translatable("betterstats.stat_type_phrase.minecraft.killed"), s -> s.kills),
KILLED_BY(Stats.KILLED_BY, translatable("betterstats.stat_type_phrase.minecraft.killed_by"), s -> s.deaths);
// ==================================================
private final StatType<?> statType;
private final Text text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"commands.statistics.query.output": "%s's stat value for %s is %s.",


"betterstats.stat_type_phrase.minecraft.killed": "Killed",
"betterstats.stat_type_phrase.minecraft.killed_by": "Died to",
"betterstats.stat_type_phrase.morestats.damaged": "Damage dealt",
"betterstats.stat_type_phrase.morestats.damaged_by": "Damage taken",
"betterstats.stat_type_phrase.morestats.totem_popped_by": "Totems popped by",


"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file": "File",
"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file.new": "New",
"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file.open": "Open",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.thecsdev.betterstats.api.client.gui.stats.widget;

import static io.github.thecsdev.betterstats.api.registry.BSRegistries.getEntityStatTypePhrase;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal;

import java.util.Objects;

import org.jetbrains.annotations.Nullable;

import io.github.thecsdev.betterstats.BetterStats;
Expand Down Expand Up @@ -63,10 +62,9 @@ public MobStatWidget(int x, int y, int size, SUMobStat stat) throws NullPointerE
else
{
@SuppressWarnings("unchecked")
final var stVal = stat.getStatsProvider().getStatValue(
(StatType<EntityType<?>>)statType, stat.getEntityType());
final var stIdStr = Objects.toString(Registries.STAT_TYPE.getId(statType));
ttt.append("\n§e-§r ").append(stIdStr + " : " + stVal);
final var statTypeE = (StatType<EntityType<?>>)statType;
final var stVal = stat.getStatsProvider().getStatValue(statTypeE, stat.getEntityType());
ttt.append("\n§e-§r ").append(getEntityStatTypePhrase(statTypeE)).append(": " + stVal);
}
}
setTooltip(this.defaultTooltip = Tooltip.of(ttt));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.thecsdev.betterstats.api.registry;

import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;

import java.util.HashMap;
Expand All @@ -14,6 +13,7 @@
import io.github.thecsdev.betterstats.BetterStats;
import io.github.thecsdev.betterstats.api.util.stats.SUMobStat;
import io.github.thecsdev.tcdcommons.api.registry.TRegistry;
import io.github.thecsdev.tcdcommons.api.util.TextUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -142,9 +142,32 @@ private BSRegistries() {}
*/
public static final Text getEntityStatTypePhrase(StatType<EntityType<?>> statType)
{
final @Nullable var p = ENTITY_STAT_PHRASE.get(statType);
if(p != null) return p;
else return literal(Objects.toString(Registries.STAT_TYPE.getId(statType)));
//first approach: look at the better-stats registry
do
{
final @Nullable var p = ENTITY_STAT_PHRASE.get(statType);
if(p == null) break;
return p;
}
while(false);

//alternative approach: look in the translation keys
do
{
final @Nullable var statTypeId = Registries.STAT_TYPE.getId(statType);
if(statTypeId == null) break;

final var stKey = statTypeId.toString().replace(':', '.');
final var tKey = "betterstats.stat_type_phrase." + stKey;
final var phrase = Text.translatable(tKey);

if(!Objects.equals(tKey, phrase.getString())) return phrase;
else return TextUtils.literal(statTypeId.toString());
}
while(false);

//last resort: null
return TextUtils.literal("null");
}
// ==================================================
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public enum MobStatType implements ITextProvider
{
// ==================================================
KILLED(Stats.KILLED, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.kills"), s -> s.kills),
KILLED_BY(Stats.KILLED_BY, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.deaths"), s -> s.deaths);
KILLED(Stats.KILLED, translatable("betterstats.stat_type_phrase.minecraft.killed"), s -> s.kills),
KILLED_BY(Stats.KILLED_BY, translatable("betterstats.stat_type_phrase.minecraft.killed_by"), s -> s.deaths);
// ==================================================
private final StatType<?> statType;
private final Text text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"commands.statistics.query.output": "%s's stat value for %s is %s.",


"betterstats.stat_type_phrase.minecraft.killed": "Killed",
"betterstats.stat_type_phrase.minecraft.killed_by": "Died to",
"betterstats.stat_type_phrase.morestats.damaged": "Damage dealt",
"betterstats.stat_type_phrase.morestats.damaged_by": "Damage taken",
"betterstats.stat_type_phrase.morestats.totem_popped_by": "Totems popped by",


"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file": "File",
"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file.new": "New",
"betterstats.api.client.gui.stats.panel.menubarpanel.menu_file.open": "Open",
Expand Down

0 comments on commit 30314ea

Please sign in to comment.