Skip to content

Commit

Permalink
Refactor PaperPlayerCharacter hologram updates
Browse files Browse the repository at this point in the history
Removed redundant methods and streamlined hologram updates by consolidating logic into a new `updateDisplayNameHologramPosition()` helper. Simplified entity transformations and added a teleport duration for the display entity to enhance consistency.
  • Loading branch information
NonSwag committed Jan 19, 2025
1 parent c133fbb commit 5fed74e
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.world.entity.Entity.RemovalReason;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.ChatVisiblity;
import net.thenextlvl.character.PlayerCharacter;
import net.thenextlvl.character.plugin.CharacterPlugin;
Expand Down Expand Up @@ -89,13 +88,6 @@ public boolean setCollidable(boolean collidable) {
return true;
}

@Override
public boolean setScale(double scale) {
if (!super.setScale(scale)) return false;
getEntity().ifPresent(this::updateDisplayName);
return true;
}

@Override
public boolean setTeamColor(@Nullable NamedTextColor color) {
if (!super.setTeamColor(color)) return false;
Expand Down Expand Up @@ -359,6 +351,7 @@ private void updateDisplayNameHologram(TextDisplay display) {
display.setBillboard(Display.Billboard.CENTER);
display.setGravity(false);
display.setPersistent(false);
display.setTeleportDuration(3);
var component = displayName == null ? Component.text(getName()) : displayName;
display.text(component.color(teamColor));
}
Expand All @@ -370,7 +363,6 @@ private void updateDisplayNameHologram(Player player) {
spawnDisplayNameHologram(player);
} else {
updateDisplayNameHologram(displayNameHologram);
displayNameHologram.teleportAsync(getDisplayNameHologramPosition(player));
}
}

Expand Down Expand Up @@ -422,16 +414,10 @@ public String getScoreboardName() {
return PaperPlayerCharacter.this.getScoreboardName();
}

@Override
public void setPose(Pose pose) {
super.setPose(pose);
getEntity().ifPresent(PaperPlayerCharacter.this::updateDisplayNameHologram);
}

@Override
public void setPos(double x, double y, double z) {
super.setPos(x, y, z);
getEntity().ifPresent(PaperPlayerCharacter.this::updateDisplayNameHologram);
updateDisplayNameHologramPosition();
}

@Override
Expand All @@ -444,5 +430,10 @@ public void tick() {
public void doTick() {
if (ticking) super.doTick();
}

private void updateDisplayNameHologramPosition() {
if (displayNameHologram == null || entity == null) return;
displayNameHologram.teleport(getDisplayNameHologramPosition(entity));
}
}
}

0 comments on commit 5fed74e

Please sign in to comment.