Search in sources :

Example 1 with ScubaData

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()))));
        }
    }
}
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 ScubaData

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);
}
Also used : ScubaData(net.tropicraft.core.common.item.scuba.ScubaData)

Aggregations

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