Jump to content

Tooltip not showing up or is invisible


ClaraArmada

Recommended Posts

I would love some help with adding a tooltip to my item, I am, ofc, a beginner in modding, and this may seem like a simple thing, but I would like some help with this:
so here's my problem, I was adding a tooltip to my code, and I've been having issues, but it seems to have been resolved, but now, I can't seem to make it show up, I think the text is invisible somehow, here is the code and the image to my item (also yes ik, I didn't add the name of my item to the .lang, and the .literal is temporary):

package com.github.ClaraArmada.serilis.common.item;

import com.github.ClaraArmada.serilis.Serilis;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ModTools extends Item {
    private static final DeferredRegister<Item> ITEMS =
            DeferredRegister.create(ForgeRegistries.ITEMS, Serilis.MODID);

    public static final RegistryObject<Item> FLINT_FLAKE = ITEMS.register("flint_flake",
            () -> new AxeItem(ItemTiers.FLINT, 1, 2f, new Item.Properties()));

    public ModTools(Properties p_41383_) {
        super(p_41383_);
    }

    @Override
    public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> components, TooltipFlag flag) {
        components.add(Component.literal("This is a tool made out of flint").withStyle(ChatFormatting.GOLD));


        super.appendHoverText(stack, level, components, flag);
    }

    public static void register(IEventBus eventBus) {
        ITEMS.register(eventBus);
    }
}

the code

ZonQq0O.png

and here's the screenshot

Link to comment
Share on other sites

Can I see the ItemInit?

 

Edit: oh I just noticed what you're doing there. That would be your ToolInit if I'm not mistaken, right? So, to achieve what you want to do you could create the ToolInit which should not extend anything and implement the deferred register in it. Then create your own class of the item and instead of doing new Item or AxeItem you do new YourClass. The class we're talking about should extend the type of item you want to imitate, in this case it seems it's an AxeItem. So YourClass extends AxeItem. Then in that class you override appendHoverText and write stuff inside it. 

Edited by DrNickenstein
  • Like 1
Link to comment
Share on other sites

alright, the problem has been fixed, thank you! 😄

14 minutes ago, DrNickenstein said:

Can I see the ItemInit?

 

Edit: oh I just noticed what you're doing there. That would be your ToolInit if I'm not mistaken, right? So, to achieve what you want to do you could create the ToolInit which should not extend anything and implement the deferred register in it. Then create your own class of the item and instead of doing new Item or AxeItem you do new YourClass. The class we're talking about should extend the type of item you want to imitate, in this case it seems it's an AxeItem. So YourClass extends AxeItem. Then in that class you override appendHoverText and write stuff inside it. 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.