Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compact damage #696

Merged
merged 12 commits into from
May 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.ColorControllerBuilder;
import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder;
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.awt.*;

public class UIAndVisualsCategory {
public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig config) {
return ConfigCategory.createBuilder()
Expand Down Expand Up @@ -355,6 +358,49 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.build())
.build())

//Compact Damage Numbers
.group(OptionGroup.createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.compactDamage"))
.collapsed(true)
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.compactDamage.enabled"))
.binding(defaults.uiAndVisuals.compactDamage.enabled,
() -> config.uiAndVisuals.compactDamage.enabled,
newValue -> config.uiAndVisuals.compactDamage.enabled = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Integer>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.compactDamage.precision"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.uiAndVisuals.compactDamage.precision.@Tooltip")))
.binding(defaults.uiAndVisuals.compactDamage.precision,
() -> config.uiAndVisuals.compactDamage.precision,
newValue -> config.uiAndVisuals.compactDamage.precision = newValue)
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(1,3).step(1))
.build())
.option(Option.<Color>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.compactDamage.normalDamageColor"))
.binding(defaults.uiAndVisuals.compactDamage.normalDamageColor,
() -> config.uiAndVisuals.compactDamage.normalDamageColor,
newValue -> config.uiAndVisuals.compactDamage.normalDamageColor = newValue)
.controller(ColorControllerBuilder::create)
.build())
.option(Option.<Color>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.compactDamage.critDamageGradientStart"))
.binding(defaults.uiAndVisuals.compactDamage.critDamageGradientStart,
() -> config.uiAndVisuals.compactDamage.critDamageGradientStart,
newValue -> config.uiAndVisuals.compactDamage.critDamageGradientStart = newValue)
.controller(ColorControllerBuilder::create)
.build())
.option(Option.<Color>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.compactDamage.critDamageGradientEnd"))
.binding(defaults.uiAndVisuals.compactDamage.critDamageGradientEnd,
() -> config.uiAndVisuals.compactDamage.critDamageGradientEnd,
newValue -> config.uiAndVisuals.compactDamage.critDamageGradientEnd = newValue)
.controller(ColorControllerBuilder::create)
.build())
.build()
)

.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import net.minecraft.util.Formatting;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -56,6 +57,9 @@ public class UIAndVisualsConfig {
@SerialEntry
public FlameOverlay flameOverlay = new FlameOverlay();

@SerialEntry
public CompactDamage compactDamage = new CompactDamage();

public static class ChestValue {
@SerialEntry
public boolean enableChestValue = true;
Expand Down Expand Up @@ -247,4 +251,20 @@ public static class FlameOverlay {
public int flameOpacity = 100;
}

public static class CompactDamage {
@SerialEntry
public boolean enabled = true;

@SerialEntry
public int precision = 1;

@SerialEntry
public Color normalDamageColor = new Color(0xFFFFFF);

@SerialEntry
public Color critDamageGradientStart = new Color(0xFFFF55);

@SerialEntry
public Color critDamageGradientEnd = new Color(0xFF5555);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.CompactDamage;
import de.hysky.skyblocker.skyblock.FishingHelper;
import de.hysky.skyblocker.skyblock.dungeon.DungeonScore;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
Expand All @@ -17,11 +19,10 @@
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityStatuses;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -103,4 +104,14 @@ public abstract class ClientPlayNetworkHandlerMixin {
}
return entity;
}

@Inject(method = "onEntityTrackerUpdate", at = @At("TAIL"))
private void skyblocker$onEntityTrackerUpdate(EntityTrackerUpdateS2CPacket packet, CallbackInfo ci, @Local Entity entity) {
if (!SkyblockerConfigManager.get().uiAndVisuals.compactDamage.enabled || !(entity instanceof ArmorStandEntity armorStandEntity)) return;
try { //Prevent packet handling fails if something goes wrong so that entity trackers still update, just without compact damage numbers
CompactDamage.compactDamage(armorStandEntity);
} catch (Exception e) {
e.printStackTrace();
Emirlol marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
78 changes: 78 additions & 0 deletions src/main/java/de/hysky/skyblocker/skyblock/CompactDamage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package de.hysky.skyblocker.skyblock;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.CustomArmorAnimatedDyes;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import org.apache.commons.lang3.math.NumberUtils;

import java.text.DecimalFormat;
import java.util.List;
import java.util.regex.Pattern;


public class CompactDamage {
private CompactDamage() {
}

public static void compactDamage(ArmorStandEntity entity) {
if (!entity.isInvisible() || !entity.hasCustomName() || !entity.isCustomNameVisible() || entity.getFireTicks() != -1 || !entity.shouldHideBasePlate()) return;
//Dmg armor stands have no base plate and have a fire time of -1 (just one of these isn't enough to determine if it's a dmg armor stand)
//In fact, even this much checking might not be accurate. Needs testing, or just waiting until someone reports it as an issue
Text customName = entity.getCustomName();
List<Text> siblings = customName.getSiblings();
if (siblings.isEmpty()) return;

MutableText prettierCustomName;
if (siblings.size() == 1) { //Non-crit damage
Text text = siblings.getFirst();
String dmg = text.getString().replace(",", "");
if (!NumberUtils.isParsable(dmg)) return; //Sanity check
String prettifiedDmg = prettifyDamageNumber(Long.parseLong(dmg));
prettierCustomName = Text.literal("").append(Text.literal(prettifiedDmg).withColor(SkyblockerConfigManager.get().uiAndVisuals.compactDamage.normalDamageColor.getRGB() & 0x00FFFFFF)).setStyle(customName.getStyle());
} else { //Crit damage
String dmg = siblings.subList(1, siblings.size() - 1) //First and last sibling are the crit symbols
.stream()
.map(Text::getString)
.reduce("", String::concat) //Concatenate all the siblings to get the dmg number
.replace(",", "");

if (!NumberUtils.isParsable(dmg)) return; //Sanity check
String prettifiedDmg = "✧" + prettifyDamageNumber(Long.parseLong(dmg)) + "✧";
prettierCustomName = Text.literal("");
int length = prettifiedDmg.length();
for (int i = 0; i < length; i++) {
prettierCustomName.append(Text.literal(prettifiedDmg.substring(i, i + 1)).withColor(
CustomArmorAnimatedDyes.interpolate(
SkyblockerConfigManager.get().uiAndVisuals.compactDamage.critDamageGradientStart.getRGB() & 0x00FFFFFF,
SkyblockerConfigManager.get().uiAndVisuals.compactDamage.critDamageGradientEnd.getRGB() & 0x00FFFFFF,
i / (length - 1.0)
)
));
}
prettierCustomName.setStyle(customName.getStyle());
}

entity.setCustomName(prettierCustomName);
}

private static String prettifyDamageNumber(long damage) {
if (damage < 1_000) return String.valueOf(damage);
if (damage < 1_000_000) return format(damage / 1_000.0) + "k";
if (damage < 1_000_000_000) return format(damage / 1_000_000.0) + "m";
if (damage < 1_000_000_000_000L) return format(damage / 1_000_000_000.0) + "b";
return format(damage / 1_000_000_000_000.0) + "t"; //This will probably never be reached
}

private static String format(double number) {
return ("%." + SkyblockerConfigManager.get().uiAndVisuals.compactDamage.precision + "f").formatted(number);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static int animateColorTransition(AnimatedDye animatedDye) {
}

//Credit to https://codepen.io/OliverBalfour/post/programmatically-making-gradients
private static int interpolate(int firstColor, int secondColor, double percentage) {
public static int interpolate(int firstColor, int secondColor, double percentage) {
int r1 = MathHelper.square((firstColor >> 16) & 0xFF);
int g1 = MathHelper.square((firstColor >> 8) & 0xFF);
int b1 = MathHelper.square(firstColor & 0xFF);
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,14 @@
"skyblocker.config.uiAndVisuals.chestValue.incompleteColor": "Incomplete Color",
"skyblocker.config.uiAndVisuals.chestValue.incompleteColor.@Tooltip": "The color to display when the price data is incomplete.",

"skyblocker.config.uiAndVisuals.compactDamage": "Compact Damage",
"skyblocker.config.uiAndVisuals.compactDamage.enabled": "Enabled",
"skyblocker.config.uiAndVisuals.compactDamage.precision": "Precision",
"skyblocker.config.uiAndVisuals.compactDamage.precision.@Tooltip" : "The number of digits to display after the decimal point.",
"skyblocker.config.uiAndVisuals.compactDamage.normalDamageColor": "Normal Damage Color",
"skyblocker.config.uiAndVisuals.compactDamage.critDamageGradientStart": "Crit Damage Gradient Start Color",
"skyblocker.config.uiAndVisuals.compactDamage.critDamageGradientEnd": "Crit Damage Gradient End Color",

"skyblocker.config.uiAndVisuals.compactorDeletorPreview": "Enable Compactor/Deletor Preview",

"skyblocker.config.uiAndVisuals.dontStripSkinAlphaValues": "Correct Transparent Skin Pixels",
Expand Down