Skip to content

Instantly share code, notes, and snippets.

@Toma400
Last active April 16, 2023 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Toma400/dba43653e2afc6b29769c52d79b3a193 to your computer and use it in GitHub Desktop.
Save Toma400/dba43653e2afc6b29769c52d79b3a193 to your computer and use it in GitHub Desktop.
Multi-versioned gist for MCreator enchantments (currently supporting 1.14.4-1.18.2 versions)
/* COMMENTS WILL BE USED TO PRECISE FORGE VERSION THEY WERE USED FOR
* CURRENTLY SUPPORTED VERSIONS:
* - 1.14.4
* - 1.15.2
* - 1.16.5
* - 1.17.1
* - 1.18.2
*
* CODE SNIPPET IS ONLY PART OF THE CODE RELATED TO TAGGING. IT IS
* NOT MEANT TO BE USED -INSTEAD- OF MCR CODE.
*
* IT ALSO SHOWS ONLY TWO TAGS - YOU CAN OF COURSE ADD MORE OF THEM,
* MIX THEM WITH ITEMS OR WHATEVER. IF YOU NEED HELP, CONTACT ME ON
* DISCORD: Toma400#9987
*/
// 1.14.4 CODE SNIPPET
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
if (ItemTags.getCollection().getOrCreate(new ResourceLocation(("tag_namespace:tag_id")))
.contains((stack).getItem()) == true)
return true;
if (ItemTags.getCollection().getOrCreate(new ResourceLocation(("tag_namespace:second_tag_id")))
.contains((stack).getItem()) == true)
return true;
return false;
}
// 1.15.2 CODE SNIPPET
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
if (ItemTags.getCollection().getOrCreate(new ResourceLocation(("tag_namespace:tag_id")))
.contains((stack).getItem()) == true)
return true;
if (ItemTags.getCollection().getOrCreate(new ResourceLocation(("tag_namespace:second_tag_id")))
.contains((stack).getItem()) == true)
return true;
return false;
}
// 1.16.5 CODE SNIPPET
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
if (ItemTags.getCollection().getTagByID(new ResourceLocation(("tag_namespace:tag_id")))
.contains((stack).getItem()) == true)
return true;
if (ItemTags.getCollection().getTagByID(new ResourceLocation(("tag_namespace:second_tag_id")))
.contains((stack).getItem()) == true)
return true;
return false;
}
// 1.17.1 CODE SNIPPET
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
if(ItemTags.getAllTags().getTagOrEmpty(new ResourceLocation("tag_namespace:tag_id")).contains(stack.getItem()))
return true;
if(ItemTags.getAllTags().getTagOrEmpty(new ResourceLocation("tag_namespace:second_tag_id")).contains(stack.getItem()))
return true;
return false;
}
//1.18.2 CODE SNIPPET
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
if(stack.is(ItemTags.create(new ResourceLocation("tag_namespace:tag_id"))))
return true;
if(stack.is(ItemTags.create(new ResourceLocation("tag_namespace:second_tag_id"))))
return true;
return false;
}
@Toma400
Copy link
Author

Toma400 commented Apr 8, 2022

1.17 - 1.18 code got updated, since previously it redirected wrongly to NBT Tags, not regular Forge/Minecraft/Mod Tags.

Also, to whoever reads this, remember about importing all elements that you write here. So just if you see auto-filling to what you write, use enters.

In case of 1.18: ItemTags and ResourceLocation are especially that case, since they need to be imported for code to work correctly.
For other versions, it may need additional one or two things to be imported additionally.

@Stoutscientist
Copy link

Thank you so much! You saved my life I have been trying to get that working for hours

@EdEnStonne
Copy link

My hero has finally come :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment