-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor + nullification/changing of header and footer option
- Loading branch information
Showing
6 changed files
with
127 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/fwloopins/tabby/mixin/HighlightMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.fwloopins.tabby.mixin; | ||
|
||
import com.fwloopins.tabby.config.TabbyConfig; | ||
import me.shedaniel.autoconfig.AutoConfig; | ||
import net.minecraft.client.gui.hud.PlayerListHud; | ||
import net.minecraft.text.MutableText; | ||
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 HighlightMixin { | ||
@Unique | ||
TabbyConfig config = AutoConfig.getConfigHolder(TabbyConfig.class).getConfig(); | ||
|
||
// 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())); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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.Text; | ||
import org.jetbrains.annotations.Nullable; | ||
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 java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Mixin(PlayerListHud.class) | ||
public abstract class TabSizeMixin { | ||
@Shadow @Final private MinecraftClient client; | ||
@Shadow public abstract void setFooter(@Nullable Text footer); | ||
|
||
@Shadow public abstract void setHeader(@Nullable Text header); | ||
|
||
@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) { | ||
setHeaderAndFooter(); | ||
|
||
if (!config.general.adaptive) | ||
return Math.max(1, config.general.maxRows); | ||
|
||
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); | ||
} | ||
|
||
@Unique | ||
private void setHeaderAndFooter() { | ||
if (!config.general.customHeader.isEmpty()) { | ||
if (config.general.customHeader.equals("null")) { | ||
setHeader(null); | ||
} else { | ||
setHeader(Text.of(config.general.customHeader)); | ||
} | ||
} | ||
|
||
if (!config.general.customFooter.isEmpty()) { | ||
if (config.general.customFooter.equals("null")) { | ||
setFooter(null); | ||
} else { | ||
setFooter(Text.of(config.general.customFooter)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters