Search in sources :

Example 1 with EntityVelocityUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket in project FallingAttackFabric by hamusuke0323.

the class FallingAttackShockWave method damage.

private void damage(Entity target, float damageModifier) {
    if (target.isAttackable()) {
        if (!target.handleAttack(this.owner)) {
            float damageAmount = (float) this.owner.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
            float attackDamage;
            if (target instanceof LivingEntity) {
                attackDamage = EnchantmentHelper.getAttackDamage(this.sword, ((LivingEntity) target).getGroup());
            } else {
                attackDamage = EnchantmentHelper.getAttackDamage(this.sword, EntityGroup.DEFAULT);
            }
            if (damageAmount > 0.0F || attackDamage > 0.0F) {
                float distanceToTarget = (float) this.pos.distanceTo(target.getPos());
                int fallingAttackLevel = EnchantmentHelper.getLevel(FallingAttack.SHARPNESS_OF_FALLING_ATTACK, this.sword) + 1;
                fallingAttackLevel = MathHelper.clamp(fallingAttackLevel, 1, 255);
                attackDamage += this.fallingAttackDamageComputer.apply(distanceToTarget, fallingAttackLevel);
                this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.owner.getSoundCategory(), 1.0F, 1.0F);
                boolean bl3 = !this.owner.isClimbing() && !this.owner.isTouchingWater() && !this.owner.hasStatusEffect(StatusEffects.BLINDNESS) && !this.owner.hasVehicle() && target instanceof LivingEntity;
                if (bl3) {
                    damageAmount *= 1.5F;
                }
                damageAmount += attackDamage;
                float targetHealth = 0.0F;
                boolean fireAspectEnchanted = false;
                int fireAspectLevel = EnchantmentHelper.getLevel(Enchantments.FIRE_ASPECT, this.sword);
                if (target instanceof LivingEntity) {
                    targetHealth = ((LivingEntity) target).getHealth();
                    if (fireAspectLevel > 0 && !target.isOnFire()) {
                        fireAspectEnchanted = true;
                        target.setOnFireFor(1);
                    }
                }
                Vec3d vec3d = target.getVelocity();
                boolean tookDamage = target.damage(DamageSource.player(this.owner), damageAmount * damageModifier);
                if (tookDamage) {
                    float yaw = (float) -MathHelper.atan2(target.getX() - this.pos.getX(), target.getZ() - this.pos.getZ());
                    float strength = this.knockbackStrengthComputer.apply(distanceToTarget, fallingAttackLevel);
                    if (target instanceof LivingEntity) {
                        ((LivingEntity) target).takeKnockback(strength, MathHelper.sin(yaw), -MathHelper.cos(yaw));
                    } else {
                        target.addVelocity(-MathHelper.sin(yaw) * strength, 0.1D, MathHelper.cos(yaw) * strength);
                    }
                    this.owner.setVelocity(this.owner.getVelocity().multiply(0.6D, 1.0D, 0.6D));
                    this.owner.setSprinting(false);
                    if (target instanceof ServerPlayerEntity && target.velocityModified) {
                        ((ServerPlayerEntity) target).networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
                        target.velocityModified = false;
                        target.setVelocity(vec3d);
                    }
                    if (bl3) {
                        this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.owner.getSoundCategory(), 1.0F, 1.0F);
                        this.owner.addCritParticles(target);
                    }
                    if (attackDamage > 0.0F) {
                        this.owner.addEnchantedHitParticles(target);
                    }
                    this.owner.onAttacking(target);
                    if (target instanceof LivingEntity) {
                        float n = targetHealth - ((LivingEntity) target).getHealth();
                        this.owner.increaseStat(Stats.DAMAGE_DEALT, Math.round(n * 10.0F));
                        if (fireAspectLevel > 0) {
                            target.setOnFireFor(fireAspectLevel * 4);
                        }
                        if (n > 2.0F) {
                            int o = (int) ((double) n * 0.5D);
                            this.world.spawnParticles(ParticleTypes.DAMAGE_INDICATOR, target.getX(), target.getBodyY(0.5D), target.getZ(), o, 0.1D, 0.0D, 0.1D, 0.2D);
                        }
                    }
                } else {
                    this.world.playSound(null, this.owner.getX(), this.owner.getY(), this.owner.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.owner.getSoundCategory(), 1.0F, 1.0F);
                    if (fireAspectEnchanted) {
                        target.extinguish();
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) EntityVelocityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket)

Example 2 with EntityVelocityUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket in project BleachHack by BleachDrinker420.

the class NoVelocity method readPacket.

@BleachSubscribe
public void readPacket(EventPacket.Read event) {
    if (mc.player == null)
        return;
    if (event.getPacket() instanceof EntityVelocityUpdateS2CPacket && getSetting(0).asToggle().getState()) {
        EntityVelocityUpdateS2CPacket packet = (EntityVelocityUpdateS2CPacket) event.getPacket();
        if (packet.getId() == mc.player.getId()) {
            double velXZ = getSetting(0).asToggle().getChild(0).asSlider().getValue() / 100;
            double velY = getSetting(0).asToggle().getChild(1).asSlider().getValue() / 100;
            double pvelX = (packet.getVelocityX() / 8000d - mc.player.getVelocity().x) * velXZ;
            double pvelY = (packet.getVelocityY() / 8000d - mc.player.getVelocity().y) * velY;
            double pvelZ = (packet.getVelocityZ() / 8000d - mc.player.getVelocity().z) * velXZ;
            packet.velocityX = (int) (pvelX * 8000 + mc.player.getVelocity().x * 8000);
            packet.velocityY = (int) (pvelY * 8000 + mc.player.getVelocity().y * 8000);
            packet.velocityZ = (int) (pvelZ * 8000 + mc.player.getVelocity().z * 8000);
        }
    } else if (event.getPacket() instanceof ExplosionS2CPacket && getSetting(1).asToggle().getState()) {
        ExplosionS2CPacket packet = (ExplosionS2CPacket) event.getPacket();
        double velXZ = getSetting(1).asToggle().getChild(0).asSlider().getValue() / 100;
        double velY = getSetting(1).asToggle().getChild(1).asSlider().getValue() / 100;
        packet.playerVelocityX = (float) (packet.getPlayerVelocityX() * velXZ);
        packet.playerVelocityY = (float) (packet.getPlayerVelocityY() * velY);
        packet.playerVelocityZ = (float) (packet.getPlayerVelocityZ() * velXZ);
    }
}
Also used : ExplosionS2CPacket(net.minecraft.network.packet.s2c.play.ExplosionS2CPacket) EntityVelocityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 3 with EntityVelocityUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket in project MCDungeonsWeapons by chronosacaria.

the class PlayerAttackHelper method attackTargetEntityWitCurrentOffhandItemAsSuper.

public static void attackTargetEntityWitCurrentOffhandItemAsSuper(PlayerEntity player, Entity target) {
    if (target.isAttackable() && !target.handleAttack(player)) {
        // get attack damage attribute value
        float f_attackDamage = (float) player.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
        float h_enchantmentEffectsTargetBonus;
        if (target instanceof LivingEntity) {
            h_enchantmentEffectsTargetBonus = EnchantmentHelper.getAttackDamage(player.getOffHandStack(), ((LivingEntity) target).getGroup());
        } else {
            h_enchantmentEffectsTargetBonus = EnchantmentHelper.getAttackDamage(player.getOffHandStack(), EntityGroup.DEFAULT);
        }
        float i_cooledAttackStrength = player.getAttackCooldownProgress(0.5F);
        f_attackDamage *= 0.2F + i_cooledAttackStrength * i_cooledAttackStrength * 0.8F;
        h_enchantmentEffectsTargetBonus *= i_cooledAttackStrength;
        if (f_attackDamage > 0.0F || h_enchantmentEffectsTargetBonus > 0.0F) {
            boolean bl_flag = i_cooledAttackStrength > 0.9F;
            boolean bl2_flag1 = false;
            int j = 0;
            j = j + EnchantmentHelper.getKnockback(player);
            if (player.isSprinting() && bl_flag) {
                player.world.playSound(null, target.getX(), target.getY(), target.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1.0F, 1.0F);
                ++j;
                bl2_flag1 = true;
            }
            boolean bl3_flag2 = bl_flag && player.fallDistance > 0.0F && !player.isOnGround() && !player.isHoldingOntoLadder() && !player.isSwimming() && !player.hasStatusEffect(StatusEffects.BLINDNESS) && !player.hasVehicle() && target instanceof LivingEntity;
            bl3_flag2 = bl3_flag2 && !player.isSprinting();
            if (bl3_flag2) {
                f_attackDamage *= 1.5f;
            }
            f_attackDamage += h_enchantmentEffectsTargetBonus;
            boolean bl4 = false;
            double d = (double) (player.horizontalSpeed - player.prevHorizontalSpeed);
            if (bl_flag && !bl3_flag2 && !bl2_flag1 && player.isOnGround() && d < (double) player.getMovementSpeed()) {
                ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND);
                if (itemStack.getItem() instanceof SwordItem) {
                    bl4 = true;
                }
            }
            float k = 0.0F;
            boolean bl5 = false;
            int l = EnchantmentHelper.getFireAspect(player);
            if (target instanceof LivingEntity) {
                k = ((LivingEntity) target).getHealth();
                if (l > 0 && !target.isOnFire()) {
                    bl5 = true;
                    target.setOnFireFor(1);
                }
            }
            Vec3d vec3d = target.getVelocity();
            boolean bl6 = target.damage(DamageSource.player(player), f_attackDamage);
            if (bl6) {
                if (j > 0) {
                    if (target instanceof LivingEntity) {
                        ((LivingEntity) target).takeKnockback((float) j * 0.5F, (double) MathHelper.sin(player.yaw * 0.017453292F), (double) (-MathHelper.cos(player.yaw * 0.017453292F)));
                    } else {
                        target.addVelocity((double) (-MathHelper.sin(player.yaw * 0.017453292F) * (float) j * 0.5F), 0.1D, (double) (MathHelper.cos(player.yaw * 0.017453292F) * (float) j * 0.5F));
                    }
                    player.setVelocity(player.getVelocity().multiply(0.6D, 1.0D, 0.6D));
                    player.setSprinting(false);
                }
                if (bl4) {
                    float m = 1.0F + EnchantmentHelper.getSweepingMultiplier(player) * f_attackDamage;
                    List<LivingEntity> list = player.world.getNonSpectatingEntities(LivingEntity.class, target.getBoundingBox().expand(1.0D, 0.25D, 1.0D));
                    Iterator var19 = list.iterator();
                    label166: while (true) {
                        LivingEntity livingEntity;
                        do {
                            do {
                                do {
                                    do {
                                        if (!var19.hasNext()) {
                                            player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, player.getSoundCategory(), 1.0F, 1.0F);
                                            player.spawnSweepAttackParticles();
                                            break label166;
                                        }
                                        livingEntity = (LivingEntity) var19.next();
                                    } while (livingEntity == player);
                                } while (livingEntity == target);
                            } while (player.isTeammate(livingEntity));
                        } while (livingEntity instanceof ArmorStandEntity && ((ArmorStandEntity) livingEntity).isMarker());
                        if (player.squaredDistanceTo(livingEntity) < 9.0D) {
                            livingEntity.takeKnockback(0.4F, (double) MathHelper.sin(player.yaw * 0.017453292F), (double) (-MathHelper.cos(player.yaw * 0.017453292F)));
                            livingEntity.damage(DamageSource.player(player), m);
                        }
                    }
                }
                if (target instanceof ServerPlayerEntity && target.velocityModified) {
                    ((ServerPlayerEntity) target).networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
                    target.velocityModified = false;
                    target.setVelocity(vec3d);
                }
                if (bl3_flag2) {
                    player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, player.getSoundCategory(), 1.0F, 1.0F);
                    player.addCritParticles(target);
                }
                if (!bl3_flag2 && !bl4) {
                    if (bl_flag) {
                        player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, player.getSoundCategory(), 1.0F, 1.0F);
                    } else {
                        player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, player.getSoundCategory(), 1.0F, 1.0F);
                    }
                }
                if (h_enchantmentEffectsTargetBonus > 0.0F) {
                    player.addEnchantedHitParticles(target);
                }
                player.onAttacking(target);
                if (target instanceof LivingEntity) {
                    EnchantmentHelper.onUserDamaged((LivingEntity) target, player);
                }
                EnchantmentHelper.onTargetDamaged(player, target);
                ItemStack itemStack2 = player.getMainHandStack();
                Entity entity = target;
                if (target instanceof EnderDragonPart) {
                    entity = ((EnderDragonPart) target).owner;
                }
                if (!player.world.isClient && !itemStack2.isEmpty() && entity instanceof LivingEntity) {
                    itemStack2.postHit((LivingEntity) entity, player);
                    if (itemStack2.isEmpty()) {
                        player.setStackInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
                    }
                }
                if (target instanceof LivingEntity) {
                    float n = k - ((LivingEntity) target).getHealth();
                    player.increaseStat(Stats.DAMAGE_DEALT, Math.round(n * 10.0F));
                    if (l > 0) {
                        target.setOnFireFor(l * 4);
                    }
                    if (player.world instanceof ServerWorld && n > 2.0F) {
                        int o = (int) ((double) n * 0.5D);
                        ((ServerWorld) player.world).spawnParticles(ParticleTypes.DAMAGE_INDICATOR, target.getX(), target.getBodyY(0.5D), target.getZ(), o, 0.1D, 0.0D, 0.1D, 0.2D);
                    }
                }
                player.addExhaustion(0.1F);
            } else {
                player.world.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, player.getSoundCategory(), 1.0F, 1.0F);
                if (bl5) {
                    target.extinguish();
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) SwordItem(net.minecraft.item.SwordItem) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) EntityVelocityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket) LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.server.world.ServerWorld) EnderDragonPart(net.minecraft.entity.boss.dragon.EnderDragonPart) Iterator(java.util.Iterator) ItemStack(net.minecraft.item.ItemStack) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity)

Example 4 with EntityVelocityUpdateS2CPacket

use of net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket in project Hypnotic-Client by Hypnotic-Development.

the class Velocity method onReceivePacket.

@EventTarget
public void onReceivePacket(EventReceivePacket event) {
    if (mc.world == null || mc.player == null)
        return;
    this.setDisplayName("Velocity " + ColorUtils.gray + "H:" + horizontal.getValue() + " V:" + vertical.getValue());
    if (event.getPacket() instanceof EntityVelocityUpdateS2CPacket) {
        EntityVelocityUpdateS2CPacket velocity = (EntityVelocityUpdateS2CPacket) event.getPacket();
        if (velocity.getId() == mc.player.getId() && !mc.player.isTouchingWater()) {
            ReflectionHelper.setPrivateValue(EntityVelocityUpdateS2CPacket.class, velocity, (int) (velocity.getVelocityX() * (horizontal.getValue() * 0.01)), "velocityX", "field_12561");
            ReflectionHelper.setPrivateValue(EntityVelocityUpdateS2CPacket.class, velocity, (int) (velocity.getVelocityY() * (vertical.getValue() * 0.01)), "velocityY", "field_12562");
            ReflectionHelper.setPrivateValue(EntityVelocityUpdateS2CPacket.class, velocity, (int) (velocity.getVelocityZ() * (horizontal.getValue() * 0.01)), "velocityZ", "field_12563");
        }
    } else if (event.getPacket() instanceof ExplosionS2CPacket) {
        ExplosionS2CPacket velocity = (ExplosionS2CPacket) event.getPacket();
        ReflectionHelper.setPrivateValue(ExplosionS2CPacket.class, velocity, (int) (velocity.getPlayerVelocityX() * (horizontal.getValue() * 0.01)), "playerVelocityX", "field_12176");
        ReflectionHelper.setPrivateValue(ExplosionS2CPacket.class, velocity, (int) (velocity.getPlayerVelocityY() * (vertical.getValue() * 0.01)), "playerVelocityY", "field_12183");
        ReflectionHelper.setPrivateValue(ExplosionS2CPacket.class, velocity, (int) (velocity.getPlayerVelocityZ() * (horizontal.getValue() * 0.01)), "playerVelocityZ", "field_12182");
    }
}
Also used : ExplosionS2CPacket(net.minecraft.network.packet.s2c.play.ExplosionS2CPacket) EntityVelocityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket) EventTarget(dev.hypnotic.event.EventTarget)

Aggregations

EntityVelocityUpdateS2CPacket (net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket)4 LivingEntity (net.minecraft.entity.LivingEntity)2 ExplosionS2CPacket (net.minecraft.network.packet.s2c.play.ExplosionS2CPacket)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 Vec3d (net.minecraft.util.math.Vec3d)2 EventTarget (dev.hypnotic.event.EventTarget)1 Iterator (java.util.Iterator)1 Entity (net.minecraft.entity.Entity)1 EnderDragonPart (net.minecraft.entity.boss.dragon.EnderDragonPart)1 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 SwordItem (net.minecraft.item.SwordItem)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)1