Search in sources :

Example 1 with ClientboundBlockBreakAckPacket

use of net.minecraft.network.protocol.game.ClientboundBlockBreakAckPacket in project SpongeCommon by SpongePowered.

the class ServerGamePacketListenerImplMixin method impl$callInteractBlockPrimaryEvent.

@Redirect(method = "handlePlayerAction", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;handleBlockBreakAction(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/protocol/game/ServerboundPlayerActionPacket$Action;Lnet/minecraft/core/Direction;I)V"))
public void impl$callInteractBlockPrimaryEvent(final ServerPlayerGameMode playerInteractionManager, final BlockPos p_225416_1_, final ServerboundPlayerActionPacket.Action p_225416_2_, final Direction p_225416_3_, final int p_225416_4_) {
    final BlockSnapshot snapshot = ((org.spongepowered.api.world.server.ServerWorld) (playerInteractionManager.level)).createSnapshot(VecHelper.toVector3i(p_225416_1_));
    final InteractBlockEvent.Primary event = SpongeCommonEventFactory.callInteractBlockEventPrimary(p_225416_2_, this.player, this.player.getItemInHand(InteractionHand.MAIN_HAND), snapshot, InteractionHand.MAIN_HAND, p_225416_3_);
    if (event instanceof Cancellable && ((Cancellable) event).isCancelled()) {
        this.player.connection.send(new ClientboundBlockBreakAckPacket(p_225416_1_, playerInteractionManager.level.getBlockState(p_225416_1_), p_225416_2_, false, "block action restricted"));
        this.impl$ignorePackets++;
    } else {
        if (p_225416_2_ == ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK) {
            if (!Objects.equals(((ServerPlayerGameModeAccessor) playerInteractionManager).accessor$destroyPos(), p_225416_1_)) {
                // prevents Mismatch in destroy block pos warning
                return;
            }
        }
        playerInteractionManager.handleBlockBreakAction(p_225416_1_, p_225416_2_, p_225416_3_, p_225416_4_);
        if (p_225416_2_ == ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK) {
            this.impl$ignorePackets++;
        }
    }
}
Also used : InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) ClientboundBlockBreakAckPacket(net.minecraft.network.protocol.game.ClientboundBlockBreakAckPacket) Cancellable(org.spongepowered.api.event.Cancellable) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ServerPlayerGameModeAccessor(org.spongepowered.common.accessor.server.level.ServerPlayerGameModeAccessor) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

ClientboundBlockBreakAckPacket (net.minecraft.network.protocol.game.ClientboundBlockBreakAckPacket)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 Cancellable (org.spongepowered.api.event.Cancellable)1 InteractBlockEvent (org.spongepowered.api.event.block.InteractBlockEvent)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 ServerPlayerGameModeAccessor (org.spongepowered.common.accessor.server.level.ServerPlayerGameModeAccessor)1