Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ _Elements 3 - 1.21.4_
- Potion display (count of heal/mana potions in inv)
- Translation for death.attack.magic.item (Player killed by magic damage)

## Additional Features (nichtDanger)

- XP Meter (Basalt)
- Measure Basalt Gen's with keybind (default: none) and target XP / target time (configurable)
- Player Level Enhancements
- Option to format level with dots as thousands separators (Player Level and Level in Player List)
- Option to change the color of the player levels
- Option to change the color of the levels in the player list
- Player XP Enhancements
- Option to format XP with dots as thousands separators
- Option to change the color of the XP display
- Option to hide the max pet
- Excalibur Time Display
- Show the time until the next Excalibur is available
- Show the next Player who can pull Excalibur

## Config

Use Modmenu to toggle features or change the position of the display
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.16.14
loom_version=1.10-SNAPSHOT

# Mod Properties
mod_version=1.4.0+1.21.4
mod_version=1.4.1+1.21.4
maven_group=dev.eposs.elementsutils
archives_base_name=elements-utils

Expand Down
44 changes: 35 additions & 9 deletions src/client/java/dev/eposs/elementsutils/ElementsUtilsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import dev.eposs.elementsutils.config.ModConfig;
import dev.eposs.elementsutils.feature.bosstimer.BossTimerData;
import dev.eposs.elementsutils.feature.bosstimer.BossTimerDisplay;
import dev.eposs.elementsutils.feature.excaliburtimer.ExcaliburTimerData;
import dev.eposs.elementsutils.feature.loot.LootSound;
import dev.eposs.elementsutils.feature.pet.PetDisplay;
import dev.eposs.elementsutils.feature.playerbase.BaseBorderDisplay;
import dev.eposs.elementsutils.feature.potion.PotionDisplay;
import dev.eposs.elementsutils.feature.xpmeter.XpMeter;
import dev.eposs.elementsutils.rendering.ScreenRendering;
import dev.eposs.elementsutils.util.DevUtil;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
Expand All @@ -30,7 +31,9 @@

public class ElementsUtilsClient implements ClientModInitializer {
private static KeyBinding baseDisplayToggle;
private static KeyBinding bossTimerToggle;
private static KeyBinding timeDisplaysToggle;
private static KeyBinding xpMeasureTrigger;
private static KeyBinding timeMeasureTrigger;
private static KeyBinding devUtils;

@Override
Expand All @@ -43,6 +46,7 @@ public void onInitializeClient() {
registerKeyBinding();
registerEvents();

ExcaliburTimerData.startUpdateTimers();
BossTimerData.startUpdateTimers();
}

Expand All @@ -63,11 +67,16 @@ private void clientTick(MinecraftClient client) {
onKeyEvent(client);
PetDisplay.updatePet(client);
PotionDisplay.updatePotions(client);
XpMeter.updateXpMeter(client);
}

private void onJoin(ClientPlayNetworkHandler handler, PacketSender sender, MinecraftClient client) {
runServerCheck(client);
PetDisplay.loadPet(handler.getRegistryManager());

ModConfig.InternalConfig.Servers server = ModConfig.getConfig().internal.server;
if (server != ModConfig.InternalConfig.Servers.UNKNOWN) {
PetDisplay.loadPet(handler.getRegistryManager());
}
}

private void onLeave(ClientPlayNetworkHandler handler, MinecraftClient client) {
Expand Down Expand Up @@ -97,9 +106,8 @@ private void runServerCheck(MinecraftClient client) {

private boolean onGameMessage(Text text, boolean b) {
LootSound.onGameMessage(text);

return true;
}
return true;
}

private void registerKeyBinding() {
String category = "category." + ElementsUtils.MOD_ID + ".keys";
Expand All @@ -110,12 +118,24 @@ private void registerKeyBinding() {
category
));

bossTimerToggle = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("bossTimerToggle"),
timeDisplaysToggle = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("timeDisplaysToggle"),
GLFW.GLFW_KEY_V,
category
));

xpMeasureTrigger = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("xpMeasureTrigger"),
GLFW.GLFW_KEY_UNKNOWN,
category
));

timeMeasureTrigger = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("timeMeasureTrigger"),
GLFW.GLFW_KEY_UNKNOWN,
category
));

devUtils = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("devUtils"),
GLFW.GLFW_KEY_UNKNOWN,
Expand All @@ -127,9 +147,15 @@ private void onKeyEvent(MinecraftClient client) {
while (baseDisplayToggle.wasPressed()) {
BaseBorderDisplay.toggleDisplay(client);
}
while (bossTimerToggle.wasPressed()) {
while (timeDisplaysToggle.wasPressed()) {
BossTimerDisplay.toggleDisplay(client);
}
while (xpMeasureTrigger.wasPressed()) {
XpMeter.startXPMeasurement(client);
}
while (timeMeasureTrigger.wasPressed()) {
XpMeter.startTimeMeasurement(client);
}
while (devUtils.wasPressed()) {
DevUtil.doSomething(client);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.eposs.elementsutils.api.excaliburtimer;

import com.google.gson.Gson;
import dev.eposs.elementsutils.ElementsUtils;
import dev.eposs.elementsutils.config.ModConfig;
import dev.eposs.elementsutils.feature.excaliburtimer.ExcaliburTimerData;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class ExcaliburTimerApi {
private static final String TIMER_URI = "https://elements-utils.eposs.dev/api/excalibur?server=$SERVER_ID";

public static @Nullable ExcaliburTimerData getExcaliburTimerData() {
String serverID;
switch (ModConfig.getConfig().internal.server) {
case COMMUNITY_SERVER_1 -> serverID = "server1";
case COMMUNITY_SERVER_2 -> serverID = "server2";
default -> {
return null;
}
}

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(TIMER_URI.replace("$SERVER_ID", serverID)))
.GET()
.build();

try (HttpClient client = HttpClient.newBuilder().build()) {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

if (response.statusCode() != 200) {
throw new IOException("Status code " + response.statusCode() + " - " + response.body());
}

return new Gson().fromJson(response.body(), ExcaliburTimerData.class);

} catch (Exception e) {
ElementsUtils.LOGGER.error("Failed to get excalibur timer data", e);
return null;
}
}
}
64 changes: 58 additions & 6 deletions src/client/java/dev/eposs/elementsutils/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ public enum Position {
}

@ConfigEntry.Gui.CollapsibleObject
public BossTimerConfig bossTimer = new BossTimerConfig();
public static class BossTimerConfig {
public TimeDisplaysConfig timeDisplays = new TimeDisplaysConfig();
public static class TimeDisplaysConfig {
public boolean show = true;
public TimeFormat timeFormat = TimeFormat.RELATIVE;
public boolean textOutline = true;

public TimeFormat bossTimeFormat = TimeFormat.RELATIVE;
public boolean colorBossNames = true;
public boolean colorBossTime = true;

public boolean colorExcaliburNames = true;
public boolean colorExcaliburTime = true;
public TimeFormat excaliburTimeFormat = TimeFormat.ABSOLUTE;

public boolean colorTime = true;
public enum TimeFormat {
RELATIVE,
ABSOLUTE,
}
}

}

Expand All @@ -79,10 +85,56 @@ public static class PotionDisplayConfig {
public enum Position {
LEFT,
RIGHT,
}
}

}

@ConfigEntry.Gui.CollapsibleObject
public XPMeterConfig xpMeterConfig = new XPMeterConfig();
public static class XPMeterConfig {
public Integer measuringXpTarget = 500;
public Integer measuringTimeTarget = 300;
}

@ConfigEntry.Gui.CollapsibleObject
public PlayerLevelConfig playerLevelConfig = new PlayerLevelConfig();
public static class PlayerLevelConfig {
public boolean enabled = true;
public KnownColor formattedPlayerLevelColor = KnownColor.EXPERIENCE_GREEN;
public KnownColor formattedPlayerListLevelColor = KnownColor.YELLOW;
}

public enum KnownColor {
BLACK(0x000000),
DARK_BLUE(0x0000AA),
DARK_GREEN(0x00AA00),
DARK_AQUA(0x00AAAA),
DARK_RED(0xAA0000),
DARK_PURPLE(0xAA00AA),
GOLD(0xFFAA00),
GRAY(0xAAAAAA),
DARK_GRAY(0x555555),
BLUE(0x5555FF),
GREEN(0x55FF55),
EXPERIENCE_GREEN(0x80FF20),
AQUA(0x55FFFF),
RED(0xFF5555),
LIGHT_PURPLE(0xFF55FF),
YELLOW(0xFFFF55),
WHITE(0xFFFFFF);

public final int color;
KnownColor(int color) { this.color = color; }
}

@ConfigEntry.Gui.CollapsibleObject
public PlayerXPConfig playerXPConfig = new PlayerXPConfig();
public static class PlayerXPConfig {
public boolean enabled = true;
public KnownColor overlayMessageColor = KnownColor.DARK_AQUA;
public boolean hideMaxPetXP = false;
}

@ConfigEntry.Gui.CollapsibleObject
public DevUtilsConfig devUtils = new DevUtilsConfig();
public static class DevUtilsConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,44 @@
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;

public class BossTimerDisplay {
public static void toggleDisplay(@NotNull MinecraftClient client) {
if (client.player == null || client.world == null) return;

ModConfig.getConfig().bossTimer.show = !ModConfig.getConfig().bossTimer.show;
ModConfig.getConfig().timeDisplays.show = !ModConfig.getConfig().timeDisplays.show;
ModConfig.save();

if (ModConfig.getConfig().bossTimer.show) {
if (ModConfig.getConfig().timeDisplays.show) {
BossTimerData.updateData();
}
}

public static void render(DrawContext context, MinecraftClient client) {
ModConfig.BossTimerConfig config = ModConfig.getConfig().bossTimer;
ModConfig.TimeDisplaysConfig config = ModConfig.getConfig().timeDisplays;
if (!config.show) return;

BossTimerData timerData = BossTimerData.getInstance();

drawText(client, context, 0, Text.translatable("text.autoconfig.elements-utils.option.bossTimer").formatted(Formatting.UNDERLINE));
drawText(client, context, 0, Text.translatable("elements-utils.display.bossTimer.title").formatted(Formatting.UNDERLINE));
drawText(client, context, 1, formattedText("Axolotl", Formatting.LIGHT_PURPLE, timerData.getAxolotl(), config));
drawText(client, context, 2, formattedText("Zombie", Formatting.GREEN, timerData.getZombie(), config));
drawText(client, context, 3, formattedText("Spider", Formatting.DARK_GRAY, timerData.getSpider(), config));
drawText(client, context, 4, formattedText("Bogged", Formatting.DARK_GREEN, timerData.getBogged(), config));
drawText(client, context, 5, formattedText("Piglin", Formatting.RED, timerData.getPiglin(), config));
}

private static Text formattedText(String name, Formatting nameColor, ZonedDateTime time, ModConfig.BossTimerConfig config) {
private static final DateTimeFormatter ABSOLUTE_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");

private static Text formattedText(String name, Formatting nameColor, ZonedDateTime time, ModConfig.TimeDisplaysConfig config) {
return Text.literal("")
.append(Text.literal(name + ": ").formatted(config.colorBossNames ? nameColor : Formatting.WHITE))
.append(time == null ? Text.translatable("elements-utils.unknown") :
config.timeFormat == ModConfig.BossTimerConfig.TimeFormat.RELATIVE
config.bossTimeFormat == ModConfig.TimeDisplaysConfig.TimeFormat.RELATIVE
? toRelativeTime(time)
: Text.literal(time.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT))))
.formatted(config.colorTime ? getTimeColor(time) : Formatting.WHITE);
: Text.literal(time.format(ABSOLUTE_FORMATTER)))
.formatted(config.colorBossTime ? getTimeColor(time) : Formatting.WHITE);
}

private static Formatting getTimeColor(ZonedDateTime dateTime) {
Expand Down Expand Up @@ -94,16 +95,17 @@ private static Text toRelativeTime(@NotNull ZonedDateTime dateTime) {
sb.append(minutes).append("m ");
}

return Text.translatable("elements-utils.display.bosstimer.relative", sb.toString().trim());
return Text.translatable("elements-utils.display.bossTimer.relative", sb.toString().trim());
}

private static void drawText(MinecraftClient client, DrawContext context, int line, Text text) {
int lineHeight = client.textRenderer.fontHeight + 3;
boolean outline = ModConfig.getConfig().timeDisplays.textOutline;
context.drawText(
client.textRenderer,
text,
4, (client.getWindow().getScaledHeight() / 2) - (lineHeight * 3) + (lineHeight * line),
Colors.WHITE, false
net.minecraft.util.Colors.WHITE, outline
);
}

Expand Down
Loading