I have created a new enchantment called Gears and i would like it to give a speed boost to the player, however i am unable to give the enchantment the speed effect and would like help please, thankyou !!
Unfortunately there's no easy way to do this because Enchantments aren't designed to directly affect an entity's attributes (e.g. movement speed), but it is possible.
You'll want to use the attribute modifier system to modify the entity's movement speed while they have boots with your enchantment equipped.
First generate a random UUID with UUID.randomUUID and print it to the log. Create a private static final UUID field in EnchantmentSpeedBoost and initialise it by calling UUID.fromString with the UUID string you generated. This will be the ID of your speed modifier.
Subscribe to a tick event like TickEvent.PlayerTickEvent (players only, make sure you check that the phase field is Phase.END) or LivingUpdateEvent (all living entities). In your handler for this event, get the entity's boots (EntityLivingBase#getEquipmentInSlot, slot 1) and check the level of your enchantment on them (EnchantmentHelper#getEnchantmentLevel).
Get the entity's movement speed attribute instance by calling EntityLivingBase#getEntityAttribute with SharedMonsterAttributes.movementSpeed and get the existing instance of your modifier with IAttributeInstance#getModifier.
If there's an existing modifier, remove it with IAttributeInstance#removeModifier. If the player's boots have your enchantment, apply the appropriate modifier with IAttributeInstance#applyModifier (use the enchantment's level to determine the modifier amount).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I have created a new enchantment called Gears and i would like it to give a speed boost to the player, however i am unable to give the enchantment the speed effect and would like help please, thankyou !!
package net.revalitecraft.enchantments;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.EnumEnchantmentType;
public class EnchantmentSpeedBoost extends Enchantment{
public EnchantmentSpeedBoost(int id, int rarity){
super(id, rarity, EnumEnchantmentType.armor_feet);
this.setName("Gears");
}
public int getMinEnchantability(int par1){
return 5 + (par1 - 1) * 10;
}
public int getMaxEnchantability(int par1){
return this.getMinEnchantability(par1) + 20;
}
public int getMaxLevel(){
return 3;
}
}
Unfortunately there's no easy way to do this because Enchantments aren't designed to directly affect an entity's attributes (e.g. movement speed), but it is possible.
You'll want to use the attribute modifier system to modify the entity's movement speed while they have boots with your enchantment equipped.
First generate a random UUID with UUID.randomUUID and print it to the log. Create a private static final UUID field in EnchantmentSpeedBoost and initialise it by calling UUID.fromString with the UUID string you generated. This will be the ID of your speed modifier.
Subscribe to a tick event like TickEvent.PlayerTickEvent (players only, make sure you check that the phase field is Phase.END) or LivingUpdateEvent (all living entities). In your handler for this event, get the entity's boots (EntityLivingBase#getEquipmentInSlot, slot 1) and check the level of your enchantment on them (EnchantmentHelper#getEnchantmentLevel).
Get the entity's movement speed attribute instance by calling EntityLivingBase#getEntityAttribute with SharedMonsterAttributes.movementSpeed and get the existing instance of your modifier with IAttributeInstance#getModifier.
If there's an existing modifier, remove it with IAttributeInstance#removeModifier. If the player's boots have your enchantment, apply the appropriate modifier with IAttributeInstance#applyModifier (use the enchantment's level to determine the modifier amount).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.