Search in sources :

Example 1 with ItemStackTooltipEvent

use of com.tangykiwi.kiwiclient.event.ItemStackTooltipEvent in project KiwiClient by TangyKiwi.

the class Tooltips method appendTooltip.

@Subscribe
@AllowConcurrentEvents
public void appendTooltip(ItemStackTooltipEvent event) {
    // Stew
    if (getSetting(0).asToggle().state) {
        if (event.itemStack.getItem() == Items.SUSPICIOUS_STEW) {
            NbtCompound tag = event.itemStack.getNbt();
            if (tag != null) {
                NbtList effects = tag.getList("Effects", 10);
                if (effects != null) {
                    for (int i = 0; i < effects.size(); i++) {
                        NbtCompound effectTag = effects.getCompound(i);
                        byte effectId = effectTag.getByte("EffectId");
                        int effectDuration = effectTag.contains("EffectDuration") ? effectTag.getInt("EffectDuration") : 160;
                        StatusEffectInstance effect = new StatusEffectInstance(StatusEffect.byRawId(effectId), effectDuration, 0);
                        event.list.add(1, getStatusText(effect));
                    }
                }
            }
        } else if (event.itemStack.getItem().isFood()) {
            FoodComponent food = event.itemStack.getItem().getFoodComponent();
            if (food != null) {
                food.getStatusEffects().forEach((e) -> {
                    StatusEffectInstance effect = e.getFirst();
                    event.list.add(1, getStatusText(effect));
                });
            }
        }
    }
    // Bees
    if (getSetting(1).asToggle().state) {
        if (event.itemStack.getItem() == Items.BEEHIVE || event.itemStack.getItem() == Items.BEE_NEST) {
            NbtCompound tag = event.itemStack.getNbt();
            if (tag != null) {
                NbtCompound blockStateTag = tag.getCompound("BlockStateTag");
                if (blockStateTag != null) {
                    int level = blockStateTag.getInt("honey_level");
                    event.list.add(1, new LiteralText(String.format("%sHoney Level: %s%d%s", Formatting.GRAY, Formatting.YELLOW, level, Formatting.GRAY)));
                }
                NbtCompound blockEntityTag = tag.getCompound("BlockEntityTag");
                if (blockEntityTag != null) {
                    NbtList beesTag = blockEntityTag.getList("Bees", 10);
                    event.list.add(1, new LiteralText(String.format("%sBees: %s%d%s", Formatting.GRAY, Formatting.YELLOW, beesTag.size(), Formatting.GRAY)));
                }
            }
        }
    }
// Fish handled in EntityBucketItemMixin
}
Also used : LiteralText(net.minecraft.text.LiteralText) NbtList(net.minecraft.nbt.NbtList) EChestMemory(com.tangykiwi.kiwiclient.util.tooltip.EChestMemory) TranslatableText(net.minecraft.text.TranslatableText) Module(com.tangykiwi.kiwiclient.modules.Module) DefaultedList(net.minecraft.util.collection.DefaultedList) Block(net.minecraft.block.Block) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Inventories(net.minecraft.inventory.Inventories) MutableText(net.minecraft.text.MutableText) ToggleSetting(com.tangykiwi.kiwiclient.modules.settings.ToggleSetting) Subscribe(com.google.common.eventbus.Subscribe) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) ItemStackTooltipEvent(com.tangykiwi.kiwiclient.event.ItemStackTooltipEvent) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) Category(com.tangykiwi.kiwiclient.modules.Category) ContainerTooltipComponent(com.tangykiwi.kiwiclient.util.tooltip.ContainerTooltipComponent) net.minecraft.item(net.minecraft.item) Blocks(net.minecraft.block.Blocks) java.awt(java.awt) TooltipDataEvent(com.tangykiwi.kiwiclient.event.TooltipDataEvent) NbtCompound(net.minecraft.nbt.NbtCompound) StatusEffect(net.minecraft.entity.effect.StatusEffect) Formatting(net.minecraft.util.Formatting) List(java.util.List) StatusEffectUtil(net.minecraft.entity.effect.StatusEffectUtil) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) ShulkerBoxBlock(net.minecraft.block.ShulkerBoxBlock) DyeColor(net.minecraft.util.DyeColor) Text(net.minecraft.text.Text) Comparator(java.util.Comparator) NbtCompound(net.minecraft.nbt.NbtCompound) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) NbtList(net.minecraft.nbt.NbtList) LiteralText(net.minecraft.text.LiteralText) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)1 Subscribe (com.google.common.eventbus.Subscribe)1 ItemStackTooltipEvent (com.tangykiwi.kiwiclient.event.ItemStackTooltipEvent)1 TooltipDataEvent (com.tangykiwi.kiwiclient.event.TooltipDataEvent)1 Category (com.tangykiwi.kiwiclient.modules.Category)1 Module (com.tangykiwi.kiwiclient.modules.Module)1 ToggleSetting (com.tangykiwi.kiwiclient.modules.settings.ToggleSetting)1 ContainerTooltipComponent (com.tangykiwi.kiwiclient.util.tooltip.ContainerTooltipComponent)1 EChestMemory (com.tangykiwi.kiwiclient.util.tooltip.EChestMemory)1 Object2IntMap (it.unimi.dsi.fastutil.objects.Object2IntMap)1 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 java.awt (java.awt)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Block (net.minecraft.block.Block)1 Blocks (net.minecraft.block.Blocks)1 ShulkerBoxBlock (net.minecraft.block.ShulkerBoxBlock)1 StatusEffect (net.minecraft.entity.effect.StatusEffect)1 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)1 StatusEffectUtil (net.minecraft.entity.effect.StatusEffectUtil)1