Changes

8 bytes removed ,  13:59, 12 January 2022
Update to 1.18
Line 4: Line 4:     
== Adding Properties to Items  ==
 
== Adding Properties to Items  ==
<code><nowiki>ItemProperties::register</nowiki></code> is used to add a property to a specific item. The <code>ResourceLocation</code> parameter is the name given to the property (e.g. <code><nowiki>new ResourceLocation("pull")</nowiki></code>). The <code>ItemPropertyFunction</code> is a function that takes the <code>ItemStack</code>, the <code>ClientLevel</code> it’s in, the <code>LivingEntity</code> that holds it, and the <code>int</code> containing the id of the holding entity or '''0''', returning the <code>float</code> value for the property. Some examples are the <code><nowiki>pulling</nowiki></code> and <code><nowiki>pull</nowiki></code> properties for <code>Items#BOW</code>, and the several default ones in <code>ItemProperties</code>. For modded item properties, it is recommended that the modid of the mod is used as the namespace (e.g. <code><nowiki>examplemod:property</nowiki></code> and not just <code>property</code>, as that really means <code><nowiki>minecraft:property</nowiki></code>). There's also another private method <code>ItemProperties::registerGeneric</code> that is used to add properties to all items, and it does not take <code>Item</code> as its parameter since all items will apply this property.
+
<code><nowiki>ItemProperties::register</nowiki></code> is used to add a property to a specific item. The <code>ResourceLocation</code> parameter is the name given to the property (e.g. <code><nowiki>new ResourceLocation("pull")</nowiki></code>). The <code>ItemPropertyFunction</code> is a function that takes the <code>ItemStack</code>, the <code>ClientLevel</code> it’s in, the <code>LivingEntity</code> that holds it, and the <code>int</code> containing the id of the holding entity or '''0''', returning the <code>float</code> value for the property. Some examples are the <code><nowiki>pulling</nowiki></code> and <code><nowiki>pull</nowiki></code> properties for <code>Items#BOW</code>, and the several default ones in <code>ItemProperties</code>. For modded item properties, it is recommended that the modid of the mod is used as the namespace (e.g. <code><nowiki>examplemod:property</nowiki></code> and not just <code>property</code>, as that really means <code><nowiki>minecraft:property</nowiki></code>). There's also another method <code>ItemProperties::registerGeneric</code> that is used to add properties to all items, and it does not take <code>Item</code> as its parameter since all items will apply this property.
    
{{Tip/Important|Use <code>FMLClientSetupEvent#enqueueWork</code> to proceed with the tasks, since the data structures in <code>ItemProperties</code> are not thread-safe.}}
 
{{Tip/Important|Use <code>FMLClientSetupEvent#enqueueWork</code> to proceed with the tasks, since the data structures in <code>ItemProperties</code> are not thread-safe.}}