Applying enchantment to Forge Tags

Started by Toma400 on

Topic category: Help with Minecraft modding (Java Edition)

Applying enchantment to Forge Tags
Sat, 07/24/2021 - 07:48 (edited)

Hello!

I wanted to ask quick question which will be crazy useful for my mod's add-on/compatibility features, yet I do not see that option in MCreator per se. And though I asked Klemen for that feature, I'm a bit afraid it won't go through 2021.2 dev process, since devs have already a lot of work on Gradle cache problem and.. other features, of course.

Question is: how can I apply Forge item Tag for enchantment? This way enchantment would not only work for items from my mod, but also for all add-ons and mods that will use my mod's Forge Tag to create their own guns.
From investigating code, I found that part of enchantment which is - I'm pretty sure - this part deciding on what kind of items enchantment applies to. It is currently using item, just for reference. How should it look like if I would like use Forge item Tag instead?
(Forge item Tag is "forge:wobr_firearms", if it's needed)

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
    if (stack.getItem() == new ItemStack(GoldenShotRevolverItem.block, (int) (1)).getItem())
        return true;
    return false;
}

Thanks in advance ^^

Edited by Toma400 on Sat, 07/24/2021 - 07:48
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey there Toma400, After…
Sun, 02/20/2022 - 16:47

Hey there Toma400,

After trying some code I have found the solution to do this.
At least, this code worked for me:

@Override
    public boolean canApplyAtEnchantingTable(ItemStack stack) {
        if (ItemTags.getAllTags().getTagOrEmpty(new ResourceLocation("forge:tagname")).contains(stack.getItem()))
            return true;
        return false;
    }

Just replace the "tagname" after forge: with the name of your tag. (so in your case it should be "forge:wobr_firearms").

Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I do want to point out that…
Sun, 02/20/2022 - 16:57

I do want to point out that at first, it might give an error message, but if you rewrite "ItemTags"  and "ResourceLocation" it works.

It's so funny, I learned…
Tue, 02/22/2022 - 08:49

It's so funny, I learned code a bit lately and came back to this idea, making working code... which is exactly what you suggested me, probably in the same day I added that feature without knowing about such kind person trying to help me ^^

But thank you nevertheless for the help, if I didn't start learning lately, you would save my life with this!
If you do not have anything against it, I can link this topic with your answer to my compatibility guide, so if anyone is wondering how to make that feature, it will be helpful for them too ^^

Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
That's totally fine, Since…
Tue, 02/22/2022 - 20:51

That's totally fine, Since you posted this a while back I did think you might've found a solution to it, but I wasn't sure and still wanted to help. Linking it to your compatibility guide sounds like a great idea.

 

I linked it, thank you so…
Tue, 03/22/2022 - 10:45

I linked it, thank you so much ^^

By the way, I also made a code storaging gist, so if anyone wants to have correct code for any post-1.12 version, it can be found here.
For now it supports 1.14-1.18 code, but I will try to support it for newer versions, as long as I actively make mods (if new version is out and gist isn't updated, just contact me).

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What should i rewrite  in…
Tue, 08/09/2022 - 14:32

What should i rewrite  in the place of RecourseLocation?