minecraft-source/src/net/minecraft/world/item/FishingRodItem.java

64 lines
2.6 KiB
Java

package net.minecraft.world.item;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.fishing.FishingHook;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.player.Player;
import net.minecraft.resources.ResourceLocation;
public class FishingRodItem extends Item {
public FishingRodItem(final Properties a) {
super(a);
boolean boolean4;
boolean boolean5;
this.addProperty(new ResourceLocation("cast"), (bek, bjt, akw) -> {
if (akw == null) {
return 0.0f;
}
else {
boolean4 = (akw.getMainHandItem() == bek);
boolean5 = (akw.getOffhandItem() == bek);
if (akw.getMainHandItem().getItem() instanceof FishingRodItem) {
boolean5 = false;
}
return ((boolean4 || boolean5) && akw instanceof Player && akw.fishing != null) ? 1.0f : 0.0f;
}
});
}
@Override
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
final ItemStack bek5 = ayg.getItemInHand(ajh);
if (ayg.fishing != null) {
if (!bjt.isClientSide) {
final int integer6 = ayg.fishing.retrieve(bek5);
bek5.<Player>hurtAndBreak(integer6, ayg, ayg -> ayg.broadcastBreakEvent(ajh));
}
bjt.playSound(null, ayg.getX(), ayg.getY(), ayg.getZ(), SoundEvents.FISHING_BOBBER_RETRIEVE, SoundSource.NEUTRAL, 1.0f, 0.4f / (FishingRodItem.random.nextFloat() * 0.4f + 0.8f));
}
else {
bjt.playSound(null, ayg.getX(), ayg.getY(), ayg.getZ(), SoundEvents.FISHING_BOBBER_THROW, SoundSource.NEUTRAL, 0.5f, 0.4f / (FishingRodItem.random.nextFloat() * 0.4f + 0.8f));
if (!bjt.isClientSide) {
final int integer6 = EnchantmentHelper.getFishingSpeedBonus(bek5);
final int integer7 = EnchantmentHelper.getFishingLuckBonus(bek5);
bjt.addFreshEntity(new FishingHook(ayg, bjt, integer7, integer6));
}
ayg.awardStat(Stats.ITEM_USED.get(this));
}
return InteractionResultHolder.<ItemStack>success(bek5);
}
@Override
public int getEnchantmentValue() {
return 1;
}
}