aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsg-programs <msgdoesstuff@gmail.com>2023-05-28 11:46:05 +0200
committermsg-programs <msgdoesstuff@gmail.com>2023-05-28 11:46:05 +0200
commiteeaae397b0000b725e2a1cb63613b28e712a6d68 (patch)
treeef3cdbd65f2420710889af6e6594a5fa33a4b99d
parentb446021b397fd70c98ac6dab595b8df6d026d355 (diff)
downloadSkyblocker-eeaae397b0000b725e2a1cb63613b28e712a6d68.tar.gz
Skyblocker-eeaae397b0000b725e2a1cb63613b28e712a6d68.tar.bz2
Skyblocker-eeaae397b0000b725e2a1cb63613b28e712a6d68.zip
Add javadoc comments to key classes.
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screens/Screen.java27
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/Ico.java3
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java39
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerLocator.java9
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java31
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java3
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java5
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java5
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java5
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java7
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java8
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java9
12 files changed, 120 insertions, 31 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screens/Screen.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screens/Screen.java
index ae71d7bd..cca2ed9e 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screens/Screen.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/screens/Screen.java
@@ -82,10 +82,16 @@ public class Screen {
};
}
+ /**
+ * Add a widget to this screen
+ */
public void addWidget(Widget w) {
widgets.add(w);
}
+ /**
+ * Add many widgets to this screen
+ */
public void addWidgets(Widget... ws) {
for (Widget w : ws) {
widgets.add(w);
@@ -98,6 +104,9 @@ public class Screen {
}
}
+ /**
+ * Stack these widgets on top of each other as determined by the lists's order
+ */
public void stackWidgetsH(Widget... list) {
int compHeight = -5;
for (Widget wid : list) {
@@ -111,6 +120,9 @@ public class Screen {
}
}
+ /**
+ * Arrange these widgets next to each other as determined by the lists's order
+ */
public void stackWidgetsW(Widget... list) {
// TODO not centered
int compWidth = -5;
@@ -125,24 +137,39 @@ public class Screen {
}
}
+ /**
+ * Center a widget vertically, keeping X pos
+ */
public void centerH(Widget wid) {
wid.setY((h - wid.getHeight()) / 2);
}
+ /**
+ * Center a widget horizontally, keeping Y pos
+ */
public void centerW(Widget wid) {
wid.setX((w - wid.getWidth()) / 2);
}
+ /**
+ * Center a widget vertically and horizontally
+ */
public void center(Widget wid) {
this.centerH(wid);
this.centerW(wid);
}
+ /**
+ * Let a widget's left border be on the screen's center, keeping Y pos
+ */
public void offCenterL(Widget wid) {
int wHalf = this.w / 2;
wid.setX(wHalf - 3 - wid.getWidth());
}
+ /**
+ * Let a widget's right border be on the screen's center, keeping Y pos
+ */
public void offCenterR(Widget wid) {
int wHalf = this.w / 2;
wid.setX(wHalf + 3);
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/Ico.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/Ico.java
index 120cabd8..ca767617 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/Ico.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/Ico.java
@@ -3,6 +3,9 @@ package me.xmrvizzy.skyblocker.skyblock.tabhud.util;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
+/**
+ * Stores convenient shorthands for common ItemStack definitions
+ */
public class Ico {
public static final ItemStack MAP = new ItemStack(Items.FILLED_MAP);
public static final ItemStack NTAG = new ItemStack(Items.NAME_TAG);
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java
index 6243415d..2cab4597 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerListMgr.java
@@ -8,12 +8,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import me.xmrvizzy.skyblocker.mixin.PlayerListHudAccessor;
+import me.xmrvizzy.skyblocker.skyblock.tabhud.TabHud;
import me.xmrvizzy.skyblocker.utils.Utils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.text.Text;
+/**
+ * This class may be used to get data from the player list.
+ * It doesn't get its data every frame, instead, a scheduler is used to
+ * update the data this class is holding periodically.
+ * The list is sorted like in the vanilla game.
+ */
public class PlayerListMgr {
public static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Regex");
@@ -28,9 +35,8 @@ public class PlayerListMgr {
ClientPlayNetworkHandler cpnwh = MinecraftClient.getInstance().getNetworkHandler();
- // check is needed, else crash on server leave
+ // check is needed, else game crash on server leave
if (cpnwh != null) {
-
playerList = cpnwh.getPlayerList()
.stream()
.sorted(PlayerListHudAccessor.getOrdering())
@@ -38,9 +44,12 @@ public class PlayerListMgr {
}
}
- // apply pattern to entry at index of player list.
- // return null if there's nothing to match against in the entry,
- // or if the pattern doesn't fully match.
+ /**
+ * Get the display name at some index of the player list and apply a pattern to
+ * it
+ *
+ * @return the matcher if p fully matches, else null
+ */
public static Matcher regexAt(int idx, Pattern p) {
String str = PlayerListMgr.strAt(idx);
@@ -51,15 +60,19 @@ public class PlayerListMgr {
Matcher m = p.matcher(str);
if (!m.matches()) {
- LOGGER.debug("no match: \"{}\" against \"{}\"", str, p);
+ LOGGER.error("no match: \"{}\" against \"{}\"", str, p);
return null;
} else {
return m;
}
}
- // return string (i.e. displayName) at index of player list.
- // return null if string is null, empty or whitespace only.
+ /**
+ * Get the display name at some index of the player list as string
+ *
+ * @return the string or null, if the display name is null, empty or whitespace
+ * only
+ */
public static String strAt(int idx) {
if (playerList == null) {
@@ -81,8 +94,14 @@ public class PlayerListMgr {
return str;
}
- public static PlayerListEntry getRaw(int i) {
- return playerList.get(i);
+ /**
+ * Get the display name at some index of the player list as Text as seen in the
+ * game
+ *
+ * @return the PlayerListEntry at that index
+ */
+ public static PlayerListEntry getRaw(int idx) {
+ return playerList.get(idx);
}
public static int getSize() {
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerLocator.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerLocator.java
index eb8210d9..49d080e2 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerLocator.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/util/PlayerLocator.java
@@ -2,6 +2,9 @@ package me.xmrvizzy.skyblocker.skyblock.tabhud.util;
import me.xmrvizzy.skyblocker.utils.Utils;
+/**
+ * Uses data from the player list to determine the area the player is in.
+ */
public class PlayerLocator {
public static enum Location {
@@ -30,10 +33,6 @@ public class PlayerLocator {
return Location.UNKNOWN;
}
- if (Utils.isInDungeons) {
- return Location.DUNGEON;
- }
-
String areaDesciptor = PlayerListMgr.strAt(41);
if (areaDesciptor == null || areaDesciptor.length() < 6) {
@@ -76,6 +75,8 @@ public class PlayerLocator {
return Location.JERRY;
case "Garden":
return Location.GARDEN;
+ case "Catacombs":
+ return Location.DUNGEON;
default:
return Location.UNKNOWN;
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java
index 23ec15d0..6b96c151 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/Widget.java
@@ -17,6 +17,12 @@ import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
+/**
+ * Abstract base class for a Widget.
+ * Widgets are containers for components with a border and a title.
+ * Their size is dependent on the components inside,
+ * the position may be changed after construction.
+ */
public abstract class Widget {
private ArrayList<Component> components = new ArrayList<>();
@@ -42,11 +48,20 @@ public abstract class Widget {
components.add(c);
}
+ /**
+ * Shorthand function for simple components.
+ * If the entry at idx has the format "<textA>: <textB>", an IcoTextComponent is added as such:
+ * [ico] [string] [textB.formatted(fmt)]
+ */
public final void addSimpleIcoText(ItemStack ico, String string, Formatting fmt, int idx) {
Text txt = Widget.simpleEntryText(idx, string, fmt);
this.addComponent(new IcoTextComponent(ico, txt));
}
+ /**
+ * Calculate the size of this widget.
+ * <b>Must be called before returning from the widget constructor and after all components are added!</b>
+ */
public final void pack() {
for (Component c : components) {
h += c.getHeight() + Component.PAD_L;
@@ -85,10 +100,16 @@ public abstract class Widget {
return this.h;
}
+ /**
+ * Draw this widget with a background
+ */
public final void render(MatrixStack ms) {
this.render(ms, true);
}
+ /**
+ * Draw this widget, possibly with a background
+ */
public final void render(MatrixStack ms, boolean hasBG) {
// not sure if this is the way to go, but it fixes Z-layer issues
@@ -140,6 +161,10 @@ public abstract class Widget {
DrawableHelper.fill(ms, xpos, ypos, xpos + 1, ypos + height, this.color);
}
+ /**
+ * If the entry at idx has the format "[textA]: [textB]", the following is returned:
+ * [entryName] [textB.formatted(contentFmt)]
+ */
public static Text simpleEntryText(int idx, String entryName, Formatting contentFmt) {
String src = PlayerListMgr.strAt(idx);
@@ -157,10 +182,16 @@ public abstract class Widget {
return Widget.simpleEntryText(src, entryName, contentFmt);
}
+ /**
+ * @return [entryName] [entryContent.formatted(contentFmt)]
+ */
public static Text simpleEntryText(String entryContent, String entryName, Formatting contentFmt) {
return Text.literal(entryName).append(Text.literal(entryContent).formatted(contentFmt));
}
+ /**
+ * @return the entry at idx as unformatted Text
+ */
public static Text plainEntryText(int idx) {
String str = PlayerListMgr.strAt(idx);
if (str == null) {
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java
index d9d84bc4..671b1f41 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/Component.java
@@ -5,6 +5,9 @@ import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
+/**
+ * Abstract base class for a component that may be added to a Widget.
+ */
public abstract class Component {
static final int ICO_DIM = 16;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java
index 55d9b889..f845eba5 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoFatTextComponent.java
@@ -6,8 +6,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
-// widget component that consists of an icon and two lines of text
-
+/**
+ * Component that consists of an icon and two lines of text
+ */
public class IcoFatTextComponent extends Component {
private static final int ICO_OFFS = 1;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java
index a14d0531..7a495a13 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/IcoTextComponent.java
@@ -6,8 +6,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
-// widget component that consists of an icon and a line of text
-
+/**
+ * Component that consists of an icon and a line of text.
+ */
public class IcoTextComponent extends Component {
private ItemStack ico;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java
index 70a72715..f356a6a3 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlainTextComponent.java
@@ -4,8 +4,9 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
-// widget component that consists of a line of text
-
+/**
+ * Component that consists of a line of text.
+ */
public class PlainTextComponent extends Component {
private Text text;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java
index ff296f28..18859080 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/PlayerComponent.java
@@ -7,8 +7,9 @@ import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
-// widget component that consists of a player's skin icon and their name
-
+/**
+ * Component that consists of a player's skin icon and their name
+ */
public class PlayerComponent extends Component {
private static final int SKIN_ICO_DIM = 8;
@@ -21,7 +22,7 @@ public class PlayerComponent extends Component {
name = ple.getProfile().getName();
tex = ple.getSkinTexture();
- this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name) ;
+ this.width = SKIN_ICO_DIM + PAD_S + txtRend.getWidth(name);
this.height = txtRend.fontHeight;
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java
index 6aaf9f67..b9ebc0e9 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/ProgressComponent.java
@@ -7,10 +7,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
-// widget component that consists of an icon, some text and a progress bar
-// progress bar either shows percentage or custom text
-// NOTICE: pcnt is 0-100, not 0-1!
+/**
+ * Component that consists of an icon, some text and a progress bar.
+ * The progress bar either shows the fill percentage or custom text.
+ * NOTICE: pcnt is 0-100, not 0-1!
+ */
public class ProgressComponent extends Component {
private static final int BAR_WIDTH = 100;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java
index 5d27380e..5d49be2c 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/tabhud/widget/component/TableComponent.java
@@ -3,11 +3,10 @@ package me.xmrvizzy.skyblocker.skyblock.tabhud.widget.component;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
-// widget component that consists of a grid of other components
-// grid cols are separated by lines
-
-// FIXME: table isn't wide enough sometimes
-// FIXME: dividers drift when there are >2 cols
+/**
+ * Meta-Component that consists of a grid of other components
+ * Grid cols are separated by lines.
+ */
public class TableComponent extends Component {
private Component[][] comps;