Get Enchantment ID

Started by Liam Jones on

Topic category: Feature requests and ideas for MCreator

Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Get Enchantment ID

I am trying to make a block that combines the enchantments of two Items for cheap, but the problem is that there isn't a procedure block that detects which enchantment your item has. There is a block that detects whether the item is enchanted, and if it has a specific enchantment, but to find what enchantment exactly your item has, you need to have one of each "does the item have x enchantment?" blocks.

It would be quite useful to just be given that information with one block.

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
U mean combine checking if…
Sat, 09/10/2022 - 11:49

U mean combine checking if it is enchanted and checking if it has specific enchantment into one block? 

 

I think that would be kinda pointless since im pretty sure that if item has enchantment x then it is enchanted, if it doesn't have, then it may be enchanted but it doesn't have your specific enchant. 

Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No, you're right that that…
Sun, 09/11/2022 - 13:08

No, you're right that that would be pointless. What I mean is a block that tells you *which* enchantment it does have. Not whether it has an enchantment or if it has a specific enchantment. Instead of asking "Does x have y enchantment?" It'd be asking "What enchantment does x have?" and it would return a text or number value.

A theoretical example would be in an anvil-like GUI with two slots to combine enchantments. You could say "copy slot 0 to the output slot, and enchant it with [get enchantment of item in slot 1]"

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Uhh, it wouldn't return a…
Sun, 09/11/2022 - 18:01

Uhh, it wouldn't return a number or text cause those are not enchantments (text can be name of the enchantment in game, but in programming its different thing).  

You mean list of all enchantments that item has? Mcreator does not support lists (or maps in this case) so it wont be added (at least anytime soon). You can do it yourself but it will require custom code

Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well, don't know how to…
Thu, 09/15/2022 - 17:40

Well, don't know how to respond to that

Joined Apr 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I did a similar thing before…
Fri, 09/23/2022 - 19:24

I did a similar thing before. these are the code parts I wrote

for (int i = 0; i<item.getEnchantmentTags().size(); i++){
    item.getEnchantmentTags().getCompound(i).getString("id")
}

using this, you can get the "id" of your item's enchantments. they are like minecraft:sharpness (not completely sure about this)

for getting the enchantment by its id, it gets more difficult

this part of code is really not readable but it just works

for (Map.Entry<ResourceKey<Enchantment>,Enchantment> setobj : ForgeRegistries.ENCHANTMENTS.getEntries()) {
                    if (enchantname.split(":",0)[1].compareTo(setobj.getKey().location().getPath())==0) { // IT JUST WORKS
                        enchant = setobj.getValue();
                    }
                }

I don't know why I used compareTo == 0. maybe it can be replaced by str1 == str2. test it yourself. also I recommend trying different things to find a better way to do this.

also I am gonna try to create procedures for this (get number of enchantments on item, get enchantment with index i from itemstack, also every procedure that takes enchantment as its input). I will reply to this post if I complete it.

Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
That first part is exactly…
Fri, 11/24/2023 - 22:49

That first part is exactly what I was thinking. A block that returns the ID of the enchantment. However, I realize that it would require a list if there were multiple enchantments on the item.