Search in sources :

Example 1 with TooltipKey

use of slimeknights.tconstruct.library.utils.TooltipKey in project TinkersConstruct by SlimeKnights.

the class TankItem method appendHoverText.

@Override
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
    if (stack.hasTag()) {
        FluidTank tank = getFluidTank(stack);
        if (tank.getFluidAmount() > 0) {
            tooltip.add(new TranslatableComponent(KEY_FLUID, tank.getFluid().getDisplayName()).withStyle(ChatFormatting.GRAY));
            int amount = tank.getFluidAmount();
            TooltipKey key = SafeClientAccess.getTooltipKey();
            if (tank.getCapacity() % FluidValues.INGOT != 0 || key == TooltipKey.SHIFT) {
                tooltip.add(new TranslatableComponent(KEY_MB, amount).withStyle(ChatFormatting.GRAY));
            } else {
                int ingots = amount / FluidValues.INGOT;
                int mb = amount % FluidValues.INGOT;
                if (mb == 0) {
                    tooltip.add(new TranslatableComponent(KEY_INGOTS, ingots).withStyle(ChatFormatting.GRAY));
                } else {
                    tooltip.add(new TranslatableComponent(KEY_MIXED, ingots, mb).withStyle(ChatFormatting.GRAY));
                }
                if (key != TooltipKey.UNKNOWN) {
                    tooltip.add(FluidTooltipHandler.HOLD_SHIFT);
                }
            }
        }
    } else {
        super.appendHoverText(stack, worldIn, tooltip, flagIn);
    }
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TooltipKey(slimeknights.tconstruct.library.utils.TooltipKey)

Example 2 with TooltipKey

use of slimeknights.tconstruct.library.utils.TooltipKey in project TinkersConstruct by SlimeKnights.

the class ToolPartItem method appendHoverText.

@Override
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
    if (TooltipUtil.isDisplay(stack)) {
        return;
    }
    // add all traits to the info
    MaterialVariantId materialVariant = this.getMaterial(stack);
    MaterialId id = materialVariant.getId();
    if (!materialVariant.equals(IMaterial.UNKNOWN_ID)) {
        if (canUseMaterial(id)) {
            for (ModifierEntry entry : MaterialRegistry.getInstance().getTraits(id, getStatType())) {
                tooltip.add(entry.getModifier().getDisplayName(entry.getLevel()));
            }
            // add stats
            if (Config.CLIENT.extraToolTips.get()) {
                TooltipKey key = SafeClientAccess.getTooltipKey();
                if (key == TooltipKey.SHIFT || key == TooltipKey.UNKNOWN) {
                    this.addStatInfoTooltip(id, tooltip);
                } else {
                    // info tooltip for detailed and component info
                    tooltip.add(TextComponent.EMPTY);
                    tooltip.add(TooltipUtil.TOOLTIP_HOLD_SHIFT);
                }
            }
        } else {
            // is the material missing, or is it not valid for this stat type?
            IMaterial material = MaterialRegistry.getMaterial(id);
            if (material == IMaterial.UNKNOWN) {
                tooltip.add(new TranslatableComponent(MISSING_MATERIAL_KEY, id));
            } else {
                tooltip.add(new TranslatableComponent(MISSING_STATS_KEY, materialStatId).withStyle(ChatFormatting.GRAY));
            }
        }
    }
// mod handled by getCreatorModId
}
Also used : IMaterial(slimeknights.tconstruct.library.materials.definition.IMaterial) MaterialId(slimeknights.tconstruct.library.materials.definition.MaterialId) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) MaterialVariantId(slimeknights.tconstruct.library.materials.definition.MaterialVariantId) ModifierEntry(slimeknights.tconstruct.library.modifiers.ModifierEntry) TooltipKey(slimeknights.tconstruct.library.utils.TooltipKey)

Aggregations

TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 TooltipKey (slimeknights.tconstruct.library.utils.TooltipKey)2 FluidTank (net.minecraftforge.fluids.capability.templates.FluidTank)1 IMaterial (slimeknights.tconstruct.library.materials.definition.IMaterial)1 MaterialId (slimeknights.tconstruct.library.materials.definition.MaterialId)1 MaterialVariantId (slimeknights.tconstruct.library.materials.definition.MaterialVariantId)1 ModifierEntry (slimeknights.tconstruct.library.modifiers.ModifierEntry)1