Search in sources :

Example 56 with InteractionResult

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;
}
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)56 ItemStack (net.minecraft.world.item.ItemStack)55 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)52 MyPet (de.Keyle.MyPet.api.entity.MyPet)52 InvocationTargetException (java.lang.reflect.InvocationTargetException)52 InteractionHand (net.minecraft.world.InteractionHand)52 Items (net.minecraft.world.item.Items)52 Level (net.minecraft.world.level.Level)52 ItemEntity (net.minecraft.world.entity.item.ItemEntity)50 Player (net.minecraft.world.entity.player.Player)50 EntityDataAccessor (net.minecraft.network.syncher.EntityDataAccessor)44 EntityDataSerializers (net.minecraft.network.syncher.EntityDataSerializers)44 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)44 MyPetApi (de.Keyle.MyPet.MyPetApi)40 Bukkit (org.bukkit.Bukkit)39 Util (de.Keyle.MyPet.api.Util)38 ServerLevel (net.minecraft.server.level.ServerLevel)38 Pair (com.mojang.datafixers.util.Pair)36 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)36 Arrays (java.util.Arrays)36