minecraft-src/net/minecraft/world/item/SwordItem.java
2025-07-04 02:00:41 +03:00

29 lines
935 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 toolMaterial, float f, float g, Item.Properties properties) {
super(toolMaterial.applySwordProperties(properties, f, g));
}
@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);
}
}