51 lines
1.4 KiB
Java
51 lines
1.4 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import net.minecraft.sounds.SoundEvents;
|
|
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.level.Level;
|
|
|
|
public class SpyglassItem extends Item {
|
|
public static final int USE_DURATION = 1200;
|
|
public static final float ZOOM_FOV_MODIFIER = 0.1F;
|
|
|
|
public SpyglassItem(Item.Properties properties) {
|
|
super(properties);
|
|
}
|
|
|
|
@Override
|
|
public int getUseDuration(ItemStack stack, LivingEntity entity) {
|
|
return 1200;
|
|
}
|
|
|
|
@Override
|
|
public ItemUseAnimation getUseAnimation(ItemStack stack) {
|
|
return ItemUseAnimation.SPYGLASS;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(Level level, Player player, InteractionHand hand) {
|
|
player.playSound(SoundEvents.SPYGLASS_USE, 1.0F, 1.0F);
|
|
player.awardStat(Stats.ITEM_USED.get(this));
|
|
return ItemUtils.startUsingInstantly(level, player, hand);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livingEntity) {
|
|
this.stopUsing(livingEntity);
|
|
return stack;
|
|
}
|
|
|
|
@Override
|
|
public boolean releaseUsing(ItemStack stack, Level level, LivingEntity entity, int timeLeft) {
|
|
this.stopUsing(entity);
|
|
return true;
|
|
}
|
|
|
|
private void stopUsing(LivingEntity user) {
|
|
user.playSound(SoundEvents.SPYGLASS_STOP_USING, 1.0F, 1.0F);
|
|
}
|
|
}
|