Skip to content

Commit

Permalink
backported 1.21 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Uraneptus committed Oct 23, 2024
1 parent d9150fe commit d32f774
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 84 deletions.
44 changes: 42 additions & 2 deletions Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ private static class Client implements NeatConfig.ConfigAccess {
private final PropertyMirror<Boolean> enableDebugInfo = PropertyMirror.create(BOOLEAN);
private final PropertyMirror<Boolean> showEntityName = PropertyMirror.create(BOOLEAN);
private final PropertyMirror<Boolean> disableNameTag = PropertyMirror.create(BOOLEAN);
private final PropertyMirror<Boolean> disableNameTagIfHealthbar = PropertyMirror.create(BOOLEAN);
private final PropertyMirror<Double> iconOffsetX = PropertyMirror.create(DOUBLE);
private final PropertyMirror<Double> iconOffsetY = PropertyMirror.create(DOUBLE);
private final PropertyMirror<String> decimalFormat = PropertyMirror.create(STRING);
private final PropertyMirror<List<String>> blacklist = PropertyMirror.create(ConfigTypes.makeList(STRING));

public ConfigTree configure(ConfigTreeBuilder builder) {
Expand All @@ -99,7 +103,7 @@ public ConfigTree configure(ConfigTreeBuilder builder) {
.finishValue(renderInF1::mirror)

.beginValue("heightAbove", DOUBLE, 0.6)
.withComment("How far above the mob health bars should render")
.withComment("How far above the mob the health bars should render")
.finishValue(heightAbove::mirror)

.beginValue("drawBackground", BOOLEAN, true)
Expand Down Expand Up @@ -139,7 +143,7 @@ public ConfigTree configure(ConfigTreeBuilder builder) {
.finishValue(groupArmor::mirror)

.beginValue("colorByType", BOOLEAN, false)
.withComment("Color the bar differently depending on whether the entity is hostile or is a boss")
.withComment("Color health bar by mob type instead of health percentage")
.finishValue(colorByType::mirror)

.beginValue("textColor", STRING, "FFFFFF")
Expand Down Expand Up @@ -198,6 +202,22 @@ public ConfigTree configure(ConfigTreeBuilder builder) {
.withComment("Disables the rendering of the vanilla name tag")
.finishValue(disableNameTag::mirror)

.beginValue("disableNameTagIfHealthbar", BOOLEAN, true)
.withComment("If this is enabled and the \"disableNameTag\" option is true, the vanilla nametag is only hidden if the mob has a Neat healthbar rendered")
.finishValue(disableNameTagIfHealthbar::mirror)

.beginValue("iconOffsetX", DOUBLE, 0.0)
.withComment("Offsets the healtbar icons on the x axis")
.finishValue(iconOffsetX::mirror)

.beginValue("iconOffsetY", DOUBLE, 0.0)
.withComment("Offsets the healtbar icons on the y axis")
.finishValue(iconOffsetY::mirror)

.beginValue("decimalFormat", STRING, "#.##")
.withComment("This value changes the decimal format of the HP. Only change this value if you are familiar with how the decimal format works!")
.finishValue(decimalFormat::mirror)

.beginValue("blacklist", ConfigTypes.makeList(STRING), NeatConfig.DEFAULT_DISABLED)
.withComment("Entity ID's that should not have bars rendered")
.finishValue(blacklist::mirror);
Expand Down Expand Up @@ -345,6 +365,26 @@ public boolean disableNameTag() {
return disableNameTag.getValue();
}

@Override
public boolean disableNameTagIfHealthbar() {
return disableNameTagIfHealthbar.getValue();
}

@Override
public double iconOffsetX() {
return iconOffsetX.getValue();
}

@Override
public double iconOffsetY() {
return iconOffsetY.getValue();
}

@Override
public String decimalFormat() {
return decimalFormat.getValue();
}

@Override
public List<String> blacklist() {
return blacklist.getValue();
Expand Down
6 changes: 6 additions & 0 deletions Forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ minecraft {
}
}

repositories {
maven {
url "https://cursemaven.com"
}
}

dependencies {
minecraft "net.minecraftforge:forge:${project.mc_version}-${project.forge_version}"
compileOnly project(":Xplat")
Expand Down
79 changes: 52 additions & 27 deletions Forge/src/main/java/vazkii/neat/NeatForgeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,49 @@ private static class ForgeNeatConfig implements NeatConfig.ConfigAccess {
private final ConfigValue<Boolean> enableDebugInfo;
private final ConfigValue<Boolean> showEntityName;
private final ConfigValue<Boolean> disableNameTag;
private final ConfigValue<Boolean> disableNameTagIfHealthbar;
private final ConfigValue<Double> iconOffsetX;
private final ConfigValue<Double> iconOffsetY;
private final ConfigValue<String> decimalFormat;
private final ConfigValue<List<? extends String>> blacklist;

public ForgeNeatConfig(ForgeConfigSpec.Builder builder) {
builder.push("general");

maxDistance = builder.define("Max Distance", 24);
maxDistanceWithoutLineOfSight = builder.define("Max Distance Without Line of Sight", 8);
renderInF1 = builder.define("Render with Interface Disabled (F1)", false);
heightAbove = builder.define("Height Above Mob", 0.6);
drawBackground = builder.define("Draw Background", true);
backgroundPadding = builder.define("Background Padding", 2);
backgroundHeight = builder.define("Background Height", 6);
barHeight = builder.define("Health Bar Height", 4);
plateSize = builder.define("Plate Size", 25);
plateSizeBoss = builder.define("Plate Size (Boss)", 50);
showAttributes = builder.define("Show Attributes", true);
showArmor = builder.define("Show Armor", true);
groupArmor = builder.define("Group Armor (condense 5 iron icons into 1 diamond icon)", true);
colorByType = builder.define("Color Health Bar by Type (instead of health percentage)", false);
maxDistance = builder.comment("Maximum distance in blocks at which health bars should render").define("max_distance", 24);
maxDistanceWithoutLineOfSight = builder.comment("Maximum distance in blocks at which health bars should render without line of sight").define("max_distance_without_line_of_sight", 8);
renderInF1 = builder.comment("Whether health bars should render when the HUD is disabled with F1").define("render_without_gui", false);
heightAbove = builder.comment("How far above the mob the health bars should render").define("height_above_mob", 0.6);
drawBackground = builder.comment("Whether the gray background plate should be drawn").define("draw_background", true);
backgroundPadding = builder.comment("Amount of extra padding space around the background plate").define("background_padding", 2);
backgroundHeight = builder.comment("How tall the background plate should be").define("background_height", 6);
barHeight = builder.comment("How tall the health bar should be").define("health_bar_height", 4);
plateSize = builder.comment("How wide the health bar should be. If the entity has a long name, the bar will increase in size to match it.").define("plate_size", 25);
plateSizeBoss = builder.comment("plateSize but for bosses").define("plate_size_boss", 50);
showAttributes = builder.comment("Show mob attributes such as arthropod or undead").define("show_attributes", true);
showArmor = builder.comment("Show armor points").define("show_armor", true);
groupArmor = builder.comment("Group 5 iron icons into 1 diamond icon").define("group_armor", true);
colorByType = builder.comment("Color health bar by mob type instead of health percentage").define("color_health_bar_by_type", false);
textColor = builder.comment("Text color in hex code format").define("text_color", "FFFFFF");
hpTextHeight = builder.define("HP Text Height", 14);
showMaxHP = builder.define("Show Max HP", true);
showCurrentHP = builder.define("Show Current HP", true);
showPercentage = builder.define("Show HP Percentage", true);
showOnPassive = builder.comment("Whether bars on passive mobs should be shown").define("showOnPassive", true);
showOnHostile = builder.comment("Whether bars on hostile mobs should be shown (does not include bosses)").define("showOnHostile", true);
showOnPlayers = builder.define("Display on Players", true);
showOnBosses = builder.define("Display on Bosses", true);
showOnlyFocused = builder.define("Only show the health bar for the entity looked at", false);
showFullHealth = builder.define("Show entities with full health", true);
enableDebugInfo = builder.define("Show Debug Info with F3", true);
showEntityName = builder.define("show_entity_name", true);
hpTextHeight = builder.comment("Height of the text on the health bar").define("hp_text_height", 14);
showMaxHP = builder.comment("Whether the maximum health of the mob should be shown").define("show_max_hp", true);
showCurrentHP = builder.comment("Whether the current health of the mob should be shown").define("show_current_hp", true);
showPercentage = builder.comment("Whether the percentage health of the mob should be shown").define("show_hp_percentage", true);
showOnPassive = builder.comment("Whether bars on passive mobs should be shown").define("show_on_passive", true);
showOnHostile = builder.comment("Whether bars on hostile mobs should be shown (does not include bosses)").define("show_on_hostile", true);
showOnPlayers = builder.comment("Whether bars on players should be shown").define("display_on_players", true);
showOnBosses = builder.comment("Whether bars on bosses should be shown").define("display_on_bosses", true);
showOnlyFocused = builder.comment("Only show bars for mobs you are targeting").define("only_health_bar_for_target", false);
showFullHealth = builder.comment("Show bars for mobs that are at full health").define("show_entity_full_health", true);
enableDebugInfo = builder.comment("Show extra debug info on the bar when F3 is enabled").define("show_debug_with_f3", true);
showEntityName = builder.comment("Show entity name").define("show_entity_name", true);
disableNameTag = builder.comment("Disables the rendering of the vanilla name tag").define("disable_name_tag", false);
disableNameTagIfHealthbar = builder.comment("If this is enabled and the \"disableNameTag\" option is true, the vanilla nametag is only hidden if the mob has a Neat healthbar rendered").define("disable_name_tag_if_healthbar", true);
iconOffsetX = builder.comment("Offsets the healtbar icons on the x axis").define("icon_offset_x", 0.0);
iconOffsetY = builder.comment("Offsets the healtbar icons on the y axis").define("icon_offset_y", 0.0);
decimalFormat = builder.comment("This value changes the decimal format of the HP. Only change this value if you are familiar with how the decimal format works!").define("decimal_format", "#.##");
blacklist = builder.comment("Blacklist uses entity IDs, not their display names. Use F3 to see them in the Neat bar.")
.defineList("Blacklist", NeatConfig.DEFAULT_DISABLED, a -> true);
.defineList("blacklist", NeatConfig.DEFAULT_DISABLED, a -> true);

builder.pop();
}
Expand Down Expand Up @@ -224,6 +232,23 @@ public boolean disableNameTag() {
return disableNameTag.get();
}

@Override
public boolean disableNameTagIfHealthbar() {
return disableNameTagIfHealthbar.get();
}
@Override
public double iconOffsetX() {
return iconOffsetX.get();
}
@Override
public double iconOffsetY() {
return iconOffsetY.get();
}
@Override
public String decimalFormat() {
return decimalFormat.get();
}

@SuppressWarnings("unchecked")
@Override
public List<String> blacklist() {
Expand Down
31 changes: 20 additions & 11 deletions Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.mojang.math.Axis;

import net.minecraft.ChatFormatting;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -36,7 +38,6 @@
import java.util.*;

public class HealthBarRenderer {
private static final DecimalFormat HEALTH_FORMAT = new DecimalFormat("#.##");

private static Entity getEntityLookedAt(Entity e) {
Entity foundEntity = null;
Expand Down Expand Up @@ -133,7 +134,7 @@ private static int getColor(LivingEntity entity, boolean colorByType, boolean bo
private static final TagKey<EntityType<?>> FABRIC_BOSS_TAG =
TagKey.create(Registries.ENTITY_TYPE, new ResourceLocation("c", "bosses"));

private static boolean isBoss(Entity entity) {
public static boolean isBoss(Entity entity) {
return entity.getType().is(FORGE_BOSS_TAG) || entity.getType().is(FABRIC_BOSS_TAG);
}

Expand Down Expand Up @@ -213,15 +214,16 @@ private static boolean shouldShowPlate(LivingEntity living, Entity cameraEntity)
}

public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSource buffers,
Quaternionf cameraOrientation) {
Camera camera, EntityRenderer<? super Entity> entityRenderer,
float partialTicks, double x, double y, double z) {
final Minecraft mc = Minecraft.getInstance();

if (!(entity instanceof LivingEntity living)) {
return;
}

//This was previously mc.gameRenderer.getMainCamera().getEntity() but that caused an incompatibility with RealCamera
if (!shouldShowPlate(living, mc.cameraEntity)) {
if (!shouldShowPlate(living, camera.getEntity())) {
return;
}

Expand All @@ -237,9 +239,15 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou
final float nameLen = mc.font.width(name) * textScale;
final float halfSize = Math.max(NeatConfig.instance.plateSize(), nameLen / 2.0F + 10.0F);

Vec3 vec3 = entityRenderer.getRenderOffset(entity, partialTicks);
double d2 = x + vec3.x();
double d3 = y + vec3.y();
double d0 = z + vec3.z();

poseStack.pushPose();
poseStack.translate(d2, d3, d0);
poseStack.translate(0, living.getBbHeight() + NeatConfig.instance.heightAbove(), 0);
poseStack.mulPose(cameraOrientation);
poseStack.mulPose(camera.rotation());

// Plate background, bars, and text operate with globalScale, but icons don't
poseStack.pushPose();
Expand Down Expand Up @@ -309,13 +317,14 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou
poseStack.scale(healthValueTextScale, healthValueTextScale, healthValueTextScale);

int h = NeatConfig.instance.hpTextHeight();
DecimalFormat health_format = new DecimalFormat(NeatConfig.instance.decimalFormat());

if (NeatConfig.instance.showCurrentHP()) {
String hpStr = HEALTH_FORMAT.format(living.getHealth());
String hpStr = health_format.format(living.getHealth());
mc.font.drawInBatch(hpStr, 2, h, textColor, false, poseStack.last().pose(), buffers, Font.DisplayMode.NORMAL, black, light);
}
if (NeatConfig.instance.showMaxHP()) {
String maxHpStr = ChatFormatting.BOLD + HEALTH_FORMAT.format(living.getMaxHealth());
String maxHpStr = ChatFormatting.BOLD + health_format.format(living.getMaxHealth());
mc.font.drawInBatch(maxHpStr, (int) (halfSize / healthValueTextScale * 2) - mc.font.width(maxHpStr) - 2, h, textColor, false, poseStack.last().pose(), buffers, Font.DisplayMode.NORMAL, black, light);
}
if (NeatConfig.instance.showPercentage()) {
Expand Down Expand Up @@ -387,11 +396,11 @@ private static void renderIcon(Level level, ItemStack icon, PoseStack poseStack,
// halfSize and co. are units operating under the assumption of globalScale,
// but in the icon rendering section we don't use globalScale, so we need
// to manually multiply it in to ensure the units line up.
float dx = (halfSize - leftShift) * globalScale;
float dy = 3F * globalScale;
float dz = zShift * globalScale;
double dx = (halfSize - leftShift) * globalScale + NeatConfig.instance.iconOffsetX();
double dy = 3F * globalScale;
double dz = zShift * globalScale;
// Need to negate X due to our rotation below
poseStack.translate(-dx, dy, dz);
poseStack.translate(-dx, dy + NeatConfig.instance.iconOffsetY(), dz);
poseStack.scale(iconScale, iconScale, iconScale);
poseStack.mulPose(Axis.YP.rotationDegrees(180F));
Minecraft.getInstance().getItemRenderer()
Expand Down
4 changes: 4 additions & 0 deletions Xplat/src/main/java/vazkii/neat/NeatConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public interface ConfigAccess {
boolean enableDebugInfo();
boolean showEntityName();
boolean disableNameTag();
boolean disableNameTagIfHealthbar();
double iconOffsetX();
double iconOffsetY();
String decimalFormat();
List<String> blacklist();
}

Expand Down
2 changes: 1 addition & 1 deletion Xplat/src/main/java/vazkii/neat/ToggleKeybind.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class ToggleKeybind {

public static final KeyMapping KEY = new KeyMapping("neat.keybind.toggle", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc");;
public static final KeyMapping KEY = new KeyMapping("neat.keybind.toggle", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc");

public static void handle() {
while (KEY.consumeClick()) {
Expand Down

This file was deleted.

Loading

0 comments on commit d32f774

Please sign in to comment.