SpyglassItem .java

net.minecraft.world.item.SpyglassItem (class, 52 lines): members: ZOOM_FOV_MODIFIER, USE_DURATION, finishUsingItem, releaseUsing, getUseAnimation, use.

net.minecraft.world.itemclass52 linescommonextends Item1.5 KB

API Surface (5)

int getUseDuration(final ItemStack itemStack, final LivingEntity user)
ItemUseAnimation getUseAnimation(final ItemStack itemStack)
InteractionResult use(final Level level, final Player player, final InteractionHand hand)
ItemStack finishUsingItem(final ItemStack itemStack, final Level level, final LivingEntity entity)
boolean releaseUsing(final ItemStack itemStack, final Level level, final LivingEntity entity, final int remainingTime)

Fields & Constants (2)

USE_DURATION
ZOOM_FOV_MODIFIER

Full Source

SpyglassItem.java52 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item;
2
3
import net.minecraft.sounds.SoundEvents;
4
import net.minecraft.stats.Stats;
5
import net.minecraft.world.InteractionHand;
6
import net.minecraft.world.InteractionResult;
7
import net.minecraft.world.entity.LivingEntity;
8
import net.minecraft.world.entity.player.Player;
9
import net.minecraft.world.level.Level;
10
11
public class SpyglassItem extends Item {
12
	public static final int USE_DURATION = 1200;
13
	public static final float ZOOM_FOV_MODIFIER = 0.1F;
14
15
	public SpyglassItem(final Item.Properties properties) {
16
		super(properties);
17
	}
18
19
	@Override
20
	public int getUseDuration(final ItemStack itemStack, final LivingEntity user) {
21
		return 1200;
22
	}
23
24
	@Override
25
	public ItemUseAnimation getUseAnimation(final ItemStack itemStack) {
26
		return ItemUseAnimation.SPYGLASS;
27
	}
28
29
	@Override
30
	public InteractionResult use(final Level level, final Player player, final InteractionHand hand) {
31
		player.playSound(SoundEvents.SPYGLASS_USE, 1.0F, 1.0F);
32
		player.awardStat(Stats.ITEM_USED.get(this));
33
		return ItemUtils.startUsingInstantly(level, player, hand);
34
	}
35
36
	@Override
37
	public ItemStack finishUsingItem(final ItemStack itemStack, final Level level, final LivingEntity entity) {
38
		this.stopUsing(entity);
39
		return itemStack;
40
	}
41
42
	@Override
43
	public boolean releaseUsing(final ItemStack itemStack, final Level level, final LivingEntity entity, final int remainingTime) {
44
		this.stopUsing(entity);
45
		return true;
46
	}
47
48
	private void stopUsing(final LivingEntity entity) {
49
		entity.playSound(SoundEvents.SPYGLASS_STOP_USING, 1.0F, 1.0F);
50
	}
51
}
52

Decompiled Minecraft 26.3 source of SpyglassItem (net/minecraft/world/item/SpyglassItem.java) with Mojang official mappings, stored verbatim on the site.