use of net.tropicraft.core.common.item.scuba.ScubaArmorItem 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.ScubaArmorItem in project Tropicraft by Tropicraft.
the class ScubaAmbienceTicker method onClientTick.
@SubscribeEvent
public static void onClientTick(ClientTickEvent event) {
if (event.phase != Phase.START)
return;
Minecraft mc = Minecraft.getInstance();
if (mc.level != null && mc.player != null) {
Camera renderInfo = mc.getEntityRenderDispatcher().camera;
Entity renderViewEntity = mc.getCameraEntity();
if (renderInfo != null && renderViewEntity instanceof Player) {
Player player = (Player) renderViewEntity;
if (renderInfo.getFluidInCamera() == FogType.WATER && player.getItemBySlot(EquipmentSlot.CHEST).getItem() instanceof ScubaArmorItem) {
if (ScubaData.getDepth(player) < 60) {
play(SHALLOW_SCUBA);
return;
} else {
play(DEEP_SCUBA);
return;
}
}
}
}
stop();
}
Aggregations