Search in sources :

Example 1 with Position

use of net.minecraft.network.play.client.CPacketPlayer.Position in project nebula by Sxmurai.

the class Criticals method onPacket.

@SubscribeEvent
public void onPacket(PacketEvent event) {
    if (event.getPacket() instanceof CPacketUseEntity && event.getDirection().equals(Direction.OUTGOING)) {
        CPacketUseEntity packet = event.getPacket();
        if (packet.getAction().equals(Action.ATTACK) && packet.getEntityFromWorld(mc.world) instanceof EntityLivingBase && mc.player.onGround) {
            switch(mode.getValue()) {
                case BASIC:
                    mc.player.connection.sendPacket(new Position(mc.player.posX, mc.player.posY + 0.21, mc.player.posZ, false));
                    mc.player.connection.sendPacket(new Position(mc.player.posX, mc.player.posY, mc.player.posZ, false));
                    break;
                case STRICT:
                    // TODO still have no idea, its now only flagging for survival fly :/
                    break;
                case JUMP:
                    mc.player.jump();
                    break;
            }
        }
    }
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Position(net.minecraft.network.play.client.CPacketPlayer.Position) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with Position

use of net.minecraft.network.play.client.CPacketPlayer.Position in project nebula by Sxmurai.

the class PearlBait method onPacket.

@SubscribeEvent
public void onPacket(PacketEvent event) {
    if (event.getDirection().equals(Direction.INCOMING) && event.getPacket() instanceof SPacketSpawnObject) {
        SPacketSpawnObject packet = event.getPacket();
        if (packet.getType() == 65) {
            mc.world.playerEntities.stream().min(Comparator.comparingDouble((p) -> p.getDistance(packet.getX(), packet.getY(), packet.getZ()))).ifPresent((player) -> {
                if (player.equals(mc.player)) {
                    if (!mc.player.onGround) {
                        return;
                    }
                    // do not allow movement
                    mc.player.motionX = 0.0;
                    mc.player.motionY = 0.0;
                    mc.player.motionZ = 0.0;
                    mc.player.movementInput.moveForward = 0.0f;
                    mc.player.movementInput.moveStrafe = 0.0f;
                    // send rubberband packet
                    mc.player.connection.sendPacket(new Position(mc.player.posX, mc.player.posY + 1.0, mc.player.posZ, false));
                }
            });
        }
    }
}
Also used : Position(net.minecraft.network.play.client.CPacketPlayer.Position) SPacketSpawnObject(net.minecraft.network.play.server.SPacketSpawnObject) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with Position

use of net.minecraft.network.play.client.CPacketPlayer.Position in project nebula by Sxmurai.

the class MixinEntityPlayerSP method spoofUpdateWalkingPlayer.

/**
 * This is taken from minecraft's source and modified to allow us to spoof rotation / position values
 *
 * @see EntityPlayerSP#onUpdateWalkingPlayer()
 * @param event The motion update event marked as PRE
 */
private void spoofUpdateWalkingPlayer(MotionUpdateEvent event) {
    if (!event.getEra().equals(Era.PRE)) {
        return;
    }
    // sync sprint state with the server
    if (isSprinting() != serverSprintState) {
        serverSprintState = isSprinting();
        connection.sendPacket(new CPacketEntityAction(this, isSprinting() ? Action.START_SPRINTING : Action.STOP_SPRINTING));
    }
    // sync sneak state with the server
    if (isSneaking() != serverSneakState) {
        serverSneakState = isSneaking();
        connection.sendPacket(new CPacketEntityAction(this, isSneaking() ? Action.START_SNEAKING : Action.STOP_SNEAKING));
    }
    // if we are currently viewing this entity
    if (isCurrentViewEntity()) {
        // update our position update ticks
        ++positionUpdateTicks;
        // find differences in our x, y, and z values
        double diffX = event.getX() - lastReportedPosX;
        double diffY = event.getY() - lastReportedPosY;
        double diffZ = event.getZ() - lastReportedPosZ;
        // if we have moved at all
        boolean moved = diffX * diffX + diffY * diffY + diffZ * diffZ > 9.0E-4 || positionUpdateTicks >= 20;
        // differences in our yaw & pitch
        float diffYaw = event.getYaw() - lastReportedYaw;
        float diffPitch = event.getPitch() - lastReportedPitch;
        // if we have rotated at all
        boolean rotated = diffYaw != 0.0f || diffPitch != 0.0f;
        // if we are riding, we send a packet with our motion x and z and then -999 for our y value, with our rotations
        if (isRiding()) {
            connection.sendPacket(new PositionRotation(motionX, -999.0, motionZ, event.getYaw(), event.getPitch(), event.isOnGround()));
            moved = false;
        } else {
            // sync our position with the server
            if (moved && rotated) {
                connection.sendPacket(new PositionRotation(event.getX(), event.getY(), event.getZ(), event.getYaw(), event.getPitch(), event.isOnGround()));
            } else if (moved) {
                connection.sendPacket(new Position(event.getX(), event.getY(), event.getZ(), event.isOnGround()));
            } else if (rotated) {
                connection.sendPacket(new Rotation(event.getYaw(), event.getPitch(), event.isOnGround()));
            } else if (prevOnGround != onGround) {
                connection.sendPacket(new CPacketPlayer(onGround));
            }
        }
        // cache our current x, y, and z values and reset position update ticks
        if (moved) {
            lastReportedPosX = event.getX();
            lastReportedPosY = event.getY();
            lastReportedPosZ = event.getZ();
            positionUpdateTicks = 0;
        }
        // cache our current yaw and pitch
        if (rotated) {
            lastReportedYaw = event.getYaw();
            lastReportedPitch = event.getPitch();
        }
        // make sure we cache our onGround state as well
        prevOnGround = onGround;
    }
}
Also used : PositionRotation(net.minecraft.network.play.client.CPacketPlayer.PositionRotation) CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) Position(net.minecraft.network.play.client.CPacketPlayer.Position) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer) Rotation(net.minecraft.network.play.client.CPacketPlayer.Rotation) PositionRotation(net.minecraft.network.play.client.CPacketPlayer.PositionRotation)

Example 4 with Position

use of net.minecraft.network.play.client.CPacketPlayer.Position in project nebula by Sxmurai.

the class SelfFill method onActivated.

@Override
protected void onActivated() {
    BlockPos pos = new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ);
    // if we are already burrowed
    if (!mc.world.getCollisionBoxes(mc.player, new AxisAlignedBB(pos)).isEmpty()) {
        disable();
        return;
    }
    int slot = InventoryUtil.getSlot(InventorySpace.HOTBAR, (s) -> s.getItem() instanceof ItemBlock && ((ItemBlock) s.getItem()).getBlock().equals(mode.getValue().block));
    if (slot == -1) {
        disable();
        return;
    }
    EnumHand hand = slot == InventoryUtil.OFFHAND_SLOT ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
    int oldSlot = -1;
    if (hand.equals(EnumHand.MAIN_HAND)) {
        oldSlot = mc.player.inventory.currentItem;
        getNebula().getHotbarManager().sendSlotChange(slot, swap.getValue());
    }
    for (double offset : FAKE_JUMP) {
        mc.player.connection.sendPacket(new Position(mc.player.posX, pos.getY() + offset, mc.player.posZ, false));
    }
    getNebula().getInteractionManager().placeBlock(pos, hand, rotate.getValue(), swing.getValue());
    if (flag.getValue()) {
        mc.player.connection.sendPacket(new Position(mc.player.posX, pos.getY() + 2.3, mc.player.posZ, false));
    } else {
        if (!mc.world.getBlockState(pos).getMaterial().isReplaceable()) {
            mc.player.setPosition(pos.getX(), pos.getY() + 1.0, pos.getZ());
        }
    }
    if (oldSlot != -1) {
        getNebula().getHotbarManager().sendSlotChange(oldSlot, swap.getValue());
    }
    disable();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Position(net.minecraft.network.play.client.CPacketPlayer.Position) EnumHand(net.minecraft.util.EnumHand) BlockPos(net.minecraft.util.math.BlockPos) ItemBlock(net.minecraft.item.ItemBlock)

Aggregations

Position (net.minecraft.network.play.client.CPacketPlayer.Position)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 ItemBlock (net.minecraft.item.ItemBlock)1 CPacketEntityAction (net.minecraft.network.play.client.CPacketEntityAction)1 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)1 PositionRotation (net.minecraft.network.play.client.CPacketPlayer.PositionRotation)1 Rotation (net.minecraft.network.play.client.CPacketPlayer.Rotation)1 CPacketUseEntity (net.minecraft.network.play.client.CPacketUseEntity)1 SPacketSpawnObject (net.minecraft.network.play.server.SPacketSpawnObject)1 EnumHand (net.minecraft.util.EnumHand)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1