Skip to content

Commit

Permalink
Beta v3.0.0-beta.2
Browse files Browse the repository at this point in the history
The statistics HUD is semi-ready. You are able to add and remove entries, but there's no feature for "live" HUD stat updates yet. Once that is done, the release will be finished. Also the "Done" button on the HUD screen is missing for now.
  • Loading branch information
TheCSDev committed Sep 28, 2023
1 parent ddd942e commit 1dd5264
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 16 deletions.
4 changes: 2 additions & 2 deletions betterstats-3-fabric-1.20.1/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ org.gradle.jvmargs=-Xmx1G
mod_name = Better Statistics Screen
mod_description = Improves the statistics screen and makes it more useful.
mod_author = TheCSDev
mod_version = 3.0.0+fabric-1.20.1
mod_version = 3.0.0-beta.2+fabric-1.20.1

mod_contact_homepage = https://github.com/TheCSMods
mod_contact_sources = https://github.com/TheCSMods/mc-better-stats
Expand All @@ -38,7 +38,7 @@ org.gradle.jvmargs=-Xmx1G
mod_depends_minecraft = >=1.20
mod_depends_java = >=17

mod_jar_tcdcommons = META-INF/jarjar/tcdcommons-3.0.0+fabric-1.20.1.jar
mod_jar_tcdcommons = META-INF/jarjar/tcdcommons-3.0.0-beta.2+fabric-1.20.1.jar

pack_mcmeta_format = 15

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thecsdev.betterstats.api.client.gui.screen;

import static io.github.thecsdev.betterstats.client.BetterStatsClient.MC_CLIENT;
import static io.github.thecsdev.betterstats.client.gui.stats.panel.StatsTabPanel.FILTER_ID_SCROLL_CACHE;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;

Expand All @@ -24,8 +25,11 @@
import io.github.thecsdev.tcdcommons.api.client.util.interfaces.IParentScreenProvider;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.ItemGroups;
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket.Mode;
import net.minecraft.resource.featuretoggle.FeatureFlags;
import net.minecraft.resource.featuretoggle.FeatureSet;

/**
* The main focal point of this mod.<br/>
Expand Down Expand Up @@ -79,6 +83,13 @@ public BetterStatsScreen(@Nullable Screen parent, IStatsProvider statsProvider)
// --------------------------------------------------
protected final @Override void onOpened()
{
//update item groups display context
if(MC_CLIENT.world != null)
ItemGroups.updateDisplayContext(
FeatureSet.of(FeatureFlags.VANILLA),
true,
MC_CLIENT.world.getRegistryManager());

//do not send a statistics request packet if not viewing one's own stats
if(this.statsProvider != LocalPlayerStatsProvider.getInstance())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.stat.Stat;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand All @@ -23,14 +24,14 @@
public abstract @Internal class SUStat<T> extends Object
{
// ==================================================
protected final IStatsProvider statProvider;
protected final IStatsProvider statsProvider;
protected final Identifier statId;
protected final Text statLabel;
protected final String statLabelSQ, statIdSQ; //"search query" helpers
// ==================================================
protected SUStat(IStatsProvider statsProvider, Identifier statId, Text statLabel) throws NullPointerException
{
this.statProvider = Objects.requireNonNull(statsProvider);
this.statsProvider = Objects.requireNonNull(statsProvider);
this.statId = Objects.requireNonNull(statId);
this.statLabel = Objects.requireNonNull(statLabel);

Expand All @@ -51,6 +52,11 @@ protected SUStat(IStatsProvider statsProvider, Identifier statId, Text statLabel
* for {@link SUMobStat}, refers to {@link EntityType}'s {@link Identifier}.
*/
public final Identifier getStatID() { return this.statId; }

/**
* Returns the {@link IStatsProvider} the {@link Stats} data was obtained from.
*/
public final IStatsProvider getStatsProvider() { return this.statsProvider; }
// --------------------------------------------------
/**
* Checks if this {@link SUStat}'s {@link #statLabel} matches a given "search query".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import org.jetbrains.annotations.Nullable;

import io.github.thecsdev.betterstats.BetterStats;
import io.github.thecsdev.tcdcommons.api.client.gui.screen.TScreenWrapper;
import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen;
import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext;
import io.github.thecsdev.tcdcommons.api.client.util.interfaces.IParentScreenProvider;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket.Mode;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand All @@ -24,8 +28,28 @@ public final class BetterStatsHudScreen extends TWidgetHudScreen implements IPar
private static final BetterStatsHudScreen INSTANCE = new BetterStatsHudScreen();
// --------------------------------------------------
private @Nullable Screen parent;
//
private float requestTimer = 0;
private final int requestDelay = 100;
// ==================================================
private BetterStatsHudScreen() { super(TEXT_TITLE, HUD_SCREEN_ID); }
// --------------------------------------------------
protected final @Override TScreenWrapper<?> createScreenWrapper() { return new BetterStatsHudScreenWrapper(this); }
// ==================================================
public final @Override void render(TDrawContext pencil)
{
//render super
super.render(pencil);

//handle auto-requesting
if(this.client == null || isOpen()) return; //don't auto-request during user setup
this.requestTimer += pencil.deltaTime;
if(this.requestTimer > this.requestDelay)
{
this.requestTimer = 0;
this.client.getNetworkHandler().sendPacket(new ClientStatusC2SPacket(Mode.REQUEST_STATS));
}
}
// ==================================================
/**
* Returns the current instance of {@link BetterStatsHudScreen}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.thecsdev.betterstats.client.gui.screen.hud;

import org.jetbrains.annotations.ApiStatus.Internal;

import io.github.thecsdev.tcdcommons.api.client.gui.screen.TScreenWrapper;
import net.minecraft.client.gui.screen.StatsListener;

@Internal class BetterStatsHudScreenWrapper extends TScreenWrapper<BetterStatsHudScreen> implements StatsListener
{
// ==================================================
public BetterStatsHudScreenWrapper(BetterStatsHudScreen target) { super(target); }
// --------------------------------------------------
public final @Override void onStatsReady() { this.target.refresh(); }
// ==================================================
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.CustomStatElement;
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget;
import io.github.thecsdev.betterstats.api.util.enumerations.ItemStatType;
import io.github.thecsdev.betterstats.api.util.io.IStatsProvider;
import io.github.thecsdev.betterstats.api.util.stats.SUItemStat;
import io.github.thecsdev.tcdcommons.api.client.gui.TElement;
import io.github.thecsdev.tcdcommons.api.client.gui.panel.TPanelElement;
import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen;
import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext;
import net.minecraft.item.Item;
import net.minecraft.text.Text;

public final class StatsHudItemEntry extends TWidgetHudScreen.WidgetEntry<TElement>
{
// ==================================================
static final int WIDTH = 150;
// --------------------------------------------------
protected final SUItemStat stat;
protected final IStatsProvider statsProvider;
protected final Item item;
protected ItemStatType mode = ItemStatType.MINED;
// ==================================================
public StatsHudItemEntry(SUItemStat stat) throws NullPointerException
public StatsHudItemEntry(SUItemStat stat) throws NullPointerException { this(stat.getStatsProvider(), stat.getItem()); }
public StatsHudItemEntry(IStatsProvider statsProvider, Item item) throws NullPointerException
{
super(0.5, 0.25);
this.stat = Objects.requireNonNull(stat);
this.statsProvider = Objects.requireNonNull(statsProvider);
this.item = Objects.requireNonNull(item);
}
// ==================================================
public final @Override TElement createWidget()
Expand All @@ -50,12 +55,12 @@ public StatsHudItemEntry(SUItemStat stat) throws NullPointerException
return el;
}
// --------------------------------------------------
private final CustomStatElement createCustomStatElement()
private final CustomStatElement createCustomStatElement(SUItemStat stat)
{
//collect info
final int i = ItemStatWidget.SIZE;
@Nullable Text left = this.mode.getText();
@Nullable Text right = literal(Integer.toString(this.mode.getStatValue(this.stat)));
@Nullable Text right = literal(Integer.toString(this.mode.getStatValue(stat)));
//create and return
return new CustomStatElement(i, 0, WIDTH - i, left, right);
}
Expand All @@ -65,8 +70,9 @@ private final class Element extends TElement
public Element()
{
super(0, 0, WIDTH, CustomStatElement.HEIGHT);
final var stat = new SUItemStat(StatsHudItemEntry.this.statsProvider, StatsHudItemEntry.this.item);
addChild(new ItemStatWidget(0, 0, stat), true);
addChild(createCustomStatElement(), true);
addChild(createCustomStatElement(stat), true);
}
public @Override void render(TDrawContext pencil) { pencil.drawTFill(TPanelElement.COLOR_BACKGROUND); }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget;
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget;
import io.github.thecsdev.betterstats.api.util.enumerations.MobStatType;
import io.github.thecsdev.betterstats.api.util.io.IStatsProvider;
import io.github.thecsdev.betterstats.api.util.stats.SUMobStat;
import io.github.thecsdev.tcdcommons.api.client.gui.TElement;
import io.github.thecsdev.tcdcommons.api.client.gui.panel.TPanelElement;
import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen;
import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext;
import net.minecraft.entity.EntityType;
import net.minecraft.text.Text;

public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry<TElement>
{
// ==================================================
static final int WIDTH = StatsHudItemEntry.WIDTH;
// --------------------------------------------------
protected final SUMobStat stat;
protected final IStatsProvider statsProvider;
protected final EntityType<?> entityType;
protected MobStatType mode = MobStatType.KILLED;
// ==================================================
public StatsHudMobEntry(SUMobStat stat) throws NullPointerException
public StatsHudMobEntry(SUMobStat stat) throws NullPointerException { this(stat.getStatsProvider(), stat.getEntityType()); }
public StatsHudMobEntry(IStatsProvider statsProvider, EntityType<?> entityType) throws NullPointerException
{
super(0.5, 0.25);
this.stat = Objects.requireNonNull(stat);
this.statsProvider = Objects.requireNonNull(statsProvider);
this.entityType = Objects.requireNonNull(entityType);
}
// ==================================================
public final @Override TElement createWidget()
Expand All @@ -51,12 +56,12 @@ public StatsHudMobEntry(SUMobStat stat) throws NullPointerException
return el;
}
// --------------------------------------------------
private final CustomStatElement createCustomStatElement()
private final CustomStatElement createCustomStatElement(SUMobStat stat)
{
//collect info
final int i = ItemStatWidget.SIZE;
@Nullable Text left = this.mode.getText();
@Nullable Text right = literal(Integer.toString(this.mode.getStatValue(this.stat)));
@Nullable Text right = literal(Integer.toString(this.mode.getStatValue(stat)));
//create and return
return new CustomStatElement(i, 0, WIDTH - i, left, right);
}
Expand All @@ -67,11 +72,12 @@ public Element()
{
super(0, 0, WIDTH, CustomStatElement.HEIGHT);

final var stat = new SUMobStat(StatsHudMobEntry.this.statsProvider, StatsHudMobEntry.this.entityType);
final var ms = new MobStatWidget(0, 0, stat);
ms.setSize(this.height, this.height);

addChild(ms, true);
addChild(createCustomStatElement(), true);
addChild(createCustomStatElement(stat), true);
}
public @Override void render(TDrawContext pencil) { pencil.drawTFill(TPanelElement.COLOR_BACKGROUND); }
}
Expand Down
Binary file not shown.

0 comments on commit 1dd5264

Please sign in to comment.