add template for injekting playerTags

This commit is contained in:
Hiajen Hiajen 2021-06-20 11:53:58 +02:00
parent 2cb319c065
commit 07dd923927
4 changed files with 40 additions and 48 deletions

View file

@ -1,21 +1,20 @@
package net.saltymc.eaa.commands; package net.saltymc.eaa.commands;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.toast.SystemToast; import net.minecraft.client.toast.SystemToast;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.saltymc.eaa.custom.ping.PingColors;
import net.saltymc.eaa.util.database.DB_Player; import net.saltymc.eaa.util.database.DB_Player;
import net.saltymc.eaa.util.database.DB_Tag; import net.saltymc.eaa.util.database.DB_Tag;
import net.saltymc.eaa.util.mojangApi.PlayerInfo; import net.saltymc.eaa.util.mojangApi.PlayerInfo;
import java.util.Collection;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal; import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal;
@ -61,4 +60,30 @@ public class TagCommand extends EaaModCommand{
.executes(this) .executes(this)
))); )));
} }
public static CustomText getScoreboardTag(String uuid){
return new CustomText(Text.of("[NaN]"), PingColors.COLOR_GREY);
}
public static class CustomText {
private final Text text;
private final int color;
public CustomText(Text text, int color) {
this.text = text;
this.color = color;
}
public Text getText() {
return text;
}
public int getColor() {
return color;
}
}
} }

View file

@ -7,6 +7,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -25,6 +26,7 @@ import net.minecraft.scoreboard.Team;
import net.minecraft.text.OrderedText; import net.minecraft.text.OrderedText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.world.GameMode; import net.minecraft.world.GameMode;
import net.saltymc.eaa.commands.TagCommand;
/** /**
* By: https://github.com/vladmarica/better-ping-display-fabric/ * By: https://github.com/vladmarica/better-ping-display-fabric/
@ -158,11 +160,17 @@ public final class CustomPlayerListHud {
aa += 9; aa += 9;
} }
int offset_tag_playername = aa;
TagCommand.CustomText playerTAG = TagCommand.getScoreboardTag(player.getProfile().getId().toString());
mc.textRenderer.drawWithShadow(stack, playerTAG.getText(), (float)aa, (float)ab, playerTAG.getColor());
offset_tag_playername += mc.textRenderer.getWidth(playerTAG.getText().asOrderedText()) + 2;
Text playerName = hud.getPlayerName(player); Text playerName = hud.getPlayerName(player);
if (player.getGameMode() == GameMode.SPECTATOR) { if (player.getGameMode() == GameMode.SPECTATOR) {
mc.textRenderer.drawWithShadow(stack, playerName, (float)aa, (float)ab, -1862270977); mc.textRenderer.drawWithShadow(stack, playerName, (float)offset_tag_playername, (float)ab, -1862270977);
} else { } else {
mc.textRenderer.drawWithShadow(stack, playerName, (float)aa, (float)ab, -1); mc.textRenderer.drawWithShadow(stack, playerName, (float)offset_tag_playername, (float)ab, -1);
} }
if (obj != null && player.getGameMode() != GameMode.SPECTATOR) { if (obj != null && player.getGameMode() != GameMode.SPECTATOR) {

View file

@ -7,8 +7,8 @@ import net.minecraft.util.math.MathHelper;
*/ */
public class PingColors { public class PingColors {
public static final int PING_START = 0; public static final int PING_START = 0;
public static final int PING_MID = 150; public static final int PING_MID = 50;
public static final int PING_END = 300; public static final int PING_END = 100;
public static final int COLOR_GREY = 0x535353; public static final int COLOR_GREY = 0x535353;
public static final int COLOR_START = 0x00E676; public static final int COLOR_START = 0x00E676;

View file

@ -1,14 +1,7 @@
package net.saltymc.eaa.custom.ping; package net.saltymc.eaa.custom.ping;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import net.saltymc.eaa.EaaMod; import net.saltymc.eaa.EaaMod;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
public class PingConfig { public class PingConfig {
@ -64,44 +57,10 @@ public class PingConfig {
return this.renderPingBars; return this.renderPingBars;
} }
public static ConfigData loadConfigFile(File configFile) throws IOException {
FileReader reader = null;
try {
Gson gson = new Gson();
reader = new FileReader(configFile);
return gson.fromJson(reader, ConfigData.class);
}
finally {
if (reader != null) {
reader.close();
}
}
}
public static void writeConfigFile(File configFile, ConfigData data) throws IOException {
FileWriter writer = null;
try {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
writer = new FileWriter(configFile);
writer.write(gson.toJson(data));
} finally {
if (writer != null) {
writer.close();
}
}
}
public static class ConfigData implements Serializable { public static class ConfigData implements Serializable {
@Expose
private boolean autoColorPingText = true; private boolean autoColorPingText = true;
@Expose
private boolean renderPingBars = false; private boolean renderPingBars = false;
@Expose
private String pingTextColor = "#A0A0A0"; private String pingTextColor = "#A0A0A0";
@Expose
private String pingTextFormatString = "%dms"; private String pingTextFormatString = "%dms";
} }
} }