Skip to content

Commit

Permalink
Merge pull request #142 from dmdinnc/random-feature-adds
Browse files Browse the repository at this point in the history
Add stronger invis mob support, stacked mobs, and non-LoS config
  • Loading branch information
Uraneptus authored Sep 9, 2024
2 parents bd9889b + 228acf4 commit 5595f29
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static void setup() {

private static class Client implements NeatConfig.ConfigAccess {
private final PropertyMirror<Integer> maxDistance = PropertyMirror.create(INTEGER);
private final PropertyMirror<Integer> maxDistanceWithoutLineOfSight = PropertyMirror.create(INTEGER);
private final PropertyMirror<Boolean> renderInF1 = PropertyMirror.create(BOOLEAN);
private final PropertyMirror<Double> heightAbove = PropertyMirror.create(DOUBLE);
private final PropertyMirror<Boolean> drawBackground = PropertyMirror.create(BOOLEAN);
Expand Down Expand Up @@ -82,6 +83,10 @@ public ConfigTree configure(ConfigTreeBuilder builder) {
.withComment("Maximum distance in blocks at which health bars should render")
.finishValue(maxDistance::mirror)

.beginValue("maxDistanceWithoutLineOfSight", INTEGER, 8)
.withComment("Maximum distance in blocks at which health bars should render without line of sight")
.finishValue(maxDistanceWithoutLineOfSight::mirror)

.beginValue("renderInF1", BOOLEAN, false)
.withComment("Whether health bars should render when the HUD is disabled with F1")
.finishValue(renderInF1::mirror)
Expand Down Expand Up @@ -178,6 +183,11 @@ public int maxDistance() {
return maxDistance.getValue();
}

@Override
public int maxDistanceWithoutLineOfSight() {
return maxDistanceWithoutLineOfSight.getValue();
}

@Override
public boolean renderInF1() {
return renderInF1.getValue();
Expand Down
7 changes: 7 additions & 0 deletions Forge/src/main/java/vazkii/neat/NeatForgeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static void init() {

private static class ForgeNeatConfig implements NeatConfig.ConfigAccess {
private final ConfigValue<Integer> maxDistance;
private final ConfigValue<Integer> maxDistanceWithoutLineOfSight;
private final ConfigValue<Boolean> renderInF1;
private final ConfigValue<Double> heightAbove;
private final ConfigValue<Boolean> drawBackground;
Expand Down Expand Up @@ -45,6 +46,7 @@ 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);
Expand Down Expand Up @@ -77,6 +79,11 @@ public int maxDistance() {
return maxDistance.get();
}

@Override
public int maxDistanceWithoutLineOfSight() {
return maxDistanceWithoutLineOfSight.get();
}

@Override
public boolean renderInF1() {
return renderInF1.get();
Expand Down
28 changes: 20 additions & 8 deletions Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ private static boolean shouldShowPlate(LivingEntity living, Entity cameraEntity)

float distance = living.distanceTo(cameraEntity);
if (distance > NeatConfig.instance.maxDistance()
|| !living.hasLineOfSight(cameraEntity)) {
|| (distance > NeatConfig.instance.maxDistanceWithoutLineOfSight()
&& !living.hasLineOfSight(cameraEntity))) {
return false;
}
if (!NeatConfig.instance.showOnBosses() && isBoss(living)) {
Expand All @@ -170,8 +171,22 @@ private static boolean shouldShowPlate(LivingEntity living, Entity cameraEntity)
}

boolean visible = true;
if (cameraEntity instanceof Player cameraPlayer) {
visible = !living.isInvisibleTo(cameraPlayer);
if (cameraEntity instanceof Player cameraPlayer
&& living.isInvisibleTo(cameraPlayer)) {
boolean wearingThings = false;
for (ItemStack armorSlot : living.getArmorSlots()) {
if (!armorSlot.isEmpty()) {
wearingThings = true;
}
}
for (ItemStack handSlot : living.getHandSlots()) {
if (!handSlot.isEmpty()) {
wearingThings = true;
}
}
if (!wearingThings) {
visible = false;
}
}
Team livingTeam = living.getTeam();
Team cameraTeam = cameraEntity.getTeam();
Expand All @@ -191,8 +206,7 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou
Quaternionf cameraOrientation) {
final Minecraft mc = Minecraft.getInstance();

if (!(entity instanceof LivingEntity living) || (!living.getPassengers().isEmpty() && living.getPassengers().get(0) instanceof LivingEntity)) {
// TODO handle mob stacks properly
if (!(entity instanceof LivingEntity living)) {
return;
}

Expand All @@ -206,9 +220,7 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou
final float textScale = 0.5F;
final int barHeight = NeatConfig.instance.barHeight();
final boolean boss = isBoss(living);
final String name = living.hasCustomName()
? ChatFormatting.ITALIC + living.getCustomName().getString()
: living.getDisplayName().getString();
final String name = living.getDisplayName().getString();
final float nameLen = mc.font.width(name) * textScale;
final float halfSize = Math.max(NeatConfig.instance.plateSize(), nameLen / 2.0F + 10.0F);

Expand Down
1 change: 1 addition & 0 deletions Xplat/src/main/java/vazkii/neat/NeatConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class NeatConfig {

public interface ConfigAccess {
int maxDistance();
int maxDistanceWithoutLineOfSight();
boolean renderInF1();
double heightAbove();
boolean drawBackground();
Expand Down

0 comments on commit 5595f29

Please sign in to comment.