Search in sources :

Example 1 with ScubaArmorItem

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()))));
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) Item(net.minecraft.world.item.Item) ScubaArmorItem(net.tropicraft.core.common.item.scuba.ScubaArmorItem) ScubaData(net.tropicraft.core.common.item.scuba.ScubaData) Player(net.minecraft.world.entity.player.Player) ChatFormatting(net.minecraft.ChatFormatting) ScubaArmorItem(net.tropicraft.core.common.item.scuba.ScubaArmorItem) ItemStack(net.minecraft.world.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with ScubaArmorItem

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();
}
Also used : Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player) Camera(net.minecraft.client.Camera) ScubaArmorItem(net.tropicraft.core.common.item.scuba.ScubaArmorItem) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

Entity (net.minecraft.world.entity.Entity)2 Player (net.minecraft.world.entity.player.Player)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 ScubaArmorItem (net.tropicraft.core.common.item.scuba.ScubaArmorItem)2 ChatFormatting (net.minecraft.ChatFormatting)1 Camera (net.minecraft.client.Camera)1 Minecraft (net.minecraft.client.Minecraft)1 Item (net.minecraft.world.item.Item)1 ItemStack (net.minecraft.world.item.ItemStack)1 ScubaData (net.tropicraft.core.common.item.scuba.ScubaData)1