Search in sources :

Example 1 with ServerPlayerGameModeBridge

use of org.spongepowered.common.bridge.server.level.ServerPlayerGameModeBridge 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;
}
Also used : InteractionResult(net.minecraft.world.InteractionResult) ServerPlayerGameModeBridge(org.spongepowered.common.bridge.server.level.ServerPlayerGameModeBridge) ItemStack(net.minecraft.world.item.ItemStack) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

InteractionResult (net.minecraft.world.InteractionResult)1 ItemStack (net.minecraft.world.item.ItemStack)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 ServerPlayerGameModeBridge (org.spongepowered.common.bridge.server.level.ServerPlayerGameModeBridge)1