use of net.tropicraft.core.common.item.scuba.ScubaData in project Tropicraft by Tropicraft.
the class ScubaHUD method renderHUD.
@SubscribeEvent
public static void renderHUD(RenderGameOverlayEvent event) {
Entity renderViewEntity = Minecraft.getInstance().cameraEntity;
if (event.getType() == ElementType.TEXT && renderViewEntity instanceof Player) {
Player player = (Player) renderViewEntity;
// TODO support other slots than chest?
ItemStack chestStack = player.getItemBySlot(EquipmentSlot.CHEST);
Item chestItem = chestStack.getItem();
if (chestItem instanceof ScubaArmorItem) {
LazyOptional<ScubaData> data = player.getCapability(ScubaData.CAPABILITY);
int airRemaining = ((ScubaArmorItem) chestItem).getRemainingAir(chestStack);
ChatFormatting airColor = getAirTimeColor(airRemaining, player.level);
double depth = ScubaData.getDepth(player);
String depthStr;
if (depth > 0) {
depthStr = String.format("%.1fm", depth);
} else {
depthStr = TropicraftLangKeys.NA.getLocalizedText();
}
data.ifPresent(d -> drawHUDStrings(event.getMatrixStack(), TropicraftLangKeys.SCUBA_AIR_TIME.format(airColor + formatTime(airRemaining)), TropicraftLangKeys.SCUBA_DIVE_TIME.format(formatTime(d.getDiveTime())), TropicraftLangKeys.SCUBA_DEPTH.format(depthStr), TropicraftLangKeys.SCUBA_MAX_DEPTH.format(String.format("%.1fm", d.getMaxDepth()))));
}
}
}
use of net.tropicraft.core.common.item.scuba.ScubaData in project Tropicraft by Tropicraft.
the class MessageUpdateScubaData method decode.
public static MessageUpdateScubaData decode(final FriendlyByteBuf buf) {
ScubaData data = new ScubaData();
data.deserializeBuffer(buf);
return new MessageUpdateScubaData(data);
}
Aggregations