Get the IEnchantmentDefinition object by the ID of StoredEnchantments
Zhang-Wei-666 opened this issue · 6 comments
Feature request name
Get the IEnchantmentDefinition object by the ID of StoredEnchantments
Feature request description
Feature request reason
I need to get the StoredEnchantments from the enchanted book and then convert to the IEnchantmentDefinition object to get the maxLevel
Feature request dependencies
No
stored enchantments are only on enchanted books, if it is a case or adding a method that is only going to affect a single item, then I don't think that is the right way to go about doing it, especially when it would just access the nbt tag, which as you said you can already do.
Kindlich provided a method that seems to work, if it doesn't or I misunderstood it being the answer, please reopen this
By ID, do you mean the numeric ID, or the resource location?
We won't add the numeric ID because technically, that could change between worlds.
For the resource location, you can get it using the Enchantment Bracket Handler
<enchantment:minecraft:protection>
@kindlich
`
var book = <minecraft:enchanted_book>;
recipes.addShapeless( "name", book, [ book.marked("input") ], function( output, ins, info ){
var inputEnchantment = ins.input.tag.StoredEnchantments[0];
var id = inputEnchantment.id;
var lvl = inputEnchantment.lvl;
print( id ); // => 16
print( lvl ); // => 3
#How to change from id to IEnchantmentDefinition object ?
});
`
Hi @kindlich ,
I think the aim there is to use recipe functions for recipes that act upon enchantments. The problem is, enchantments are stored in NBT as numeric ID, but the Crafttweaker API does not provide access to those id (since they changes in different worlds).
Therefore, you can only add enchantment recipe that are blind to the type of the enchantment. You cannot test if the enchantment is applicable to the output, you cannot use its max level, etc. This is quite limiting for recipes acting on enchantments.
Is it possible to add a way to retrieve IEnchantmentDefinition
or IEnchantment
objects from an IItemStack
within the context of a recipe function, were a world is accessible and the <enchantment ID - registry name> conversion is defined ?
Maybe add a method to the ICraftingInfo
interface, or the IWorld
interface accessible with ICraftingInfo.getWorld()
?
I think net.minecraft.enchantment.Enchantment.getEnchantmentByID()
is the method we need, wrapping the returned Enchantment
in a `MCEnchantmentDefinition.
Thanks for considering again !
Oh right, I missed that one !
Looking at the code, it doesn't seems to work for the StoredEnchantments
tag of enchanted books, as it access only the ench
tag. Maybe I can do a pull request to add a method like getStoredEnchantments
and an attribute storedEnchantments
to MCItemStack
and IItemStack
? Would that fit within CrT ?
EDIT: to be fair, I can always copy the StoredEnchantment
tag in the ench
tag and then use the getter, so this is not really necessary.