Search in sources :

Example 1 with SEntityVelocityPacket

use of net.minecraft.network.play.server.SEntityVelocityPacket in project Arclight by IzzelAliz.

the class PlayerEntityMixin method attackTargetEntityWithCurrentItem.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void attackTargetEntityWithCurrentItem(final Entity entity) {
    if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget((PlayerEntity) (Object) this, entity))
        return;
    if (entity.canBeAttackedWithItem() && !entity.hitByEntity((PlayerEntity) (Object) this)) {
        float f = (float) this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getValue();
        float f2;
        if (entity instanceof LivingEntity) {
            f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((LivingEntity) entity).getCreatureAttribute());
        } else {
            f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), CreatureAttribute.UNDEFINED);
        }
        final float f3 = this.getCooledAttackStrength(0.5f);
        f *= 0.2f + f3 * f3 * 0.8f;
        f2 *= f3;
        this.resetCooldown();
        if (f > 0.0f || f2 > 0.0f) {
            final boolean flag = f3 > 0.9f;
            boolean flag2 = false;
            final byte b0 = 0;
            int i = b0 + EnchantmentHelper.getKnockbackModifier((PlayerEntity) (Object) this);
            if (this.isSprinting() && flag) {
                this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0f, 1.0f);
                ++i;
                flag2 = true;
            }
            boolean flag3 = flag && this.fallDistance > 0.0f && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Effects.BLINDNESS) && !this.isPassenger() && entity instanceof LivingEntity;
            net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit((PlayerEntity) (Object) this, entity, flag3, flag3 ? 1.5F : 1.0F);
            flag3 = hitResult != null;
            if (flag3) {
                f *= hitResult.getDamageModifier();
            }
            f += f2;
            boolean flag4 = false;
            final double d0 = this.distanceWalkedModified - this.prevDistanceWalkedModified;
            if (flag && !flag3 && !flag2 && this.onGround && d0 < this.getAIMoveSpeed()) {
                final ItemStack itemstack = this.getHeldItem(Hand.MAIN_HAND);
                if (itemstack.getItem() instanceof SwordItem) {
                    flag4 = true;
                }
            }
            float f4 = 0.0f;
            boolean flag5 = false;
            final int j = EnchantmentHelper.getFireAspectModifier((PlayerEntity) (Object) this);
            if (entity instanceof LivingEntity) {
                f4 = ((LivingEntity) entity).getHealth();
                if (j > 0 && !entity.isBurning()) {
                    final EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 1);
                    Bukkit.getPluginManager().callEvent(combustEvent);
                    if (!combustEvent.isCancelled()) {
                        flag5 = true;
                        ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
                    }
                }
            }
            final Vec3d vec3d = entity.getMotion();
            final boolean flag6 = entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) (Object) this), f);
            if (flag6) {
                if (i > 0) {
                    if (entity instanceof LivingEntity) {
                        ((LivingEntity) entity).knockBack((PlayerEntity) (Object) this, i * 0.5f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
                    } else {
                        entity.addVelocity(-MathHelper.sin(this.rotationYaw * 0.017453292f) * i * 0.5f, 0.1, MathHelper.cos(this.rotationYaw * 0.017453292f) * i * 0.5f);
                    }
                    this.setMotion(this.getMotion().mul(0.6, 1.0, 0.6));
                    this.setSprinting(false);
                }
                if (flag4) {
                    final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((PlayerEntity) (Object) this) * f;
                    final List<LivingEntity> list = this.world.getEntitiesWithinAABB((Class<? extends LivingEntity>) LivingEntity.class, entity.getBoundingBox().grow(1.0, 0.25, 1.0));
                    for (final LivingEntity entityliving : list) {
                        if (entityliving != (Object) this && entityliving != entity && !this.isOnSameTeam(entityliving) && (!(entityliving instanceof ArmorStandEntity) || !((ArmorStandEntity) entityliving).hasMarker()) && this.getDistanceSq(entityliving) < 9.0 && entityliving.attackEntityFrom(((DamageSourceBridge) DamageSource.causePlayerDamage((PlayerEntity) (Object) this)).bridge$sweep(), f5)) {
                            entityliving.knockBack((PlayerEntity) (Object) this, 0.4f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
                        }
                    }
                    this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0f, 1.0f);
                    this.spawnSweepParticles();
                }
                if (entity instanceof ServerPlayerEntity && entity.velocityChanged) {
                    boolean cancelled = false;
                    final Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity();
                    final Vector velocity = CraftVector.toBukkit(vec3d);
                    final PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
                    Bukkit.getPluginManager().callEvent(event);
                    if (event.isCancelled()) {
                        cancelled = true;
                    } else if (!velocity.equals(event.getVelocity())) {
                        player.setVelocity(event.getVelocity());
                    }
                    if (!cancelled) {
                        ((ServerPlayerEntity) entity).connection.sendPacket(new SEntityVelocityPacket(entity));
                        entity.velocityChanged = false;
                        entity.setMotion(vec3d);
                    }
                }
                if (flag3) {
                    this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0f, 1.0f);
                    this.onCriticalHit(entity);
                }
                if (!flag3 && !flag4) {
                    if (flag) {
                        this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0f, 1.0f);
                    } else {
                        this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0f, 1.0f);
                    }
                }
                if (f2 > 0.0f) {
                    this.onEnchantmentCritical(entity);
                }
                this.setLastAttackedEntity(entity);
                if (entity instanceof LivingEntity) {
                    EnchantmentHelper.applyThornEnchantments((LivingEntity) entity, (PlayerEntity) (Object) this);
                }
                EnchantmentHelper.applyArthropodEnchantments((PlayerEntity) (Object) this, entity);
                final ItemStack itemstack2 = this.getHeldItemMainhand();
                Object object = entity;
                if (entity instanceof EnderDragonPartEntity) {
                    object = ((EnderDragonPartEntity) entity).dragon;
                }
                if (!this.world.isRemote && !itemstack2.isEmpty() && object instanceof LivingEntity) {
                    ItemStack copy = itemstack2.copy();
                    itemstack2.hitEntity((LivingEntity) object, (PlayerEntity) (Object) this);
                    if (itemstack2.isEmpty()) {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((PlayerEntity) (Object) this, copy, Hand.MAIN_HAND);
                        this.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY);
                    }
                }
                if (entity instanceof LivingEntity) {
                    final float f6 = f4 - ((LivingEntity) entity).getHealth();
                    this.addStat(Stats.DAMAGE_DEALT, Math.round(f6 * 10.0f));
                    if (j > 0) {
                        final EntityCombustByEntityEvent combustEvent2 = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), j * 4);
                        Bukkit.getPluginManager().callEvent(combustEvent2);
                        if (!combustEvent2.isCancelled()) {
                            ((EntityBridge) entity).bridge$setOnFire(combustEvent2.getDuration(), false);
                        }
                    }
                    if (this.world instanceof ServerWorld && f6 > 2.0f) {
                        final int k = (int) (f6 * 0.5);
                        ((ServerWorld) this.world).spawnParticle(ParticleTypes.DAMAGE_INDICATOR, entity.posX, entity.posY + entity.getHeight() * 0.5f, entity.posZ, k, 0.1, 0.0, 0.1, 0.2);
                    }
                }
                this.addExhaustion(0.1f);
            } else {
                this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0f, 1.0f);
                if (flag5) {
                    entity.extinguish();
                }
                if (this instanceof ServerPlayerEntityBridge) {
                    ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity().updateInventory();
                }
            }
        }
    }
}
Also used : PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) SwordItem(net.minecraft.item.SwordItem) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) ServerWorld(net.minecraft.world.server.ServerWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ArmorStandEntity(net.minecraft.entity.item.ArmorStandEntity) Vector(org.bukkit.util.Vector) CraftVector(org.bukkit.craftbukkit.v.util.CraftVector) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) DamageSourceBridge(io.izzel.arclight.common.bridge.util.DamageSourceBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) EnderDragonPartEntity(net.minecraft.entity.boss.dragon.EnderDragonPartEntity) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with SEntityVelocityPacket

use of net.minecraft.network.play.server.SEntityVelocityPacket in project Arclight by IzzelAliz.

the class TrackedEntityMixin method a.

public void a(final Consumer<IPacket<?>> consumer, final ServerPlayerEntity entityplayer) {
    if (this.trackedEntity.removed) {
        return;
    }
    final IPacket<?> packet = this.trackedEntity.createSpawnPacket();
    this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
    consumer.accept(packet);
    if (!this.trackedEntity.getDataManager().isEmpty()) {
        consumer.accept(new SEntityMetadataPacket(this.trackedEntity.getEntityId(), this.trackedEntity.getDataManager(), true));
    }
    boolean flag = this.sendVelocityUpdates;
    if (this.trackedEntity instanceof LivingEntity) {
        final AttributeMap attributemapserver = (AttributeMap) ((LivingEntity) this.trackedEntity).getAttributes();
        final Collection<IAttributeInstance> collection = attributemapserver.getWatchedAttributes();
        if (this.trackedEntity.getEntityId() == entityplayer.getEntityId()) {
            ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false);
        }
        if (!collection.isEmpty()) {
            consumer.accept(new SEntityPropertiesPacket(this.trackedEntity.getEntityId(), collection));
        }
        if (((LivingEntity) this.trackedEntity).isElytraFlying()) {
            flag = true;
        }
    }
    this.velocity = this.trackedEntity.getMotion();
    if (flag && !(packet instanceof SSpawnMobPacket)) {
        consumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
    }
    if (this.trackedEntity instanceof LivingEntity) {
        for (final EquipmentSlotType enumitemslot : EquipmentSlotType.values()) {
            final ItemStack itemstack = ((LivingEntity) this.trackedEntity).getItemStackFromSlot(enumitemslot);
            if (!itemstack.isEmpty()) {
                consumer.accept(new SEntityEquipmentPacket(this.trackedEntity.getEntityId(), enumitemslot, itemstack));
            }
        }
    }
    this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
    consumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) this.encodedRotationYawHead));
    if (this.trackedEntity instanceof LivingEntity) {
        final LivingEntity entityliving = (LivingEntity) this.trackedEntity;
        for (final EffectInstance mobeffect : entityliving.getActivePotionEffects()) {
            consumer.accept(new SPlayEntityEffectPacket(this.trackedEntity.getEntityId(), mobeffect));
        }
    }
    if (!this.trackedEntity.getPassengers().isEmpty()) {
        consumer.accept(new SSetPassengersPacket(this.trackedEntity));
    }
    if (this.trackedEntity.isPassenger()) {
        consumer.accept(new SSetPassengersPacket(this.trackedEntity.getRidingEntity()));
    }
    if (this.trackedEntity instanceof MobEntity) {
        MobEntity mobentity = (MobEntity) this.trackedEntity;
        if (mobentity.getLeashed()) {
            consumer.accept(new SMountEntityPacket(mobentity, mobentity.getLeashHolder()));
        }
    }
}
Also used : SEntityPropertiesPacket(net.minecraft.network.play.server.SEntityPropertiesPacket) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) SEntityHeadLookPacket(net.minecraft.network.play.server.SEntityHeadLookPacket) SSetPassengersPacket(net.minecraft.network.play.server.SSetPassengersPacket) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) SMountEntityPacket(net.minecraft.network.play.server.SMountEntityPacket) SPlayEntityEffectPacket(net.minecraft.network.play.server.SPlayEntityEffectPacket) SEntityEquipmentPacket(net.minecraft.network.play.server.SEntityEquipmentPacket) SSpawnMobPacket(net.minecraft.network.play.server.SSpawnMobPacket) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) AttributeMap(net.minecraft.entity.ai.attributes.AttributeMap) SEntityMetadataPacket(net.minecraft.network.play.server.SEntityMetadataPacket) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) MobEntity(net.minecraft.entity.MobEntity)

Example 3 with SEntityVelocityPacket

use of net.minecraft.network.play.server.SEntityVelocityPacket in project ChocolateQuestRepoured by TeamChocoQuest.

the class ItemUtil method attackTarget.

/**
 * Copied from {@link PlayerEntity#attackTargetEntityWithCurrentItem(Entity)}
 *
 * @param stack
 * @param player
 * @param targetEntity
 * @param fakeCrit                     If set to true and no real crit occurred it will spawn spell crit particles
 *                                     (vanilla: false)
 * @param damageBonus                  A flat damage bonus which affects the main attack and enchantments like sweeping
 *                                     edge (vanilla: 0.0F)
 * @param damageMultiplier             A damage multiplier which affects the main attack and enchantments like sweeping
 *                                     edge (vanilla: 1.0F)
 * @param sweepingEnabled              If set to false the player won't be able to make a sweeping attack with this item
 *                                     (vanilla: true)
 * @param sweepingDamage               The base amount of damage which the sweeping attack deals (vanilla: 1.0F)
 * @param sweepingDamageMultiplicative A damage bonus for sweeping attacks based on the main attack damage (vanilla:
 *                                     0.0F)
 * @param sweepingRangeHorizontal      (vanilla: 1.0D)
 * @param sweepingRangeVertical        (vanilla: 0.25D)
 * @param sweepingKnockback            (vanilla: 0.4F)
 */
public static void attackTarget(ItemStack stack, PlayerEntity player, Entity targetEntity, boolean fakeCrit, float damageBonus, float damageMultiplier, boolean sweepingEnabled, float sweepingDamage, float sweepingDamageMultiplicative, double sweepingRangeHorizontal, double sweepingRangeVertical, float sweepingKnockback) {
    // CQR: Replacement for ForgeHooks.onPlayerAttackTarget to prevent infinity loop
    if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, targetEntity))) {
        return;
    }
    if (targetEntity.isAttackable()) {
        if (!targetEntity.skipAttackInteraction(player)) {
            float f = (float) player.getAttribute(Attributes.ATTACK_DAMAGE).getValue();
            // CQR: Add flat damage bonus
            f = f + damageBonus;
            float f1;
            if (targetEntity instanceof LivingEntity) {
                f1 = EnchantmentHelper.getDamageBonus(player.getMainHandItem(), ((LivingEntity) targetEntity).getMobType());
            } else {
                f1 = EnchantmentHelper.getDamageBonus(player.getMainHandItem(), CreatureAttribute.UNDEFINED);
            }
            float f2 = player.getAttackStrengthScale(0.5F);
            f = f * (0.2F + f2 * f2 * 0.8F);
            f1 = f1 * f2;
            player.resetAttackStrengthTicker();
            if (f > 0.0F || f1 > 0.0F) {
                boolean flag = f2 > 0.9F;
                boolean flag1 = false;
                int i = 0;
                i = i + EnchantmentHelper.getKnockbackBonus(player);
                if (player.isSprinting() && flag) {
                    player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, player.getSoundSource(), 1.0F, 1.0F);
                    ++i;
                    flag1 = true;
                }
                boolean flag2 = flag && player.fallDistance > 0.0F && !player.isOnGround() && !player.onClimbable() && !player.isInWater() && !player.hasEffect(Effects.BLINDNESS) && !player.isPassenger() && targetEntity instanceof LivingEntity;
                flag2 = flag2 && !player.isSprinting();
                CriticalHitEvent hitResult = ForgeHooks.getCriticalHit(player, targetEntity, flag2, flag2 ? 1.5F : 1.0F);
                flag2 = hitResult != null;
                if (flag2) {
                    f *= hitResult.getDamageModifier();
                }
                f = f + f1;
                // CQR: Add damage bonus multiplier
                f = f * damageMultiplier;
                boolean flag3 = false;
                double d0 = player.walkDist - player.walkDistO;
                // CQR: Disable sweep attack when sweepingEnabled is false
                if (sweepingEnabled && flag && !flag2 && !flag1 && player.isOnGround() && d0 < player.getSpeed()) {
                    ItemStack itemstack = player.getItemInHand(Hand.MAIN_HAND);
                    if (itemstack.getItem() instanceof SwordItem) {
                        flag3 = true;
                    }
                }
                float f4 = 0.0F;
                boolean flag4 = false;
                int j = EnchantmentHelper.getFireAspect(player);
                if (targetEntity instanceof LivingEntity) {
                    f4 = ((LivingEntity) targetEntity).getHealth();
                    if (j > 0 && !targetEntity.isOnFire()) {
                        flag4 = true;
                        targetEntity.setSecondsOnFire(1);
                    }
                }
                Vector3d motion = player.getDeltaMovement();
                boolean flag5 = targetEntity.hurt(DamageSource.playerAttack(player), f);
                if (flag5) {
                    if (i > 0) {
                        if (targetEntity instanceof LivingEntity) {
                            ((LivingEntity) targetEntity).knockback(i * 0.5F, MathHelper.sin(player.yRot * 0.017453292F), (-MathHelper.cos(player.yRot * 0.017453292F)));
                        } else {
                            targetEntity.push(-MathHelper.sin(player.yRot * 0.017453292F) * i * 0.5F, 0.1D, MathHelper.cos(player.yRot * 0.017453292F) * i * 0.5F);
                        }
                        player.setDeltaMovement(player.getDeltaMovement().multiply(0.6, 1.0, 0.6));
                        player.setSprinting(false);
                    }
                    if (flag3) {
                        // CQR: Allow modification of sweeping damage
                        float f3 = sweepingDamage + sweepingDamageMultiplicative * f;
                        f3 = f3 + EnchantmentHelper.getSweepingDamageRatio(player) * f;
                        double entityReachDistanceSqr = getEntityReachDistanceSqr(player);
                        // CQR: Allow modification of sweeping hitbox
                        AxisAlignedBB aabb = targetEntity.getBoundingBox().expandTowards(sweepingRangeHorizontal, sweepingRangeVertical, sweepingRangeHorizontal);
                        for (LivingEntity entitylivingbase : player.level.getEntitiesOfClass(LivingEntity.class, aabb)) {
                            // CQR: Increase sweeping range when players reach distance is higher
                            if (entitylivingbase != player && entitylivingbase != targetEntity && !player.isAlliedTo(entitylivingbase) && player.distanceToSqr(entitylivingbase) < entityReachDistanceSqr) {
                                // CQR: Allow modification of sweeping knockback strength
                                entitylivingbase.knockback(sweepingKnockback, MathHelper.sin(player.yRot * 0.017453292F), (-MathHelper.cos(player.yRot * 0.017453292F)));
                                entitylivingbase.hurt(DamageSource.playerAttack(player), f3);
                            }
                        }
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, player.getSoundSource(), 1.0F, 1.0F);
                        player.sweepAttack();
                    }
                    if (targetEntity instanceof ServerPlayerEntity && targetEntity.hurtMarked) {
                        ((ServerPlayerEntity) targetEntity).connection.send(new SEntityVelocityPacket(targetEntity));
                        targetEntity.hurtMarked = false;
                        targetEntity.setDeltaMovement(motion);
                    }
                    if (flag2) {
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, player.getSoundSource(), 1.0F, 1.0F);
                        player.crit(targetEntity);
                    } else if (fakeCrit) {
                        // CQR: Allow fake crits to happen
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, player.getSoundSource(), 1.0F, 1.2F);
                        player.crit(targetEntity);
                    }
                    if (!flag2 && !fakeCrit && !flag3) {
                        if (flag) {
                            player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, player.getSoundSource(), 1.0F, 1.0F);
                        } else {
                            player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, player.getSoundSource(), 1.0F, 1.0F);
                        }
                    }
                    if (f1 > 0.0F) {
                        player.magicCrit(targetEntity);
                    }
                    player.setLastHurtMob(targetEntity);
                    if (targetEntity instanceof LivingEntity) {
                        EnchantmentHelper.doPostHurtEffects((LivingEntity) targetEntity, player);
                    }
                    EnchantmentHelper.doPostDamageEffects(player, targetEntity);
                    ItemStack itemstack1 = player.getMainHandItem();
                    Entity entity = targetEntity;
                    if (targetEntity instanceof PartEntity) {
                        Entity ientitymultipart = ((PartEntity) targetEntity).getParent();
                        if (ientitymultipart instanceof LivingEntity) {
                            entity = (LivingEntity) ientitymultipart;
                        }
                    }
                    if (!itemstack1.isEmpty() && entity instanceof LivingEntity) {
                        ItemStack beforeHitCopy = itemstack1.copy();
                        itemstack1.hurtEnemy((LivingEntity) entity, player);
                        if (itemstack1.isEmpty()) {
                            ForgeEventFactory.onPlayerDestroyItem(player, beforeHitCopy, Hand.MAIN_HAND);
                            player.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
                        }
                    }
                    if (targetEntity instanceof LivingEntity) {
                        float f5 = f4 - ((LivingEntity) targetEntity).getHealth();
                        player.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
                        if (j > 0) {
                            targetEntity.setSecondsOnFire(j * 4);
                        }
                        if (player.level instanceof ServerWorld && f5 > 2.0F) {
                            int k = (int) (f5 * 0.5D);
                            ((ServerWorld) targetEntity.level).sendParticles(ParticleTypes.DAMAGE_INDICATOR, targetEntity.getX(), targetEntity.getY(0.5D), targetEntity.getZ(), k, 0.1D, 0.0D, 0.1D, 0.2D);
                        }
                    }
                    player.causeFoodExhaustion(0.1F);
                } else {
                    player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, player.getSoundSource(), 1.0F, 1.0F);
                    if (flag4) {
                        targetEntity.clearFire();
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) PartEntity(net.minecraftforge.entity.PartEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PartEntity(net.minecraftforge.entity.PartEntity) SwordItem(net.minecraft.item.SwordItem) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) ServerWorld(net.minecraft.world.server.ServerWorld) AttackEntityEvent(net.minecraftforge.event.entity.player.AttackEntityEvent) CriticalHitEvent(net.minecraftforge.event.entity.player.CriticalHitEvent) Vector3d(net.minecraft.util.math.vector.Vector3d) ItemStack(net.minecraft.item.ItemStack)

Example 4 with SEntityVelocityPacket

use of net.minecraft.network.play.server.SEntityVelocityPacket in project Arclight by IzzelAliz.

the class TrackedEntityMixin method tick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    List<Entity> list = this.trackedEntity.getPassengers();
    if (!list.equals(this.passengers)) {
        this.passengers = list;
        this.sendPacket(new SSetPassengersPacket(this.trackedEntity));
    }
    if (this.trackedEntity instanceof ItemFrameEntity) {
        ItemFrameEntity entityitemframe = (ItemFrameEntity) this.trackedEntity;
        ItemStack itemstack = entityitemframe.getDisplayedItem();
        if (this.updateCounter % 10 == 0 && itemstack.getItem() instanceof FilledMapItem) {
            MapData worldmap = FilledMapItem.getMapData(itemstack, this.world);
            for (ServerPlayerEntity entityplayer : this.trackedPlayers) {
                worldmap.updateVisiblePlayers(entityplayer, itemstack);
                IPacket<?> packet = ((FilledMapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.world, entityplayer);
                if (packet != null) {
                    entityplayer.connection.sendPacket(packet);
                }
            }
        }
        this.sendMetadata();
    }
    if (this.updateCounter % this.updateFrequency == 0 || this.trackedEntity.isAirBorne || this.trackedEntity.getDataManager().isDirty()) {
        if (this.trackedEntity.isPassenger()) {
            int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
            int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
            boolean flag = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
            if (flag) {
                this.packetConsumer.accept(new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround));
                this.encodedRotationYaw = i;
                this.encodedRotationPitch = j;
            }
            this.updateEncodedPosition();
            this.sendMetadata();
            this.riding = true;
        } else {
            ++this.ticksSinceAbsoluteTeleport;
            int i = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0f / 360.0f);
            int j = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0f / 360.0f);
            Vec3d vec3d = this.trackedEntity.getPositionVec().subtract(SEntityPacket.func_218744_a(this.encodedPosX, this.encodedPosY, this.encodedPosZ));
            boolean flag2 = vec3d.lengthSquared() >= 7.62939453125E-6;
            IPacket<?> packet2 = null;
            boolean flag3 = flag2 || this.updateCounter % 60 == 0;
            boolean flag4 = Math.abs(i - this.encodedRotationYaw) >= 1 || Math.abs(j - this.encodedRotationPitch) >= 1;
            if (flag3) {
                this.updateEncodedPosition();
            }
            if (flag4) {
                this.encodedRotationYaw = i;
                this.encodedRotationPitch = j;
            }
            if (this.updateCounter > 0 || this.trackedEntity instanceof AbstractArrowEntity) {
                long k = SEntityPacket.func_218743_a(vec3d.x);
                long l = SEntityPacket.func_218743_a(vec3d.y);
                long i2 = SEntityPacket.func_218743_a(vec3d.z);
                boolean flag5 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i2 < -32768L || i2 > 32767L;
                if (!flag5 && this.ticksSinceAbsoluteTeleport <= 400 && !this.riding && this.onGround == this.trackedEntity.onGround) {
                    if ((!flag3 || !flag4) && !(this.trackedEntity instanceof AbstractArrowEntity)) {
                        if (flag3) {
                            packet2 = new SEntityPacket.RelativeMovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, this.trackedEntity.onGround);
                        } else if (flag4) {
                            packet2 = new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i, (byte) j, this.trackedEntity.onGround);
                        }
                    } else {
                        packet2 = new SEntityPacket.MovePacket(this.trackedEntity.getEntityId(), (short) k, (short) l, (short) i2, (byte) i, (byte) j, this.trackedEntity.onGround);
                    }
                } else {
                    this.onGround = this.trackedEntity.onGround;
                    this.ticksSinceAbsoluteTeleport = 0;
                    packet2 = new SEntityTeleportPacket(this.trackedEntity);
                }
            }
            if ((this.sendVelocityUpdates || this.trackedEntity.isAirBorne || (this.trackedEntity instanceof LivingEntity && ((LivingEntity) this.trackedEntity).isElytraFlying())) && this.updateCounter > 0) {
                Vec3d vec3d2 = this.trackedEntity.getMotion();
                double d0 = vec3d2.squareDistanceTo(this.velocity);
                if (d0 > 1.0E-7 || (d0 > 0.0 && vec3d2.lengthSquared() == 0.0)) {
                    this.velocity = vec3d2;
                    this.packetConsumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity));
                }
            }
            if (packet2 != null) {
                this.packetConsumer.accept(packet2);
            }
            this.sendMetadata();
            this.riding = false;
        }
        int i = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f);
        if (Math.abs(i - this.encodedRotationYawHead) >= 1) {
            this.packetConsumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) i));
            this.encodedRotationYawHead = i;
        }
        this.trackedEntity.isAirBorne = false;
    }
    ++this.updateCounter;
    if (this.trackedEntity.velocityChanged) {
        boolean cancelled = false;
        if (this.trackedEntity instanceof ServerPlayerEntity) {
            Player player = ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity();
            Vector velocity = player.getVelocity();
            PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                cancelled = true;
            } else if (!velocity.equals(event.getVelocity())) {
                player.setVelocity(event.getVelocity());
            }
        }
        if (!cancelled) {
            this.sendPacket(new SEntityVelocityPacket(this.trackedEntity));
        }
        this.trackedEntity.velocityChanged = false;
    }
}
Also used : AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) TrackedEntity(net.minecraft.world.TrackedEntity) PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) SEntityHeadLookPacket(net.minecraft.network.play.server.SEntityHeadLookPacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) MapData(net.minecraft.world.storage.MapData) FilledMapItem(net.minecraft.item.FilledMapItem) SEntityTeleportPacket(net.minecraft.network.play.server.SEntityTeleportPacket) Vector(org.bukkit.util.Vector) Player(org.bukkit.entity.Player) SEntityPacket(net.minecraft.network.play.server.SEntityPacket) SEntityHeadLookPacket(net.minecraft.network.play.server.SEntityHeadLookPacket) SSetPassengersPacket(net.minecraft.network.play.server.SSetPassengersPacket) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) ItemFrameEntity(net.minecraft.entity.item.ItemFrameEntity) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

LivingEntity (net.minecraft.entity.LivingEntity)4 ItemStack (net.minecraft.item.ItemStack)4 SEntityVelocityPacket (net.minecraft.network.play.server.SEntityVelocityPacket)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 Entity (net.minecraft.entity.Entity)2 MobEntity (net.minecraft.entity.MobEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 SwordItem (net.minecraft.item.SwordItem)2 SEntityHeadLookPacket (net.minecraft.network.play.server.SEntityHeadLookPacket)2 SSetPassengersPacket (net.minecraft.network.play.server.SSetPassengersPacket)2 Vec3d (net.minecraft.util.math.Vec3d)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 Player (org.bukkit.entity.Player)2 PlayerVelocityEvent (org.bukkit.event.player.PlayerVelocityEvent)2 Vector (org.bukkit.util.Vector)2 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)1 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)1 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)1 DamageSourceBridge (io.izzel.arclight.common.bridge.util.DamageSourceBridge)1