use of net.minecraft.world.InteractionResult in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Tracker method tracker$checkState.
@Redirect(method = "handleUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItemOn(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;"))
private InteractionResult tracker$checkState(final ServerPlayerGameMode interactionManager, final ServerPlayer playerIn, final net.minecraft.world.level.Level worldIn, final ItemStack stack, final InteractionHand hand, final BlockHitResult rayTraceResult) {
final InteractionResult actionResult = interactionManager.useItemOn(this.player, worldIn, stack, hand, rayTraceResult);
if (PhaseTracker.getInstance().getPhaseContext().isEmpty()) {
return actionResult;
}
final PacketContext<?> context = ((PacketContext<?>) PhaseTracker.getInstance().getPhaseContext());
// If a plugin or mod has changed the item, avoid restoring
if (!context.getInteractItemChanged()) {
final ItemStack itemStack = ItemStackUtil.toNative(context.getItemUsed());
// Only do a restore if something actually changed. The client does an identity check ('==')
// to determine if it should continue using an itemstack. If we always resend the itemstack, we end up
// cancelling item usage (e.g. eating food) that occurs while targeting a block
final boolean isInteractionCancelled = ((ServerPlayerGameModeBridge) this.player.gameMode).bridge$isInteractBlockRightClickCancelled();
if (!ItemStack.matches(itemStack, this.player.getItemInHand(hand)) && isInteractionCancelled) {
PacketPhaseUtil.handlePlayerSlotRestore(this.player, itemStack, hand);
}
}
context.interactItemChanged(false);
((ServerPlayerGameModeBridge) this.player.gameMode).bridge$setInteractBlockRightClickCancelled(false);
return actionResult;
}
Aggregations