Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Hacky name highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
jwkerr committed Aug 26, 2023
1 parent 33e3394 commit f0e0698
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 55 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.parallel=true
loader_version=0.14.21

# Mod Properties
mod_version = 1.3.3
mod_version = 1.4.0
maven_group = net.xbyz
archives_base_name = tabby-1.20.1

Expand Down
58 changes: 47 additions & 11 deletions src/main/java/com/fwloopins/tabby/config/TabbyConfig.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
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;

@me.shedaniel.autoconfig.annotation.Config(name = "Tabby")
public class TabbyConfig implements ConfigData {
@Comment("The maximum players that can be rendered, set to 0 for the max to always be the current online player count")
public long maxCount = 0L;
@ConfigEntry.BoundedDiscrete(min = 1, max = 100)
@Comment("The maximum rows that can be rendered, this value is not used if adaptive is set to true")
public int maxRows = 40;
@Comment("Set to true for the amount of rows to adapt based off how many players there are")
public boolean adaptive = false;
@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;
}
@ConfigEntry.Category("General")
@ConfigEntry.Gui.TransitiveObject
public General general = new General();

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

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")
public long maxCount = 0L;
@ConfigEntry.BoundedDiscrete(min = 1, max = 100)
@Comment("The maximum rows that can be rendered, this value is not used if adaptive is set to true")
public int maxRows = 40;
@Comment("Set to true for the amount of rows to adapt based off how many players there are")
public boolean adaptive = false;
@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 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;
}
}
70 changes: 70 additions & 0 deletions src/main/java/com/fwloopins/tabby/mixin/TabMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.fwloopins.tabby.mixin;

import com.fwloopins.tabby.config.TabbyConfig;
import me.shedaniel.autoconfig.AutoConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.text.MutableText;
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.*;
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 TabMixin {
@Shadow @Final private MinecraftClient client;
@Unique
TabbyConfig config = AutoConfig.getConfigHolder(TabbyConfig.class).getConfig();

@ModifyConstant(constant = @Constant(longValue = 80L), method = "collectPlayerEntries")
private long modifyCount(long count) {
if (config.general.maxCount <= 0) {
return client.player.networkHandler.getListedPlayerListEntries().size();
}
return config.general.maxCount;
}

@ModifyConstant(constant = @Constant(intValue = 20), method = "render")
private int modifyMaxRows(int MAX_ROWS) {
if (config.general.adaptive) {
if (config.general.maxCount <= 0) {
int onlinePlayers = client.player.networkHandler.getListedPlayerListEntries().size();
return Math.max(1, onlinePlayers / config.general.adaptiveDivisor);
}
return (int) Math.max(1, config.general.maxCount / config.general.adaptiveDivisor);
}
return Math.max(1, config.general.maxRows);
}

// Hacky clusterfuck
@Inject(method = "applyGameModeFormatting", at = @At("RETURN"), cancellable = true)
private void modifyNameColour(CallbackInfoReturnable<MutableText> cir) {
if (config.colour.customColours) {
MutableText text = cir.getReturnValue();
String[] splitOne = config.colour.namesOne.split(" ");
String[] splitTwo = config.colour.namesTwo.split(" ");
String[] splitThree = config.colour.namesThree.split(" ");
String[] splitFour = config.colour.namesFour.split(" ");
List<String> nameListOne = new ArrayList<>(Arrays.asList(splitOne));
List<String> nameListTwo = new ArrayList<>(Arrays.asList(splitTwo));
List<String> nameListThree = new ArrayList<>(Arrays.asList(splitThree));
List<String> nameListFour = new ArrayList<>(Arrays.asList(splitFour));

if (nameListOne.contains(text.getString())) {
cir.setReturnValue(text.formatted(config.colour.highlightColourOne.formatting()));
} else if (nameListTwo.contains(text.getString())) {
cir.setReturnValue(text.formatted(config.colour.highlightColourTwo.formatting()));
} else if (nameListThree.contains(text.getString())) {
cir.setReturnValue(text.formatted(config.colour.highlightColourThree.formatting()));
} else if (nameListFour.contains(text.getString())) {
cir.setReturnValue(text.formatted(config.colour.highlightColourFour.formatting()));
}
}
}
}
38 changes: 0 additions & 38 deletions src/main/java/com/fwloopins/tabby/mixin/TabSizeMixin.java

This file was deleted.

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

import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;

public enum Colours {
DARK_RED(Formatting.DARK_RED),
RED(Formatting.RED),
GOLD(Formatting.GOLD),
YELLOW(Formatting.YELLOW),
DARK_GREEN(Formatting.DARK_GREEN),
GREEN(Formatting.GREEN),
AQUA(Formatting.AQUA),
DARK_AQUA(Formatting.DARK_AQUA),
DARK_BLUE(Formatting.DARK_BLUE),
BLUE(Formatting.BLUE),
LIGHT_PURPLE(Formatting.LIGHT_PURPLE),
DARK_PURPLE(Formatting.DARK_PURPLE),
WHITE(Formatting.WHITE),
GRAY(Formatting.GRAY),
DARK_GRAY(Formatting.DARK_GRAY),
BLACK(Formatting.BLACK);

private final Formatting formatting;

Colours(Formatting formatting) {
this.formatting = formatting;
}

@NotNull
public Formatting formatting() {
return this.formatting;
}
}
21 changes: 17 additions & 4 deletions src/main/resources/assets/tabby/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
{
"text.autoconfig.Tabby.title": "Tabby Config",
"text.autoconfig.Tabby.option.maxCount": "Max Count",
"text.autoconfig.Tabby.option.maxRows": "Max Rows",
"text.autoconfig.Tabby.option.adaptive": "Adaptive",
"text.autoconfig.Tabby.option.adaptiveDivisor": "Adaptive Divisor"

"text.autoconfig.Tabby.category.General": "General",
"text.autoconfig.Tabby.option.general.maxCount": "Max Count",
"text.autoconfig.Tabby.option.general.maxRows": "Max Rows",
"text.autoconfig.Tabby.option.general.adaptive": "Adaptive",
"text.autoconfig.Tabby.option.general.adaptiveDivisor": "Adaptive Divisor",

"text.autoconfig.Tabby.category.Colour": "Colour",
"text.autoconfig.Tabby.option.colour.customColours": "Custom colours",
"text.autoconfig.Tabby.option.colour.namesOne": "First list of names",
"text.autoconfig.Tabby.option.colour.highlightColourOne": "First list's colour",
"text.autoconfig.Tabby.option.colour.namesTwo": "Second list of names",
"text.autoconfig.Tabby.option.colour.highlightColourTwo": "Second list's colour",
"text.autoconfig.Tabby.option.colour.namesThree": "Third list of names",
"text.autoconfig.Tabby.option.colour.highlightColourThree": "Third list's colour",
"text.autoconfig.Tabby.option.colour.namesFour": "Fourth list of names",
"text.autoconfig.Tabby.option.colour.highlightColourFour": "Fourth list's colour"
}
2 changes: 1 addition & 1 deletion src/main/resources/tabby.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"mixins": [
],
"client": [
"TabSizeMixin"
"TabMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit f0e0698

Please sign in to comment.