use of cope.cosmos.asm.mixins.accessor.ICPacketPlayer in project cosmos by momentumdevelopment.
the class CriticalsModule method onPacketSend.
@SubscribeEvent
public void onPacketSend(PacketEvent.PacketSendEvent event) {
// packet for attacks
if (event.getPacket() instanceof CPacketUseEntity && ((CPacketUseEntity) event.getPacket()).getAction().equals(CPacketUseEntity.Action.ATTACK)) {
// entity we attacked, if there was one
Entity attackEntity = ((CPacketUseEntity) event.getPacket()).getEntityFromWorld(mc.world);
// pause in liquid, ladders, blindness, webs, and air, since strict anticheats will flag as irregular movement
if (PlayerUtil.isInLiquid() || mc.player.isRiding() || mc.player.isPotionActive(MobEffects.BLINDNESS) || mc.player.isOnLadder() || !mc.player.onGround || ((IEntity) mc.player).getInWeb()) {
return;
}
// pause if attacking a crystal, helps compatability with AutoCrystal
if (attackEntity instanceof EntityEnderCrystal) {
return;
}
// critical hits on 32k's are insignificant
if (InventoryUtil.getHighestEnchantLevel() >= 1000) {
return;
}
// make sure the attacked entity exists
if (attackEntity != null && !attackEntity.isDead) {
// destroying a vehicle takes 5 hits -> regardless of damage
if (EntityUtil.isVehicleMob(attackEntity)) {
// attack 5 times
if (mc.getConnection() != null) {
for (int i = 0; i < 5; i++) {
mc.getConnection().getNetworkManager().sendPacket(new CPacketUseEntity(attackEntity));
mc.getConnection().getNetworkManager().sendPacket(new CPacketAnimation());
}
}
} else {
// send position packets after attack if we didn't modify them
if (!mode.getValue().equals(Mode.VANILLA) && !mode.getValue().equals(Mode.VANILLA_STRICT)) {
// attempt motion criticals
if (mode.getValue().equals(Mode.MOTION)) {
// jump
mc.player.motionY = motion.getValue();
// cancel the attack, we'll resend it next tick
event.setCanceled(true);
resendAttackPacket = (CPacketUseEntity) event.getPacket();
}
// if our timer has cleared the delay, then we are cleared to attempt another critical attack
if (criticalTimer.passedTime(delay.getValue().longValue(), Format.MILLISECONDS)) {
if (mode.getValue().equals(Mode.PACKET_STRICT)) {
// cancel the attack, we'll resend it after packets
event.setCanceled(true);
}
if (mode.getValue().equals(Mode.PACKET) || mode.getValue().equals(Mode.PACKET_STRICT)) {
// send packets for each of the offsets
for (float offset : mode.getValue().getOffsets()) {
// last packet on strict should confirm player position
mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.getEntityBoundingBox().minY + offset, mc.player.posZ, false));
}
// set our attacked entity
criticalEntity = attackEntity;
}
// resend attack packet
if (mode.getValue().equals(Mode.PACKET_STRICT)) {
if (mc.getConnection() != null) {
mc.getConnection().getNetworkManager().sendPacket(new CPacketUseEntity(attackEntity));
}
}
}
criticalTimer.resetTime();
// add critical effects to the hit
mc.player.onCriticalHit(attackEntity);
}
}
}
}
// packet for swing animation
if (event.getPacket() instanceof CPacketAnimation) {
if (mode.getValue().equals(Mode.MOTION)) {
// cancel our swing animation, we'll resend it next tick
event.setCanceled(true);
resendAnimationPacket = (CPacketAnimation) event.getPacket();
}
}
if (event.getPacket() instanceof CPacketPlayer) {
if (((ICPacketPlayer) event.getPacket()).isMoving()) {
if (criticalEntity != null) {
// make sure entity is hurt
if (criticalEntity.hurtResistantTime <= 16) {
criticalEntity = null;
return;
}
event.setCanceled(true);
// modify packets
if (mode.getValue().equals(Mode.VANILLA)) {
// all vanilla packets are off ground
((ICPacketPlayer) event.getPacket()).setOnGround(false);
// modify packets based on entity hurt time
switch(criticalEntity.hurtResistantTime) {
case 20:
((ICPacketPlayer) event.getPacket()).setY(mc.player.getEntityBoundingBox().minY + 0.5F);
break;
case 19:
case 17:
((ICPacketPlayer) event.getPacket()).setY(mc.player.getEntityBoundingBox().minY);
break;
case 18:
((ICPacketPlayer) event.getPacket()).setY(mc.player.getEntityBoundingBox().minY + 0.3F);
break;
}
} else // strict has dynamic onGround packets
if (mode.getValue().equals(Mode.VANILLA_STRICT)) {
// all vanilla packets are off ground
((ICPacketPlayer) event.getPacket()).setOnGround(false);
// modify packets based on entity hurt time
switch(criticalEntity.hurtResistantTime) {
case 19:
((ICPacketPlayer) event.getPacket()).setY(mc.player.getEntityBoundingBox().minY + 0.062602401692772F);
break;
case 18:
((ICPacketPlayer) event.getPacket()).setY(mc.player.getEntityBoundingBox().minY + 0.0726023996066094F);
break;
case 17:
((ICPacketPlayer) event.getPacket()).setY(mc.player.getEntityBoundingBox().minY);
break;
}
}
}
}
}
}
use of cope.cosmos.asm.mixins.accessor.ICPacketPlayer in project cosmos by momentumdevelopment.
the class RotationManager method onPacketSend.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPacketSend(PacketEvent.PacketSendEvent event) {
if (event.getPacket() instanceof CPacketPlayer) {
CPacketPlayer packet = (CPacketPlayer) event.getPacket();
// check if the packet has rotations
if (((ICPacketPlayer) packet).isRotating()) {
// update our server rotation
serverRotation.setYaw(packet.getYaw(0));
serverRotation.setPitch(packet.getPitch(0));
}
}
}
Aggregations