Search in sources :

Example 21 with PlayerActionC2SPacket

use of net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket in project meteor-rejects by AntiCope.

the class AutoExtinguish method extinguishFire.

private void extinguishFire(BlockPos blockPos) {
    mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, blockPos, net.minecraft.util.math.Direction.UP));
    mc.player.swingHand(Hand.MAIN_HAND);
    mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, blockPos, net.minecraft.util.math.Direction.UP));
}
Also used : PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)

Example 22 with PlayerActionC2SPacket

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

the class AutoTotem method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (holdingTotem && mc.player.getOffHandStack().getItem() != Items.TOTEM_OF_UNDYING) {
        delay = Math.max(getSetting(2).asSlider().getValueInt(), delay);
    }
    holdingTotem = mc.player.getOffHandStack().getItem() == Items.TOTEM_OF_UNDYING;
    if (delay > 0) {
        delay--;
        return;
    }
    if (holdingTotem || (!mc.player.getOffHandStack().isEmpty() && !getSetting(0).asToggle().getState())) {
        return;
    }
    // Cancel at all non-survival-inventory containers
    if (mc.player.playerScreenHandler == mc.player.currentScreenHandler) {
        for (int i = 9; i < 45; i++) {
            if (mc.player.getInventory().getStack(i >= 36 ? i - 36 : i).getItem() == Items.TOTEM_OF_UNDYING) {
                boolean itemInOffhand = !mc.player.getOffHandStack().isEmpty();
                mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, i, 0, SlotActionType.PICKUP, mc.player);
                mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, 45, 0, SlotActionType.PICKUP, mc.player);
                if (itemInOffhand)
                    mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, i, 0, SlotActionType.PICKUP, mc.player);
                delay = getSetting(1).asSlider().getValueInt();
                return;
            }
        }
    } else {
        // If the player is in another inventory, atleast check the hotbar for anything to swap
        for (int i = 0; i < 9; i++) {
            if (mc.player.getInventory().getStack(i).getItem() == Items.TOTEM_OF_UNDYING) {
                if (i != mc.player.getInventory().selectedSlot) {
                    mc.player.getInventory().selectedSlot = i;
                    mc.player.networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(i));
                }
                mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.DOWN));
                delay = getSetting(1).asSlider().getValueInt();
                return;
            }
        }
    }
}
Also used : PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 23 with PlayerActionC2SPacket

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

the class BowBot method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (!(mc.player.getMainHandStack().getItem() instanceof RangedWeaponItem) || !mc.player.isUsingItem())
        return;
    if (getSetting(0).asToggle().getState()) {
        if (mc.player.getMainHandStack().getItem() == Items.CROSSBOW && (float) mc.player.getItemUseTime() / (float) CrossbowItem.getPullTime(mc.player.getMainHandStack()) >= 1f) {
            mc.player.stopUsingItem();
            mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.UP));
            mc.interactionManager.interactItem(mc.player, mc.world, Hand.MAIN_HAND);
        } else if (mc.player.getMainHandStack().getItem() == Items.BOW && BowItem.getPullProgress(mc.player.getItemUseTime()) >= getSetting(0).asToggle().getChild(0).asSlider().getValueFloat()) {
            mc.player.stopUsingItem();
            mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Direction.UP));
        }
    }
    // Credit: https://github.com/Wurst-Imperium/Wurst7/blob/master/src/main/java/net/wurstclient/hacks/BowAimbotHack.java
    SettingToggle aimToggle = getSetting(1).asToggle();
    if (aimToggle.getState()) {
        LivingEntity target = Streams.stream(mc.world.getEntities()).filter(e -> EntityUtils.isAttackable(e, true) && (!aimToggle.getChild(3).asToggle().getState() || mc.player.canSee(e))).filter(e -> (aimToggle.getChild(0).asToggle().getState() && EntityUtils.isPlayer(e)) || (aimToggle.getChild(1).asToggle().getState() && EntityUtils.isMob(e)) || (aimToggle.getChild(2).asToggle().getState() && EntityUtils.isAnimal(e))).sorted(Comparator.comparing(mc.player::distanceTo)).map(e -> (LivingEntity) e).findFirst().orElse(null);
        if (target == null)
            return;
        // set velocity
        float velocity = (72000 - mc.player.getItemUseTimeLeft()) / 20F;
        velocity = Math.min(1f, (velocity * velocity + velocity * 2) / 3);
        // set position to aim at
        Vec3d newTargetVec = target.getPos().add(target.getVelocity());
        double d = mc.player.getEyePos().distanceTo(target.getBoundingBox().offset(target.getVelocity()).getCenter());
        double x = newTargetVec.x + (newTargetVec.x - target.getX()) * d - mc.player.getX();
        double y = newTargetVec.y + (newTargetVec.y - target.getY()) * d + target.getHeight() * 0.5 - mc.player.getY() - mc.player.getEyeHeight(mc.player.getPose());
        double z = newTargetVec.z + (newTargetVec.z - target.getZ()) * d - mc.player.getZ();
        // set yaw
        mc.player.setYaw((float) Math.toDegrees(Math.atan2(z, x)) - 90);
        // calculate needed pitch
        double hDistance = Math.sqrt(x * x + z * z);
        double hDistanceSq = hDistance * hDistance;
        float g = 0.006F;
        float velocitySq = velocity * velocity;
        float velocityPow4 = velocitySq * velocitySq;
        float neededPitch = (float) -Math.toDegrees(Math.atan((velocitySq - Math.sqrt(velocityPow4 - g * (g * hDistanceSq + 2 * y * velocitySq))) / (g * hDistance)));
        // set pitch
        if (Float.isNaN(neededPitch)) {
            WorldUtils.facePos(target.getX(), target.getY() + target.getHeight() / 2, target.getZ());
        } else {
            mc.player.setPitch(neededPitch);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) SettingSlider(org.bleachhack.setting.module.SettingSlider) EntityUtils(org.bleachhack.util.world.EntityUtils) ModuleCategory(org.bleachhack.module.ModuleCategory) CrossbowItem(net.minecraft.item.CrossbowItem) LivingEntity(net.minecraft.entity.LivingEntity) RangedWeaponItem(net.minecraft.item.RangedWeaponItem) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) Streams(com.google.common.collect.Streams) Module(org.bleachhack.module.Module) Action(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action) WorldUtils(org.bleachhack.util.world.WorldUtils) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d) Hand(net.minecraft.util.Hand) SettingToggle(org.bleachhack.setting.module.SettingToggle) BowItem(net.minecraft.item.BowItem) Comparator(java.util.Comparator) EventTick(org.bleachhack.event.events.EventTick) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket) SettingToggle(org.bleachhack.setting.module.SettingToggle) RangedWeaponItem(net.minecraft.item.RangedWeaponItem) Vec3d(net.minecraft.util.math.Vec3d) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 24 with PlayerActionC2SPacket

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

the class InstaAutoCity method doMine.

private void doMine() {
    --delayLeft;
    if (!mining) {
        if (rotate.get())
            Rotations.rotate(Rotations.getYaw(mineTarget), Rotations.getPitch(mineTarget));
        if (swing.get())
            mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
        else
            mc.player.swingHand(Hand.MAIN_HAND);
        mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, mineTarget, direction));
        mining = true;
    }
    if (delayLeft <= 0) {
        if (rotate.get())
            Rotations.rotate(Rotations.getYaw(mineTarget), Rotations.getPitch(mineTarget));
        mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
        mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, mineTarget, direction));
        delayLeft = delay.get();
    }
}
Also used : HandSwingC2SPacket(net.minecraft.network.packet.c2s.play.HandSwingC2SPacket) PlayerActionC2SPacket(net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)

Example 25 with PlayerActionC2SPacket

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

the class SelfProtect 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)

Aggregations

PlayerActionC2SPacket (net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket)32 BlockPos (net.minecraft.util.math.BlockPos)10 HandSwingC2SPacket (net.minecraft.network.packet.c2s.play.HandSwingC2SPacket)6 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)4 EventTarget (dev.hypnotic.event.EventTarget)3 EventHandler (mathax.client.eventbus.EventHandler)3 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)3 Items (net.minecraft.item.Items)3 Hand (net.minecraft.util.Hand)3 Direction (net.minecraft.util.math.Direction)3 Vec3d (net.minecraft.util.math.Vec3d)3 Comparator (java.util.Comparator)2 BlockState (net.minecraft.block.BlockState)2 LivingEntity (net.minecraft.entity.LivingEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 PlayerInteractBlockC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)2 UpdateSelectedSlotC2SPacket (net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket)2 BlockHitResult (net.minecraft.util.hit.BlockHitResult)2 Lists (com.google.common.collect.Lists)1