Skip to content

Commit

Permalink
Run pmd
Browse files Browse the repository at this point in the history
  • Loading branch information
williewillus committed Jul 4, 2022
1 parent 6a1b773 commit bc8a007
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
57 changes: 38 additions & 19 deletions src/main/java/vazkii/neat/HealthBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ public static Entity getEntityLookedAt(Entity e) {
HitResult pos = raycast(e, finalDistance);
Vec3 positionVector = e.position();

if (e instanceof Player)
if (e instanceof Player) {
positionVector = positionVector.add(0, e.getEyeHeight(e.getPose()), 0);
}

if (pos != null)
if (pos != null) {
distance = pos.getLocation().distanceTo(positionVector);
}

Vec3 lookVector = e.getLookAngle();
Vec3 reachVector = positionVector.add(lookVector.x * finalDistance, lookVector.y * finalDistance, lookVector.z * finalDistance);
Expand Down Expand Up @@ -84,21 +86,24 @@ public static Entity getEntityLookedAt(Entity e) {
}
}

if (lookedEntity != null && (minDistance < distance || pos == null))
if (lookedEntity != null && (minDistance < distance || pos == null)) {
foundEntity = lookedEntity;
}
}

return foundEntity;
}

public static HitResult raycast(Entity e, double len) {
Vec3 vec = new Vec3(e.getX(), e.getY(), e.getZ());
if (e instanceof Player)
if (e instanceof Player) {
vec = vec.add(new Vec3(0, e.getEyeHeight(e.getPose()), 0));
}

Vec3 look = e.getLookAngle();
if (look == null)
if (look == null) {
return null;
}

return raycast(vec, look, e, len);
}
Expand Down Expand Up @@ -150,8 +155,9 @@ public static int getColor(LivingEntity entity, boolean colorByType, boolean bos
public void onRenderLevelLast(RenderLevelLastEvent event) {
Minecraft mc = Minecraft.getInstance();

if ((!NeatConfig.renderInF1 && !Minecraft.renderNames()) || !NeatConfig.draw)
if ((!NeatConfig.renderInF1 && !Minecraft.renderNames()) || !NeatConfig.draw) {
return;
}

Camera camera = mc.gameRenderer.getMainCamera();
PoseStack poseStack = event.getPoseStack();
Expand Down Expand Up @@ -198,21 +204,27 @@ public void renderHealthBar(LivingEntity passedEntity, Minecraft mc, PoseStack p
boolean boss = !entity.canChangeDimensions();

String entityID = entity.getType().getRegistryName().toString();
if (NeatConfig.blacklist.contains(entityID))
if (NeatConfig.blacklist.contains(entityID)) {
continue;
}

processing: {
float distance = passedEntity.distanceTo(viewPoint);
if (distance > NeatConfig.maxDistance || !passedEntity.hasLineOfSight(viewPoint) || entity.isInvisible())
if (distance > NeatConfig.maxDistance || !passedEntity.hasLineOfSight(viewPoint) || entity.isInvisible()) {
break processing;
if (!NeatConfig.showOnBosses && boss)
}
if (!NeatConfig.showOnBosses && boss) {
break processing;
if (!NeatConfig.showOnPlayers && entity instanceof Player)
}
if (!NeatConfig.showOnPlayers && entity instanceof Player) {
break processing;
if (entity.getMaxHealth() <= 0)
}
if (entity.getMaxHealth() <= 0) {
break processing;
if (!NeatConfig.showFullHealth && entity.getHealth() == entity.getMaxHealth())
}
if (!NeatConfig.showFullHealth && entity.getHealth() == entity.getMaxHealth()) {
break processing;
}

double x = passedEntity.xo + (passedEntity.getX() - passedEntity.xo) * partialTicks;
double y = passedEntity.yo + (passedEntity.getY() - passedEntity.yo) * partialTicks;
Expand Down Expand Up @@ -249,8 +261,9 @@ private void renderEntity(Minecraft mc, PoseStack poseStack, MultiBufferSource.B
float textScale = 0.5F;

String name = (entity.hasCustomName() ? entity.getCustomName() : entity.getDisplayName()).getString();
if (entity.hasCustomName())
if (entity.hasCustomName()) {
name = ChatFormatting.ITALIC + name;
}

float namel = mc.font.width(name) * textScale;
if (namel + 20 > size * 2) {
Expand Down Expand Up @@ -312,19 +325,25 @@ private void renderEntity(Minecraft mc, PoseStack poseStack, MultiBufferSource.B
String hpStr = "" + Math.round(health * 100.0) / 100.0;
String percStr = (int) percent + "%";

if (maxHpStr.endsWith(".00"))
if (maxHpStr.endsWith(".00")) {
maxHpStr = maxHpStr.substring(0, maxHpStr.length() - 3);
if (hpStr.endsWith(".00"))
}
if (hpStr.endsWith(".00")) {
hpStr = hpStr.substring(0, hpStr.length() - 3);
}

if (NeatConfig.showCurrentHP)
if (NeatConfig.showCurrentHP) {
mc.font.drawInBatch(hpStr, 2, h, white, false, modelViewMatrix, buffer, false, black, light);
if (NeatConfig.showMaxHP)
}
if (NeatConfig.showMaxHP) {
mc.font.drawInBatch(maxHpStr, (int) (size / (textScale * s1) * 2) - 2 - mc.font.width(maxHpStr), h, white, false, modelViewMatrix, buffer, false, black, light);
if (NeatConfig.showPercentage)
}
if (NeatConfig.showPercentage) {
mc.font.drawInBatch(percStr, (int) (size / (textScale * s1)) - mc.font.width(percStr) / 2, h, white, false, modelViewMatrix, buffer, false, black, light);
if (NeatConfig.enableDebugInfo && mc.options.renderDebug)
}
if (NeatConfig.enableDebugInfo && mc.options.renderDebug) {
mc.font.drawInBatch("ID: \"" + entity.getType().getRegistryName().toString() + "\"", 0, h + 16, white, false, modelViewMatrix, buffer, false, black, light);
}
}
poseStack.popPose();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/neat/ToggleKeybind.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public void onKeyInput(InputEvent.KeyInputEvent event) {
Minecraft mc = Minecraft.getInstance();
boolean wasDown = down;
down = key.isDown();
if (mc.isWindowActive() && down && !wasDown)
if (mc.isWindowActive() && down && !wasDown) {
NeatConfig.draw = !NeatConfig.draw;
}
}

}

0 comments on commit bc8a007

Please sign in to comment.