修改ItemDisplay自定义名称的高度
有没有办法改变ItemDisplay实体的自定义名称高度?现在ItemDisplay的自定义名称直接出现在我玩家的显示名称中。我的当前代码:
ItemDisplay crystalDisplay = player.getWorld().spawn(player.getLocation(), ItemDisplay.class, display -> {
display.setItemStack(itemStack);
Transformation transformation = display.getTransformation();
transformation.getScale().set(0.5f, 0.5f, 0.5f);
transformation.getTranslation().set(0f, 0.8f, 0f);
display.setTransformation(transformation);
display.setBillboard(Display.Billboard.CENTER);
display.setInvulnerable(true);
display.setCustomNameVisible(true);
display.customName(miniMessage.deserialize("<#E36060><bold>HP</bold>"));
display.setInterpolationDuration(20);
display.setInterpolationDelay(0);
player_display.put(player.getUniqueId(), display);
});
player.addPassenger(spacer);
spacer.addPassenger(crystalDisplay);
解决方案
这只会移动 渲染出的物品,而不是 实体位置:
transformation.getTranslation().set(0f, 0.8f, 0f);
与其移动 物品平移,不如移动 实体位置。
transformation.getTranslation().set(0f, 0f, 0f);
或者,
使用Spacer实体。你已经在spacer的使用上部分实现了。通过乘客叠放来创建垂直偏移。
或者,
与其使用实体名称牌,不如使用 TextDisplay。
示例:
TextDisplay text = player.getWorld().spawn(
player.getLocation().add(0, 1.2, 0),
TextDisplay.class
);
text.text(miniMessage.deserialize("<#E36060><bold>HP</bold>"));
text.setBillboard(Display.Billboard.CENTER);
text.setShadowed(true);
text.setSeeThrough(true);
// Make it follow the player
player.addPassenger(text);
我觉得你不能直接改变customName的高度。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。