From d6fcd7a101a6ce41cff502aed20c6a093f074089 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Tue, 8 Jul 2025 21:59:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B3=A8=E5=86=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../item/ArtilleryIndicator.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/com/atsuishio/superbwarfare/item/ArtilleryIndicator.java b/src/main/java/com/atsuishio/superbwarfare/item/ArtilleryIndicator.java index 4b9009a45..20fe64dfc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/ArtilleryIndicator.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/ArtilleryIndicator.java @@ -1,6 +1,18 @@ package com.atsuishio.superbwarfare.item; +import net.minecraft.sounds.SoundEvents; +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.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemUtils; +import net.minecraft.world.item.UseAnim; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.ParametersAreNonnullByDefault; public class ArtilleryIndicator extends Item { @@ -8,6 +20,42 @@ public class ArtilleryIndicator extends Item { super(new Properties().stacksTo(1)); } + @Override + @ParametersAreNonnullByDefault + public int getUseDuration(ItemStack stack, LivingEntity entity) { + return 1200; + } + + @Override + public @NotNull UseAnim getUseAnimation(@NotNull ItemStack stack) { + return UseAnim.SPYGLASS; + } + + @Override + @ParametersAreNonnullByDefault + public @NotNull InteractionResultHolder use(Level worldIn, Player playerIn, InteractionHand handIn) { + ItemStack stack = playerIn.getItemInHand(handIn); + playerIn.playSound(SoundEvents.SPYGLASS_USE, 1.0F, 1.0F); + return ItemUtils.startUsingInstantly(worldIn, playerIn, handIn); + } + + @Override + @ParametersAreNonnullByDefault + public @NotNull ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) { + this.stopUsing(pLivingEntity); + return pStack; + } + + @Override + @ParametersAreNonnullByDefault + public void releaseUsing(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity, int pTimeCharged) { + this.stopUsing(pLivingEntity); + } + + private void stopUsing(LivingEntity pUser) { + pUser.playSound(SoundEvents.SPYGLASS_STOP_USING, 1.0F, 1.0F); + } + // @Override // public @NotNull InteractionResult useOn(UseOnContext pContext) { // ItemStack stack = pContext.getItemInHand();