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

29 lines
1.1 KiB
Java

package net.minecraft.world.item;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Saddleable;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.gameevent.GameEvent;
public class SaddleItem extends Item {
public SaddleItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand) {
if (interactionTarget instanceof Saddleable saddleable && interactionTarget.isAlive() && !saddleable.isSaddled() && saddleable.isSaddleable()) {
if (!player.level().isClientSide) {
saddleable.equipSaddle(stack.split(1), SoundSource.NEUTRAL);
interactionTarget.level().gameEvent(interactionTarget, GameEvent.EQUIP, interactionTarget.position());
}
return InteractionResult.SUCCESS;
} else {
return InteractionResult.PASS;
}
}
}