minecraft-src/net/minecraft/world/item/FishingRodItem.java
2025-07-04 01:41:11 +03:00

69 lines
2.1 KiB
Java

package net.minecraft.world.item;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
public class FishingRodItem extends Item {
public FishingRodItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
ItemStack itemStack = player.getItemInHand(usedHand);
if (player.fishing != null) {
if (!level.isClientSide) {
int i = player.fishing.retrieve(itemStack);
itemStack.hurtAndBreak(i, player, LivingEntity.getSlotForHand(usedHand));
}
level.playSound(
null,
player.getX(),
player.getY(),
player.getZ(),
SoundEvents.FISHING_BOBBER_RETRIEVE,
SoundSource.NEUTRAL,
1.0F,
0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)
);
player.gameEvent(GameEvent.ITEM_INTERACT_FINISH);
} else {
level.playSound(
null,
player.getX(),
player.getY(),
player.getZ(),
SoundEvents.FISHING_BOBBER_THROW,
SoundSource.NEUTRAL,
0.5F,
0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F)
);
if (level instanceof ServerLevel serverLevel) {
int j = (int)(EnchantmentHelper.getFishingTimeReduction(serverLevel, itemStack, player) * 20.0F);
int k = EnchantmentHelper.getFishingLuckBonus(serverLevel, itemStack, player);
level.addFreshEntity(new FishingHook(player, level, k, j));
}
player.awardStat(Stats.ITEM_USED.get(this));
player.gameEvent(GameEvent.ITEM_INTERACT_START);
}
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide());
}
@Override
public int getEnchantmentValue() {
return 1;
}
}