Skip to content

Commit

Permalink
1.5.0 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jwkerr committed Aug 26, 2023
1 parent 0089860 commit 8ab2d7b
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 140 deletions.
66 changes: 63 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
<p align="center">
<img src="src/main/resources/assets/tabby/img/Tabby.gif" alt="Tabby" width="10%" height="10%">

---

# Tabby
A Minecraft Fabric mod that extends the "player list" that is shown when holding tab
Tabby is a highly customisable Fabric mod for Minecraft that adds extra utility to the tab list.

Tabby adds many utilities to the tab list such as:
- Configurable settings to change the amount of players shown and the amount of rows
- A highly configurable file to define groups of name colours and formats, full RGB and Minecraft formatting, read [here](#groups-config) for setup help
- Option to remove or change the headers and footers on tab, no more obnoxious advertising

Join my Discord at https://discord.gg/ey6ZvnwAJp for support and discussion.

<img src="src/main/resources/assets/tabby/img/Tabby.png" alt="Tabby" width="75%" height="75%">

## Installation
Download the mod from [here](https://github.com/Fruitloopins/Tabby/releases/latest)

Additionally, this mod requires:
- [Cloth Config API](https://modrinth.com/mod/cloth-config)
- [Fabric API](https://modrinth.com/mod/fabric-api)
- and optionally (highly recommended) [Mod Menu](https://modrinth.com/mod/modmenu) to view the config

You will most likely have some, or all of these dependencies installed if you already use Fabric mods.

If you have never used or installed Fabric before, learn how to install it [here](https://fabricmc.net/wiki/install)

### Navigating to .minecraft
Read [here](https://minecraft.fandom.com/wiki/.minecraft#Locating_.minecraft) for a guide for your OS on how to do navigate to the .minecraft directory.

## Groups Config
> Launch Minecraft with Tabby installed before following this guide to create the relevant files
If you would like to customise the formatting of specific usernames in tab, you must navigate to your ".minecraft" folder, read [here](#navigating-to-minecraft) for help with that. There is regrettably no in-game editor for this functionality as of now.

Once you have reached the .minecraft directory, navigate to `.minecraft/config/Tabby`. You will find that there is already a file here named "groups.json", the groups defined by default in this file are staff of the server I develop for, EarthMC.

You are free to edit this file as you like, however, it is important that you follow the structure I have laid out. Below is an example of the "bare minimum":
```json
[
{
"group": "Friends",
"colour": "GOLD",
"bold": false,
"italic": false,
"underline": false,
"strikethrough": false,
"obfuscated": false,
"usernames": [
"Fruitloopins",
"Uberstrase"
]
}
]
```

If you don't understand what you are doing when editing this file you should just replace the default values I have already put there rather than attempting to start from scratch. If you have made an irreparable mistake you can delete the file or folder and restart your client to re-initialise the file.

- "group" can be any string you like
- "colour" can be any of the colours listed [here](https://www.digminecraft.com/lists/color_list_pc.php) i.e. BLACK, DARK_AQUA, RED etc. or you can choose a hexadecimal number, i.e. 4A412A
- All boolean values (bold-obfuscated) must be present even if you are not setting them to true

This mod requires Cloth Config API, Fabric API and Mod Menu to view the config. Join my Discord at https://discord.gg/ey6ZvnwAJp for support and discussion.
![2023-04-23_06 47 15](https://user-images.githubusercontent.com/49851457/233806357-9169f9f4-f63a-483e-ad25-df73d26ee531.png)
You can define as many groups as you like. If you make changes while in-game, you can press F9 to reload them on the fly. This is due to the JSON being cached to prevent lag.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ org.gradle.parallel=true
loader_version=0.14.21

# Mod Properties
mod_version = 1.4.0
maven_group = net.xbyz
mod_version = 1.5.0
maven_group = com.fwloopins
archives_base_name = tabby-1.20.1

# Dependencies
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/fwloopins/tabby/Tabby.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.fwloopins.tabby;

import com.fwloopins.tabby.config.TabbyConfig;
import com.fwloopins.tabby.config.DataManager;
import com.fwloopins.tabby.misc.Reload;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
import net.fabricmc.api.ModInitializer;
Expand All @@ -14,6 +16,11 @@ public class Tabby implements ModInitializer {
public void onInitialize() {
AutoConfig.register(TabbyConfig.class, GsonConfigSerializer::new);

DataManager.initFiles();
DataManager.cacheJson();

Reload.reload();

LOGGER.info("Tabby initialized");
}
}
50 changes: 50 additions & 0 deletions src/main/java/com/fwloopins/tabby/config/DataManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fwloopins.tabby.config;

import com.fwloopins.tabby.Tabby;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import net.fabricmc.loader.api.FabricLoader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public class DataManager {
private static JsonArray cachedJson = null;

public static void initFiles() {
Path dir = FabricLoader.getInstance().getConfigDir().resolve("Tabby");

try {
if (!Files.exists(dir.resolve("groups.json"))) {
InputStream json = DataManager.class.getClassLoader().getResourceAsStream("assets/tabby/groups.json");

if (!Files.exists(dir))
Files.createDirectory(dir);

Files.copy(json, dir.resolve("groups.json"));
}
} catch (IOException e) {
Tabby.LOGGER.error("Failed to copy groups.json to " + dir, e);
}
}

public static void cacheJson() {
try {
BufferedReader reader = Files.newBufferedReader(FabricLoader.getInstance().getConfigDir().resolve("Tabby/groups.json"), StandardCharsets.UTF_8);
JsonElement element = JsonParser.parseReader(reader);

cachedJson = element.getAsJsonArray();
} catch (IOException e) {
Tabby.LOGGER.error("Failed to read groups.json", e);
}
}

public static JsonArray getCachedJson() {
return cachedJson;
}
}
38 changes: 10 additions & 28 deletions src/main/java/com/fwloopins/tabby/config/TabbyConfig.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.fwloopins.tabby.config;

import com.fwloopins.tabby.object.Colours;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment;
import org.lwjgl.glfw.GLFW;

@me.shedaniel.autoconfig.annotation.Config(name = "Tabby")
public class TabbyConfig implements ConfigData {
@ConfigEntry.Category("General")
@ConfigEntry.Gui.TransitiveObject
public General general = new General();

@ConfigEntry.Category("Colour")
@ConfigEntry.Category("Misc")
@ConfigEntry.Gui.TransitiveObject
public Colour colour = new Colour();
public Misc misc = new Misc();

public static class General {
@Comment("The maximum players that can be rendered, set to 0 for the max to always be the current online player count")
Expand All @@ -26,34 +26,16 @@ public static class General {
@ConfigEntry.BoundedDiscrete(min = 1, max = 10)
@Comment("The amount to divide the players online by to determine how many rows will be rendered when adaptive is set to true\nFormula: x / y = maxRows\nWhere x is the value of maxCount and y is the adaptiveDivisor value")
public int adaptiveDivisor = 5;
}

public static class Misc {
@Comment("Set to true to enable custom highlight colours for specific names in tab\nEdit this at .minecraft/config/Tabby/groups.json")
public boolean customColours = true;
@Comment("Change header to a custom string, leave blank for no change, write null for nothing to be rendered")
public String customHeader = "";
@Comment("Change footer to a custom string, leave blank for no change, write null for nothing to be rendered")
public String customFooter = "";
}

public static class Colour {
@Comment("Set to true to enable custom highlight colours for specific names in tab\nThis feature is currently hacked together and experimental")
public boolean customColours = false;
@Comment("List of names separated by a space for first colour choice")
public String namesOne = "Fruitloopins";
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN)
@Comment("Highlight colour for first list of names")
public Colours highlightColourOne = Colours.GOLD;
@Comment("List of names separated by a space for second colour choice")
public String namesTwo = "";
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN)
@Comment("Highlight colour for second list of names")
public Colours highlightColourTwo = Colours.DARK_RED;
@Comment("List of names separated by a space for third colour choice")
public String namesThree = "";
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN)
@Comment("Highlight colour for third list of names")
public Colours highlightColourThree = Colours.DARK_GREEN;
@Comment("List of names separated by a space for fourth colour choice")
public String namesFour = "";
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN)
@Comment("Highlight colour for fourth list of names")
public Colours highlightColourFour = Colours.DARK_BLUE;
@Comment("Keybinding to reload certain Tabby features")
public int reloadKey = GLFW.GLFW_KEY_F9;
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/fwloopins/tabby/misc/Reload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.fwloopins.tabby.misc;

import com.fwloopins.tabby.config.DataManager;
import com.fwloopins.tabby.config.TabbyConfig;
import me.shedaniel.autoconfig.AutoConfig;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

public class Reload {
static TabbyConfig config = AutoConfig.getConfigHolder(TabbyConfig.class).getConfig();

public static void reload() {
KeyBinding reloadBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.reload",
InputUtil.Type.KEYSYM,
config.misc.reloadKey,
"category.tabby"
));

ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (reloadBinding.wasPressed()) {
DataManager.cacheJson();
}
});
}
}
47 changes: 0 additions & 47 deletions src/main/java/com/fwloopins/tabby/mixin/HighlightMixin.java

This file was deleted.

63 changes: 63 additions & 0 deletions src/main/java/com/fwloopins/tabby/mixin/TabHighlightMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.fwloopins.tabby.mixin;

import com.fwloopins.tabby.config.DataManager;
import com.fwloopins.tabby.config.TabbyConfig;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.shedaniel.autoconfig.AutoConfig;
import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.util.Formatting;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Mixin(PlayerListHud.class)
public class TabHighlightMixin {
@Unique
TabbyConfig config = AutoConfig.getConfigHolder(TabbyConfig.class).getConfig();
final List<String> colours = new ArrayList<>(Arrays.asList("DARK_RED", "RED", "GOLD", "YELLOW", "DARK_GREEN", "GREEN", "AQUA", "DARK_AQUA", "DARK_BLUE", "BLUE", "LIGHT_PURPLE", "DARK_PURPLE", "WHITE", "GRAY", "DARK_GRAY", "BLACK"));

@Inject(method = "applyGameModeFormatting", at = @At("RETURN"), cancellable = true)
private void modifyNameColour(CallbackInfoReturnable<MutableText> cir) {
if (!config.misc.customColours)
return;

MutableText text = cir.getReturnValue();
String name = text.getString();
JsonArray jsonArray = DataManager.getCachedJson().getAsJsonArray();

for (JsonElement group : jsonArray) {
JsonArray usernamesArray = group.getAsJsonObject().getAsJsonArray("usernames");

for (JsonElement username : usernamesArray) {
if (username.getAsString().equals(name)) {
JsonObject jsonObject = group.getAsJsonObject();

String colour = jsonObject.get("colour").getAsString();

boolean bold = jsonObject.get("bold").getAsBoolean();
boolean italic = jsonObject.get("italic").getAsBoolean();
boolean underline = jsonObject.get("underline").getAsBoolean();
boolean strikethrough = jsonObject.get("strikethrough").getAsBoolean();
boolean obfuscated = jsonObject.get("obfuscated").getAsBoolean();

if (colours.contains(colour)) {
cir.setReturnValue(text.setStyle(Style.EMPTY.withColor(Formatting.byName(colour)).withBold(bold).withItalic(italic).withUnderline(underline).withStrikethrough(strikethrough).withObfuscated(obfuscated)));
} else {
int rgb = Integer.parseInt(colour, 16);
cir.setReturnValue(text.setStyle(Style.EMPTY.withColor(rgb).withBold(bold).withItalic(italic).withUnderline(underline).withStrikethrough(strikethrough).withObfuscated(obfuscated)));
}
}
}
}
}
}
Loading

0 comments on commit 8ab2d7b

Please sign in to comment.