Skip to content

Commit

Permalink
More 1.5.0 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jwkerr committed Aug 27, 2023
1 parent 8ea71e9 commit 8331428
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 68 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ You will most likely have some, or all of these dependencies installed if you al

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

Once you have downloaded all the above mods, place them in `.minecraft/mods`, read below for help with that.

### 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.

Expand All @@ -42,13 +44,13 @@ You are free to edit this file as you like, however, it is important that you fo
{
"group": "Friends",
"colour": "GOLD",
"bold": false,
"bold": true,
"italic": false,
"underline": false,
"underline": true,
"strikethrough": false,
"obfuscated": false,
"usernames": [
"Fruitloopins",
"fed0ec4a-f1ad-4b97-9443-876391668b34",
"Uberstrase"
]
}
Expand All @@ -58,6 +60,7 @@ You are free to edit this file as you like, however, it is important that you fo
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
- UUIDs are a valid input for usernames
- "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

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/fwloopins/tabby/Tabby.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public void onInitialize() {

Reload.reload();

LOGGER.info("Tabby initialized");
logInfo("Tabby initialised");
}

public static void logInfo(String msg) {
LOGGER.info("[Tabby] " + msg);
}

public static void logError(String msg) {
LOGGER.error("[Tabby] " + msg);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/fwloopins/tabby/config/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void initFiles() {
Files.copy(json, dir.resolve("groups.json"));
}
} catch (IOException e) {
Tabby.LOGGER.error("Failed to copy groups.json to " + dir, e);
Tabby.logError("Failed to copy groups.json to " + dir + "\n" + e);
}
}

Expand All @@ -40,7 +40,7 @@ public static void cacheJson() {

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

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/fwloopins/tabby/config/TabbyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ public static class Misc {
public String customFooter = "";
@Comment("Keybinding to reload certain Tabby features")
public int reloadKey = GLFW.GLFW_KEY_F9;
@Comment("Set to true to enable specific debug logs\nWill spam logs")
public boolean debug = false;
}
}
68 changes: 48 additions & 20 deletions src/main/java/com/fwloopins/tabby/mixin/TabHighlightMixin.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.fwloopins.tabby.mixin;

import com.fwloopins.tabby.Tabby;
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.MinecraftClient;
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.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -22,9 +26,9 @@

@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"));
@Shadow @Final private MinecraftClient client;
@Unique TabbyConfig config = AutoConfig.getConfigHolder(TabbyConfig.class).getConfig();
@Unique 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) {
Expand All @@ -33,31 +37,55 @@ private void modifyNameColour(CallbackInfoReturnable<MutableText> cir) {

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

for (JsonElement group : jsonArray) {
JsonArray usernamesArray = group.getAsJsonObject().getAsJsonArray("usernames");
String uuid;
try {
uuid = client.player.networkHandler.getPlayerListEntry(name).getProfile().getId().toString();
} catch (NullPointerException e) {
uuid = "";
}

JsonArray jsonArray;
try {
jsonArray = DataManager.getCachedJson().getAsJsonArray();
} catch (Exception e) {
if (config.misc.debug)
Tabby.logError("Failed to read groups.json");

for (JsonElement username : usernamesArray) {
if (username.getAsString().equals(name)) {
JsonObject jsonObject = group.getAsJsonObject();
cir.setReturnValue(text);
return;
}

String colour = jsonObject.get("colour").getAsString();
try {
for (JsonElement group : jsonArray) {
JsonArray usernamesArray = group.getAsJsonObject().getAsJsonArray("usernames");

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();
for (JsonElement username : usernamesArray) {
if (username.getAsString().equals(name) || username.getAsString().equals(uuid)) {
JsonObject jsonObject = group.getAsJsonObject();

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)));
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)));
}
}
}
}
} catch (Exception e) {
if (config.misc.debug)
Tabby.logError("Failed to parse groups.json, likely malformed JSON");

cir.setReturnValue(text);
}
}
}
82 changes: 41 additions & 41 deletions src/main/resources/assets/tabby/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"strikethrough": false,
"obfuscated": false,
"usernames": [
"Fix"
"7395d056-536a-4cf3-9c96-6c7a7df6897a"
]
},
{
Expand All @@ -20,9 +20,9 @@
"strikethrough": false,
"obfuscated": false,
"usernames": [
"1212rah",
"CorruptedGreed",
"KarlOfDuty"
"b4d2215c-e47b-4f39-a3e3-e6726e0bc596",
"f17d77ab-aed4-44e7-96ef-ec9cd473eda3",
"ea798ca9-1192-4334-8ef5-f098bdc9cb39"
]
},
{
Expand All @@ -34,8 +34,8 @@
"strikethrough": false,
"obfuscated": false,
"usernames": [
"Fruitloopins",
"Warriorrr"
"fed0ec4a-f1ad-4b97-9443-876391668b34",
"e25ad129-fe8a-4306-b1af-1dee1ff59841"
]
},
{
Expand All @@ -47,9 +47,9 @@
"strikethrough": false,
"obfuscated": false,
"usernames": [
"Proser",
"PolkadotBlueBear",
"WTDpuddles"
"8f90a970-90de-407d-b4e7-0d9fde10f51a",
"7b589f55-c5e2-41b7-89fc-13eb8781058e",
"96d55845-c99f-447d-923d-1e652ab50bb1"
]
},
{
Expand All @@ -61,32 +61,32 @@
"strikethrough": false,
"obfuscated": false,
"usernames": [
"32Andrew",
"__Zlatan__",
"aas5aa_OvO",
"Aehmett",
"linkeron1",
"Barbay1",
"BigshotWarrior",
"Coblobster",
"earlgreyteabag",
"girlygirlfiji",
"fabinostalgia",
"Gris_",
"KeijoDPutt",
"Knowlton",
"Mednis",
"Masrain",
"Professor__Pro",
"RAWRyoutube",
"RlZ58",
"ShindoiASU",
"SuperHappyBros",
"wishful_",
"XxSlayerMCxX",
"yellune",
"Shia_chan",
"Superaktif"
"7f551e7c-082c-4533-b484-7435d9941d0d",
"bae75988-00f4-41ce-b902-abc21fcb8978",
"d32c9786-17e6-43a2-8f83-8f95a6655893",
"c14bb5d7-6d51-4e3f-a388-36d6a5992272",
"9d3857a7-9fb7-4232-ae5e-c66d6ca1f621",
"ad978482-b062-472b-a168-4d317af0f72a",
"94a4c5ea-027f-4509-a434-66320c29948a",
"16b5a2e4-04a3-40f7-8311-4bffeccd23ba",
"0b992c62-587d-45ea-8821-4f3b39bb6cc4",
"0bacd488-bc41-4f76-ba8b-50dc843efe49",
"2bf8f573-f2e8-4d2c-b1e9-072bf052722a",
"2de5dbaa-27aa-4c1a-82f6-65f4ed966592",
"a77418cd-b9a0-4f0d-9c77-ab799ef71ac4",
"376d4c35-7ffb-480b-9bd3-bc1ef1bd09f7",
"379f1b2b-0b53-4ea4-b0b2-14b6e4777983",
"ea0c4d98-106d-416c-9647-06203f861e1b",
"479d37aa-229f-41a4-a49f-784c29e1fe65",
"a87996b7-243a-40ec-af03-f7604a5ae97b",
"25c9762f-df85-45d2-8edd-be83c09eec34",
"7a9da17c-834d-4f45-b4ce-07ea04274a12",
"9449b781-a702-484a-934d-9ed351bcebd4",
"0c16f3f8-59c2-413e-9327-8f4b1f7f44cf",
"7f235a6f-2988-4967-ba5d-adbe2781728f",
"a82437de-882d-43c2-9e12-3355e8783c9d",
"3947e217-95ae-4952-93b7-6b4004b54f40",
"ad0a2de0-1e73-401d-967c-f5b155dc6ad1"
]
},
{
Expand All @@ -98,12 +98,12 @@
"strikethrough": false,
"obfuscated": false,
"usernames": [
"32Breach",
"Creightor",
"dopecello",
"Lion_Of_Judah12",
"Lucas2011",
"Unbated"
"c99d4771-f844-4eff-b2ac-aee086d15bbe",
"19c5aede-d9af-4234-9a21-b956ae99b0ba",
"c200e96f-834e-40b7-81d5-e27fd3107ecd",
"2cbaad0b-ed5b-453e-a6b0-ec4b88ca43cd",
"4452780b-034d-4d46-b427-717ce3f5acda",
"0ef76084-7c86-4115-b1a5-a9c4e9bc89a6"
]
}
]
3 changes: 2 additions & 1 deletion src/main/resources/assets/tabby/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"text.autoconfig.Tabby.option.misc.customColours": "Custom Colours",
"text.autoconfig.Tabby.option.misc.customHeader": "Custom Header",
"text.autoconfig.Tabby.option.misc.customFooter": "Custom Footer",
"text.autoconfig.Tabby.option.misc.reloadKey": "Reload Key"
"text.autoconfig.Tabby.option.misc.reloadKey": "Reload Key",
"text.autoconfig.Tabby.option.misc.debug": "Debug"
}

0 comments on commit 8331428

Please sign in to comment.