/* * Decompiled with CFR 0.152. */ 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.InteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; 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 InteractionResult use(Level level, Player player, InteractionHand hand) { ItemStack itemStack = player.getItemInHand(hand); if (player.fishing != null) { if (!level.isClientSide()) { int dmg = player.fishing.retrieve(itemStack); itemStack.hurtAndBreak(dmg, (LivingEntity)player, hand.asEquipmentSlot()); } 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 serverLevel = (ServerLevel)level; int lureSpeed = (int)(EnchantmentHelper.getFishingTimeReduction(serverLevel, itemStack, player) * 20.0f); int luck = EnchantmentHelper.getFishingLuckBonus(serverLevel, itemStack, player); Projectile.spawnProjectile(new FishingHook(player, level, luck, lureSpeed), serverLevel, itemStack); } player.awardStat(Stats.ITEM_USED.get(this)); player.gameEvent(GameEvent.ITEM_INTERACT_START); } return InteractionResult.SUCCESS; } }