|
17 | 17 | import net.minecraft.sounds.SoundSource; |
18 | 18 | import net.minecraft.tags.BlockTags; |
19 | 19 | import net.minecraft.world.InteractionHand; |
| 20 | +import net.minecraft.world.InteractionResult; |
20 | 21 | import net.minecraft.world.InteractionResultHolder; |
21 | 22 | import net.minecraft.world.entity.Entity; |
22 | 23 | import net.minecraft.world.entity.player.Player; |
23 | 24 | import net.minecraft.world.inventory.tooltip.TooltipComponent; |
24 | 25 | import net.minecraft.world.item.*; |
| 26 | +import net.minecraft.world.item.context.UseOnContext; |
25 | 27 | import net.minecraft.world.level.ClipContext; |
26 | 28 | import net.minecraft.world.level.Level; |
27 | 29 | import net.minecraft.world.level.block.entity.BlockEntity; |
@@ -99,22 +101,40 @@ public void appendHoverText(ItemStack stack, Level world, List<Component> stacks |
99 | 101 | } |
100 | 102 | } |
101 | 103 |
|
| 104 | + @NotNull |
102 | 105 | @Override |
103 | | - public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { |
| 106 | + public InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand) { |
104 | 107 | ItemStack stack = player.getItemInHand(hand); |
105 | | - if (player.isSecondaryUseActive() && hand == InteractionHand.MAIN_HAND) { |
106 | | - int tier = getLevel(stack); |
| 108 | + int tier = getLevel(stack); |
| 109 | + if (!player.isSecondaryUseActive() || tier == 0) { |
| 110 | + return InteractionResultHolder.pass(stack); |
| 111 | + } |
| 112 | + if (hand == InteractionHand.MAIN_HAND && !player.getOffhandItem().isEmpty()) { |
107 | 113 | BlockHitResult blockhitresult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.NONE); |
108 | 114 |
|
109 | | - if (tier != 0 && blockhitresult.getType() != HitResult.Type.BLOCK) { |
110 | | - setEnabled(stack, !isEnabled(stack)); |
111 | | - if (!level.isClientSide) { |
112 | | - level.playSound(null, player.getX(), player.getY(), player.getZ(), BotaniaSounds.terraPickMode, SoundSource.PLAYERS, 1F, 1F); |
113 | | - } |
114 | | - return InteractionResultHolder.sidedSuccess(stack, level.isClientSide()); |
| 115 | + if (blockhitresult.getType() == HitResult.Type.BLOCK) { |
| 116 | + return InteractionResultHolder.pass(stack); |
115 | 117 | } |
116 | 118 | } |
117 | | - return InteractionResultHolder.pass(stack); |
| 119 | + setEnabled(stack, !isEnabled(stack)); |
| 120 | + if (!level.isClientSide) { |
| 121 | + level.playSound(null, player.getX(), player.getY(), player.getZ(), BotaniaSounds.terraPickMode, SoundSource.PLAYERS, 1F, 1F); |
| 122 | + } |
| 123 | + return InteractionResultHolder.sidedSuccess(stack, level.isClientSide()); |
| 124 | + } |
| 125 | + |
| 126 | + @NotNull |
| 127 | + @Override |
| 128 | + public InteractionResult useOn(UseOnContext ctx) { |
| 129 | + Player player = ctx.getPlayer(); |
| 130 | + if (player == null) { |
| 131 | + return super.useOn(ctx); |
| 132 | + } else if (ctx.getHand() == InteractionHand.MAIN_HAND && !player.getOffhandItem().isEmpty()) { |
| 133 | + return InteractionResult.PASS; |
| 134 | + } |
| 135 | + return !player.isSecondaryUseActive() || getLevel(ctx.getItemInHand()) == 0 |
| 136 | + ? super.useOn(ctx) |
| 137 | + : InteractionResult.PASS; |
118 | 138 | } |
119 | 139 |
|
120 | 140 | @Override |
|
0 commit comments