This site works best with JavaScript enabled. Please enable JavaScript to get the best experience from this site.
I want that my weapon can't be right clicked if it doesn't have the minimum durability of 299, any ideas how I could do that?
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.*; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; public class WolfBlood extends SwordItem { public WolfBlood(ToolMaterial Material, int attackDamage, float attackSpeed, Settings settings) { super(Material, attackDamage, attackSpeed, settings); } public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand){ ItemStack itemStack = user.getStackInHand(hand); user.getItemCooldownManager().set(this,16*20); user.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED,126)); user.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH,126)); user.getMainHandStack().damage(299,user,e-> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); return TypedActionResult.success(itemStack); } }
You can check how damaged the stack is by using itemStack.getDamage()
should I use it like if (itemStack.getDamage()) ?
You could use it for example like this:
if (itemStack.getDamage() < 100) { // This code will only run if the sword has taken // less than 100 durability damage }
thanks for the help I Finally get it to work
No problem, glad I could help!
I want that my weapon can't be right clicked if it doesn't have the minimum durability of 299, any ideas how I could do that?
You can check how damaged the stack is by using itemStack.getDamage()
should I use it like if (itemStack.getDamage()) ?
You could use it for example like this:
thanks for the help I Finally get it to work
No problem, glad I could help!