29 lines
969 B
Java
29 lines
969 B
Java
package net.minecraft.world.item;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.entity.EquipmentSlot;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class SwordItem extends Item {
|
|
public SwordItem(ToolMaterial material, float attackDamage, float attackSpeed, Item.Properties properties) {
|
|
super(material.applySwordProperties(properties, attackDamage, attackSpeed));
|
|
}
|
|
|
|
@Override
|
|
public boolean canAttackBlock(BlockState state, Level level, BlockPos pos, Player player) {
|
|
return !player.isCreative();
|
|
}
|
|
|
|
@Override
|
|
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void postHurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
|
stack.hurtAndBreak(1, attacker, EquipmentSlot.MAINHAND);
|
|
}
|
|
}
|