Search in sources :

Example 1 with HandSwingC2SPacket

use of net.minecraft.network.packet.c2s.play.HandSwingC2SPacket in project BleachHack by BleachDrinker420.

the class WorldUtils method placeBlock.

public static boolean placeBlock(BlockPos pos, int slot, int rotateMode, boolean forceLegit, boolean airPlace, boolean swingHand) {
    if (!mc.world.isInBuildLimit(pos) || !isBlockEmpty(pos))
        return false;
    for (Direction d : Direction.values()) {
        if (!mc.world.isInBuildLimit(pos.offset(d)))
            continue;
        Block neighborBlock = mc.world.getBlockState(pos.offset(d)).getBlock();
        if (!airPlace && neighborBlock.getDefaultState().getMaterial().isReplaceable())
            continue;
        Vec3d vec = getLegitLookPos(pos.offset(d), d.getOpposite(), true, 5);
        if (vec == null) {
            if (forceLegit) {
                continue;
            }
            vec = getLegitLookPos(pos.offset(d), d.getOpposite(), false, 5);
            if (vec == null) {
                continue;
            }
        }
        int prevSlot = mc.player.getInventory().selectedSlot;
        Hand hand = InventoryUtils.selectSlot(slot);
        if (hand == null) {
            return false;
        }
        if (rotateMode == 1) {
            facePosPacket(vec.x, vec.y, vec.z);
        } else if (rotateMode == 2) {
            facePos(vec.x, vec.y, vec.z);
        }
        if (RIGHTCLICKABLE_BLOCKS.contains(neighborBlock)) {
            mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.PRESS_SHIFT_KEY));
        }
        if (swingHand) {
            mc.player.swingHand(hand);
        } else {
            mc.player.networkHandler.sendPacket(new HandSwingC2SPacket(hand));
        }
        mc.interactionManager.interactBlock(mc.player, mc.world, hand, new BlockHitResult(Vec3d.of(pos), airPlace ? d : d.getOpposite(), airPlace ? pos : pos.offset(d), false));
        if (RIGHTCLICKABLE_BLOCKS.contains(neighborBlock))
            mc.player.networkHandler.sendPacket(new ClientCommandC2SPacket(mc.player, Mode.RELEASE_SHIFT_KEY));
        mc.player.getInventory().selectedSlot = prevSlot;
        return true;
    }
    return false;
}
Also used : ClientCommandC2SPacket(net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket) HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket) LeavesBlock(net.minecraft.block.LeavesBlock) Block(net.minecraft.block.Block) PlantBlock(net.minecraft.block.PlantBlock) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) Hand(net.minecraft.util.Hand) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with HandSwingC2SPacket

use of net.minecraft.network.packet.c2s.play.HandSwingC2SPacket in project meteor-client by MeteorDevelopment.

the class BlockUtils method breakBlock.

/**
 * Needs to be used in {@link TickEvent.Pre}
 */
public static boolean breakBlock(BlockPos blockPos, boolean swing) {
    if (!canBreak(blockPos, mc.world.getBlockState(blockPos)))
        return false;
    // Creating new instance of block pos because minecraft assigns the parameter to a field and we don't want it to change when it has been stored in a field somewhere
    BlockPos pos = blockPos instanceof BlockPos.Mutable ? new BlockPos(blockPos) : blockPos;
    if (mc.interactionManager.isBreakingBlock())
        mc.interactionManager.updateBlockBreakingProgress(pos, Direction.UP);
    else
        mc.interactionManager.attackBlock(pos, Direction.UP);
    if (swing)
        mc.player.swingHand(Hand.MAIN_HAND);
    else
        mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
    breaking = true;
    breakingThisTick = true;
    return true;
}
Also used : HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with HandSwingC2SPacket

use of net.minecraft.network.packet.c2s.play.HandSwingC2SPacket in project meteor-client by MeteorDevelopment.

the class BlockUtils method place.

private static void place(BlockHitResult blockHitResult, Hand hand, boolean swing) {
    boolean wasSneaking = mc.player.input.sneaking;
    mc.player.input.sneaking = false;
    ActionResult result = mc.interactionManager.interactBlock(mc.player, mc.world, hand, blockHitResult);
    if (result.shouldSwingHand()) {
        if (swing)
            mc.player.swingHand(hand);
        else
            mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(hand));
    }
    mc.player.input.sneaking = wasSneaking;
}
Also used : ActionResult(net.minecraft.util.ActionResult) HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket)

Example 4 with HandSwingC2SPacket

use of net.minecraft.network.packet.c2s.play.HandSwingC2SPacket in project meteor-client by MeteorDevelopment.

the class AntiBed method sendStopPackets.

private void sendStopPackets(BlockPos blockPos) {
    mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, blockPos, Direction.UP));
    mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
}
Also used : PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket)

Example 5 with HandSwingC2SPacket

use of net.minecraft.network.packet.c2s.play.HandSwingC2SPacket in project Client by MatHax.

the class TNTAura method mine.

public void mine(BlockPos blockPos, FindItemResult item) {
    if (breakMode.get() == Mode.Normal) {
        InvUtils.swap(item.slot(), false);
        mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, blockPos, Direction.UP));
        mc.player.swingHand(Hand.MAIN_HAND);
        mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, blockPos, Direction.UP));
    }
    if (breakMode.get() == Mode.Instant) {
        InvUtils.swap(item.slot(), false);
        if (!startBreak) {
            mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, blockPos, Direction.UP));
            startBreak = true;
        }
        if (rotate.get())
            Rotations.rotate(Rotations.getYaw(blockPos), Rotations.getPitch(blockPos), () -> mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, blockPos, direction)));
        else
            mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, blockPos, direction));
        mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
    }
}
Also used : PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket)

Aggregations

HandSwingC2SPacket (net.minecraft.network.packet.c2s.play.HandSwingC2SPacket)16 PlayerActionC2SPacket (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)6 ActionResult (net.minecraft.util.ActionResult)4 BlockHitResult (net.minecraft.util.hit.BlockHitResult)4 BlockPos (net.minecraft.util.math.BlockPos)4 Vec3d (net.minecraft.util.math.Vec3d)4 Hand (net.minecraft.util.Hand)3 Direction (net.minecraft.util.math.Direction)3 Scaffold (dev.hypnotic.module.player.Scaffold)2 List (java.util.List)2 Entity (net.minecraft.entity.Entity)2 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)2 Lists (com.google.common.collect.Lists)1 FriendManager (dev.hypnotic.config.friends.FriendManager)1 EventTarget (dev.hypnotic.event.EventTarget)1 EventMotionUpdate (dev.hypnotic.event.events.EventMotionUpdate)1 EventRender3D (dev.hypnotic.event.events.EventRender3D)1 EventSendPacket (dev.hypnotic.event.events.EventSendPacket)1 PlayerMoveC2SPacketAccessor (dev.hypnotic.mixin.PlayerMoveC2SPacketAccessor)1 Category (dev.hypnotic.module.Category)1