package net.minecraft.world.entity.projectile;

import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.item.ItemStack;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.CompoundTag;
import java.util.Arrays;
import java.util.Collection;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.damagesource.DamageSource;
import com.google.common.collect.Lists;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.phys.BlockHitResult;
import java.util.Iterator;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EntityType;
import java.util.List;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import net.minecraft.sounds.SoundEvent;
import javax.annotation.Nullable;
import net.minecraft.world.level.block.state.BlockState;
import java.util.UUID;
import java.util.Optional;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.world.entity.Entity;

public abstract class AbstractArrow extends Entity implements Projectile {
    private static final EntityDataAccessor<Byte> ID_FLAGS;
    protected static final EntityDataAccessor<Optional<UUID>> DATA_OWNERUUID_ID;
    private static final EntityDataAccessor<Byte> PIERCE_LEVEL;
    @Nullable
    private BlockState lastState;
    protected boolean inGround;
    protected int inGroundTime;
    public Pickup pickup;
    public int shakeTime;
    public UUID ownerUUID;
    private int life;
    private int flightTime;
    private double baseDamage;
    private int knockback;
    private SoundEvent soundEvent;
    private IntOpenHashSet piercingIgnoreEntityIds;
    private List<Entity> piercedAndKilledEntities;
    
    protected AbstractArrow(final EntityType<? extends AbstractArrow> aku, final Level bjw) {
        super(aku, bjw);
        this.pickup = Pickup.DISALLOWED;
        this.baseDamage = 2.0;
        this.soundEvent = this.getDefaultHitGroundSoundEvent();
    }
    
    protected AbstractArrow(final EntityType<? extends AbstractArrow> aku, final double double2, final double double3, final double double4, final Level bjw) {
        this(aku, bjw);
        this.setPos(double2, double3, double4);
    }
    
    protected AbstractArrow(final EntityType<? extends AbstractArrow> aku, final LivingEntity akz, final Level bjw) {
        this(aku, akz.getX(), akz.getEyeY() - 0.10000000149011612, akz.getZ(), bjw);
        this.setOwner(akz);
        if (akz instanceof Player) {
            this.pickup = Pickup.ALLOWED;
        }
    }
    
    public void setSoundEvent(final SoundEvent aah) {
        this.soundEvent = aah;
    }
    
    @Override
    public boolean shouldRenderAtSqrDistance(final double double1) {
        double double2 = this.getBoundingBox().getSize() * 10.0;
        if (Double.isNaN(double2)) {
            double2 = 1.0;
        }
        double2 *= 64.0 * getViewScale();
        return double1 < double2 * double2;
    }
    
    @Override
    protected void defineSynchedData() {
        this.entityData.<Byte>define(AbstractArrow.ID_FLAGS, (Byte)0);
        this.entityData.<Optional<UUID>>define(AbstractArrow.DATA_OWNERUUID_ID, Optional.<UUID>empty());
        this.entityData.<Byte>define(AbstractArrow.PIERCE_LEVEL, (Byte)0);
    }
    
    public void shootFromRotation(final Entity akq, final float float2, final float float3, final float float4, final float float5, final float float6) {
        final float float7 = -Mth.sin(float3 * 0.017453292f) * Mth.cos(float2 * 0.017453292f);
        final float float8 = -Mth.sin(float2 * 0.017453292f);
        final float float9 = Mth.cos(float3 * 0.017453292f) * Mth.cos(float2 * 0.017453292f);
        this.shoot(float7, float8, float9, float5, float6);
        this.setDeltaMovement(this.getDeltaMovement().add(akq.getDeltaMovement().x, akq.onGround ? 0.0 : akq.getDeltaMovement().y, akq.getDeltaMovement().z));
    }
    
    @Override
    public void shoot(final double double1, final double double2, final double double3, final float float4, final float float5) {
        final Vec3 cvl10 = new Vec3(double1, double2, double3).normalize().add(this.random.nextGaussian() * 0.007499999832361937 * float5, this.random.nextGaussian() * 0.007499999832361937 * float5, this.random.nextGaussian() * 0.007499999832361937 * float5).scale(float4);
        this.setDeltaMovement(cvl10);
        final float float6 = Mth.sqrt(Entity.getHorizontalDistanceSqr(cvl10));
        this.yRot = (float)(Mth.atan2(cvl10.x, cvl10.z) * 57.2957763671875);
        this.xRot = (float)(Mth.atan2(cvl10.y, float6) * 57.2957763671875);
        this.yRotO = this.yRot;
        this.xRotO = this.xRot;
        this.life = 0;
    }
    
    @Override
    public void lerpTo(final double double1, final double double2, final double double3, final float float4, final float float5, final int integer, final boolean boolean7) {
        this.setPos(double1, double2, double3);
        this.setRot(float4, float5);
    }
    
    @Override
    public void lerpMotion(final double double1, final double double2, final double double3) {
        this.setDeltaMovement(double1, double2, double3);
        if (this.xRotO == 0.0f && this.yRotO == 0.0f) {
            final float float8 = Mth.sqrt(double1 * double1 + double3 * double3);
            this.xRot = (float)(Mth.atan2(double2, float8) * 57.2957763671875);
            this.yRot = (float)(Mth.atan2(double1, double3) * 57.2957763671875);
            this.xRotO = this.xRot;
            this.yRotO = this.yRot;
            this.moveTo(this.getX(), this.getY(), this.getZ(), this.yRot, this.xRot);
            this.life = 0;
        }
    }
    
    @Override
    public void tick() {
        super.tick();
        final boolean boolean2 = this.isNoPhysics();
        Vec3 cvl3 = this.getDeltaMovement();
        if (this.xRotO == 0.0f && this.yRotO == 0.0f) {
            final float float4 = Mth.sqrt(Entity.getHorizontalDistanceSqr(cvl3));
            this.yRot = (float)(Mth.atan2(cvl3.x, cvl3.z) * 57.2957763671875);
            this.xRot = (float)(Mth.atan2(cvl3.y, float4) * 57.2957763671875);
            this.yRotO = this.yRot;
            this.xRotO = this.xRot;
        }
        final BlockPos fk4 = new BlockPos(this);
        final BlockState byj5 = this.level.getBlockState(fk4);
        if (!byj5.isAir() && !boolean2) {
            final VoxelShape cwf6 = byj5.getCollisionShape(this.level, fk4);
            if (!cwf6.isEmpty()) {
                final Vec3 cvl4 = this.position();
                for (final AABB cvf9 : cwf6.toAabbs()) {
                    if (cvf9.move(fk4).contains(cvl4)) {
                        this.inGround = true;
                        break;
                    }
                }
            }
        }
        if (this.shakeTime > 0) {
            --this.shakeTime;
        }
        if (this.isInWaterOrRain()) {
            this.clearFire();
        }
        if (this.inGround && !boolean2) {
            if (this.lastState != byj5 && this.level.noCollision(this.getBoundingBox().inflate(0.06))) {
                this.inGround = false;
                this.setDeltaMovement(cvl3.multiply(this.random.nextFloat() * 0.2f, this.random.nextFloat() * 0.2f, this.random.nextFloat() * 0.2f));
                this.life = 0;
                this.flightTime = 0;
            }
            else if (!this.level.isClientSide) {
                this.tickDespawn();
            }
            ++this.inGroundTime;
            return;
        }
        this.inGroundTime = 0;
        ++this.flightTime;
        final Vec3 cvl5 = this.position();
        Vec3 cvl4 = cvl5.add(cvl3);
        HitResult cvi8 = this.level.clip(new ClipContext(cvl5, cvl4, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this));
        if (cvi8.getType() != HitResult.Type.MISS) {
            cvl4 = cvi8.getLocation();
        }
        while (!this.removed) {
            EntityHitResult cvh9 = this.findHitEntity(cvl5, cvl4);
            if (cvh9 != null) {
                cvi8 = cvh9;
            }
            if (cvi8 != null && cvi8.getType() == HitResult.Type.ENTITY) {
                final Entity akq10 = ((EntityHitResult)cvi8).getEntity();
                final Entity akq11 = this.getOwner();
                if (akq10 instanceof Player && akq11 instanceof Player && !((Player)akq11).canHarmPlayer((Player)akq10)) {
                    cvi8 = null;
                    cvh9 = null;
                }
            }
            if (cvi8 != null && !boolean2) {
                this.onHit(cvi8);
                this.hasImpulse = true;
            }
            if (cvh9 == null) {
                break;
            }
            if (this.getPierceLevel() <= 0) {
                break;
            }
            cvi8 = null;
        }
        cvl3 = this.getDeltaMovement();
        final double double9 = cvl3.x;
        final double double10 = cvl3.y;
        final double double11 = cvl3.z;
        if (this.isCritArrow()) {
            for (int integer15 = 0; integer15 < 4; ++integer15) {
                this.level.addParticle(ParticleTypes.CRIT, this.getX() + double9 * integer15 / 4.0, this.getY() + double10 * integer15 / 4.0, this.getZ() + double11 * integer15 / 4.0, -double9, -double10 + 0.2, -double11);
            }
        }
        final double double12 = this.getX() + double9;
        final double double13 = this.getY() + double10;
        final double double14 = this.getZ() + double11;
        final float float5 = Mth.sqrt(Entity.getHorizontalDistanceSqr(cvl3));
        if (boolean2) {
            this.yRot = (float)(Mth.atan2(-double9, -double11) * 57.2957763671875);
        }
        else {
            this.yRot = (float)(Mth.atan2(double9, double11) * 57.2957763671875);
        }
        this.xRot = (float)(Mth.atan2(double10, float5) * 57.2957763671875);
        while (this.xRot - this.xRotO < -180.0f) {
            this.xRotO -= 360.0f;
        }
        while (this.xRot - this.xRotO >= 180.0f) {
            this.xRotO += 360.0f;
        }
        while (this.yRot - this.yRotO < -180.0f) {
            this.yRotO -= 360.0f;
        }
        while (this.yRot - this.yRotO >= 180.0f) {
            this.yRotO += 360.0f;
        }
        this.xRot = Mth.lerp(0.2f, this.xRotO, this.xRot);
        this.yRot = Mth.lerp(0.2f, this.yRotO, this.yRot);
        float float6 = 0.99f;
        final float float7 = 0.05f;
        if (this.isInWater()) {
            for (int integer16 = 0; integer16 < 4; ++integer16) {
                final float float8 = 0.25f;
                this.level.addParticle(ParticleTypes.BUBBLE, double12 - double9 * 0.25, double13 - double10 * 0.25, double14 - double11 * 0.25, double9, double10, double11);
            }
            float6 = this.getWaterInertia();
        }
        this.setDeltaMovement(cvl3.scale(float6));
        if (!this.isNoGravity() && !boolean2) {
            final Vec3 cvl6 = this.getDeltaMovement();
            this.setDeltaMovement(cvl6.x, cvl6.y - 0.05000000074505806, cvl6.z);
        }
        this.setPos(double12, double13, double14);
        this.checkInsideBlocks();
    }
    
    protected void tickDespawn() {
        ++this.life;
        if (this.life >= 1200) {
            this.remove();
        }
    }
    
    protected void onHit(final HitResult cvi) {
        final HitResult.Type a3 = cvi.getType();
        if (a3 == HitResult.Type.ENTITY) {
            this.onHitEntity((EntityHitResult)cvi);
        }
        else if (a3 == HitResult.Type.BLOCK) {
            final BlockHitResult cvg4 = (BlockHitResult)cvi;
            final BlockState byj5 = this.level.getBlockState(cvg4.getBlockPos());
            this.lastState = byj5;
            final Vec3 cvl6 = cvg4.getLocation().subtract(this.getX(), this.getY(), this.getZ());
            this.setDeltaMovement(cvl6);
            final Vec3 cvl7 = cvl6.normalize().scale(0.05000000074505806);
            this.setPosRaw(this.getX() - cvl7.x, this.getY() - cvl7.y, this.getZ() - cvl7.z);
            this.playSound(this.getHitGroundSoundEvent(), 1.0f, 1.2f / (this.random.nextFloat() * 0.2f + 0.9f));
            this.inGround = true;
            this.shakeTime = 7;
            this.setCritArrow(false);
            this.setPierceLevel((byte)0);
            this.setSoundEvent(SoundEvents.ARROW_HIT);
            this.setShotFromCrossbow(false);
            this.resetPiercedEntities();
            byj5.onProjectileHit(this.level, byj5, cvg4, this);
        }
    }
    
    private void resetPiercedEntities() {
        if (this.piercedAndKilledEntities != null) {
            this.piercedAndKilledEntities.clear();
        }
        if (this.piercingIgnoreEntityIds != null) {
            this.piercingIgnoreEntityIds.clear();
        }
    }
    
    protected void onHitEntity(final EntityHitResult cvh) {
        final Entity akq3 = cvh.getEntity();
        final float float4 = (float)this.getDeltaMovement().length();
        int integer5 = Mth.ceil(Math.max(float4 * this.baseDamage, 0.0));
        if (this.getPierceLevel() > 0) {
            if (this.piercingIgnoreEntityIds == null) {
                this.piercingIgnoreEntityIds = new IntOpenHashSet(5);
            }
            if (this.piercedAndKilledEntities == null) {
                this.piercedAndKilledEntities = Lists.newArrayListWithCapacity(5);
            }
            if (this.piercingIgnoreEntityIds.size() >= this.getPierceLevel() + 1) {
                this.remove();
                return;
            }
            this.piercingIgnoreEntityIds.add(akq3.getId());
        }
        if (this.isCritArrow()) {
            integer5 += this.random.nextInt(integer5 / 2 + 2);
        }
        final Entity akq4 = this.getOwner();
        DamageSource ajz6;
        if (akq4 == null) {
            ajz6 = DamageSource.arrow(this, this);
        }
        else {
            ajz6 = DamageSource.arrow(this, akq4);
            if (akq4 instanceof LivingEntity) {
                ((LivingEntity)akq4).setLastHurtMob(akq3);
            }
        }
        final boolean boolean8 = akq3.getType() == EntityType.ENDERMAN;
        final int integer6 = akq3.getRemainingFireTicks();
        if (this.isOnFire() && !boolean8) {
            akq3.setSecondsOnFire(5);
        }
        if (akq3.hurt(ajz6, (float)integer5)) {
            if (boolean8) {
                return;
            }
            if (akq3 instanceof LivingEntity) {
                final LivingEntity akz10 = (LivingEntity)akq3;
                if (!this.level.isClientSide && this.getPierceLevel() <= 0) {
                    akz10.setArrowCount(akz10.getArrowCount() + 1);
                }
                if (this.knockback > 0) {
                    final Vec3 cvl11 = this.getDeltaMovement().multiply(1.0, 0.0, 1.0).normalize().scale(this.knockback * 0.6);
                    if (cvl11.lengthSqr() > 0.0) {
                        akz10.push(cvl11.x, 0.1, cvl11.z);
                    }
                }
                if (!this.level.isClientSide && akq4 instanceof LivingEntity) {
                    EnchantmentHelper.doPostHurtEffects(akz10, akq4);
                    EnchantmentHelper.doPostDamageEffects((LivingEntity)akq4, akz10);
                }
                this.doPostHurtEffects(akz10);
                if (akq4 != null && akz10 != akq4 && akz10 instanceof Player && akq4 instanceof ServerPlayer) {
                    ((ServerPlayer)akq4).connection.send(new ClientboundGameEventPacket(6, 0.0f));
                }
                if (!akq3.isAlive() && this.piercedAndKilledEntities != null) {
                    this.piercedAndKilledEntities.add(akz10);
                }
                if (!this.level.isClientSide && akq4 instanceof ServerPlayer) {
                    final ServerPlayer xe11 = (ServerPlayer)akq4;
                    if (this.piercedAndKilledEntities != null && this.shotFromCrossbow()) {
                        CriteriaTriggers.KILLED_BY_CROSSBOW.trigger(xe11, this.piercedAndKilledEntities, this.piercedAndKilledEntities.size());
                    }
                    else if (!akq3.isAlive() && this.shotFromCrossbow()) {
                        CriteriaTriggers.KILLED_BY_CROSSBOW.trigger(xe11, Arrays.<Entity>asList(akq3), 0);
                    }
                }
            }
            this.playSound(this.soundEvent, 1.0f, 1.2f / (this.random.nextFloat() * 0.2f + 0.9f));
            if (this.getPierceLevel() <= 0) {
                this.remove();
            }
        }
        else {
            akq3.setRemainingFireTicks(integer6);
            this.setDeltaMovement(this.getDeltaMovement().scale(-0.1));
            this.yRot += 180.0f;
            this.yRotO += 180.0f;
            this.flightTime = 0;
            if (!this.level.isClientSide && this.getDeltaMovement().lengthSqr() < 1.0E-7) {
                if (this.pickup == Pickup.ALLOWED) {
                    this.spawnAtLocation(this.getPickupItem(), 0.1f);
                }
                this.remove();
            }
        }
    }
    
    protected SoundEvent getDefaultHitGroundSoundEvent() {
        return SoundEvents.ARROW_HIT;
    }
    
    protected final SoundEvent getHitGroundSoundEvent() {
        return this.soundEvent;
    }
    
    protected void doPostHurtEffects(final LivingEntity akz) {
    }
    
    @Nullable
    protected EntityHitResult findHitEntity(final Vec3 cvl1, final Vec3 cvl2) {
        return ProjectileUtil.getHitResult(this.level, this, cvl1, cvl2, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0), akq -> !akq.isSpectator() && akq.isAlive() && akq.isPickable() && (akq != this.getOwner() || this.flightTime >= 5) && (this.piercingIgnoreEntityIds == null || !this.piercingIgnoreEntityIds.contains(akq.getId())));
    }
    
    public void addAdditionalSaveData(final CompoundTag jt) {
        jt.putShort("life", (short)this.life);
        if (this.lastState != null) {
            jt.put("inBlockState", NbtUtils.writeBlockState(this.lastState));
        }
        jt.putByte("shake", (byte)this.shakeTime);
        jt.putBoolean("inGround", this.inGround);
        jt.putByte("pickup", (byte)this.pickup.ordinal());
        jt.putDouble("damage", this.baseDamage);
        jt.putBoolean("crit", this.isCritArrow());
        jt.putByte("PierceLevel", this.getPierceLevel());
        if (this.ownerUUID != null) {
            jt.putUUID("OwnerUUID", this.ownerUUID);
        }
        jt.putString("SoundEvent", Registry.SOUND_EVENT.getKey(this.soundEvent).toString());
        jt.putBoolean("ShotFromCrossbow", this.shotFromCrossbow());
    }
    
    public void readAdditionalSaveData(final CompoundTag jt) {
        this.life = jt.getShort("life");
        if (jt.contains("inBlockState", 10)) {
            this.lastState = NbtUtils.readBlockState(jt.getCompound("inBlockState"));
        }
        this.shakeTime = (jt.getByte("shake") & 0xFF);
        this.inGround = jt.getBoolean("inGround");
        if (jt.contains("damage", 99)) {
            this.baseDamage = jt.getDouble("damage");
        }
        if (jt.contains("pickup", 99)) {
            this.pickup = Pickup.byOrdinal(jt.getByte("pickup"));
        }
        else if (jt.contains("player", 99)) {
            this.pickup = (jt.getBoolean("player") ? Pickup.ALLOWED : Pickup.DISALLOWED);
        }
        this.setCritArrow(jt.getBoolean("crit"));
        this.setPierceLevel(jt.getByte("PierceLevel"));
        if (jt.hasUUID("OwnerUUID")) {
            this.ownerUUID = jt.getUUID("OwnerUUID");
        }
        if (jt.contains("SoundEvent", 8)) {
            this.soundEvent = Registry.SOUND_EVENT.getOptional(new ResourceLocation(jt.getString("SoundEvent"))).orElse(this.getDefaultHitGroundSoundEvent());
        }
        this.setShotFromCrossbow(jt.getBoolean("ShotFromCrossbow"));
    }
    
    public void setOwner(@Nullable final Entity akq) {
        this.ownerUUID = ((akq == null) ? null : akq.getUUID());
        if (akq instanceof Player) {
            this.pickup = (((Player)akq).abilities.instabuild ? Pickup.CREATIVE_ONLY : Pickup.ALLOWED);
        }
    }
    
    @Nullable
    public Entity getOwner() {
        if (this.ownerUUID != null && this.level instanceof ServerLevel) {
            return ((ServerLevel)this.level).getEntity(this.ownerUUID);
        }
        return null;
    }
    
    @Override
    public void playerTouch(final Player ayj) {
        if (this.level.isClientSide || (!this.inGround && !this.isNoPhysics()) || this.shakeTime > 0) {
            return;
        }
        boolean boolean3 = this.pickup == Pickup.ALLOWED || (this.pickup == Pickup.CREATIVE_ONLY && ayj.abilities.instabuild) || (this.isNoPhysics() && this.getOwner().getUUID() == ayj.getUUID());
        if (this.pickup == Pickup.ALLOWED && !ayj.inventory.add(this.getPickupItem())) {
            boolean3 = false;
        }
        if (boolean3) {
            ayj.take(this, 1);
            this.remove();
        }
    }
    
    protected abstract ItemStack getPickupItem();
    
    @Override
    protected boolean isMovementNoisy() {
        return false;
    }
    
    public void setBaseDamage(final double double1) {
        this.baseDamage = double1;
    }
    
    public double getBaseDamage() {
        return this.baseDamage;
    }
    
    public void setKnockback(final int integer) {
        this.knockback = integer;
    }
    
    @Override
    public boolean isAttackable() {
        return false;
    }
    
    @Override
    protected float getEyeHeight(final Pose alj, final EntityDimensions akr) {
        return 0.0f;
    }
    
    public void setCritArrow(final boolean boolean1) {
        this.setFlag(1, boolean1);
    }
    
    public void setPierceLevel(final byte byte1) {
        this.entityData.<Byte>set(AbstractArrow.PIERCE_LEVEL, byte1);
    }
    
    private void setFlag(final int integer, final boolean boolean2) {
        final byte byte4 = this.entityData.<Byte>get(AbstractArrow.ID_FLAGS);
        if (boolean2) {
            this.entityData.<Byte>set(AbstractArrow.ID_FLAGS, (byte)(byte4 | integer));
        }
        else {
            this.entityData.<Byte>set(AbstractArrow.ID_FLAGS, (byte)(byte4 & ~integer));
        }
    }
    
    public boolean isCritArrow() {
        final byte byte2 = this.entityData.<Byte>get(AbstractArrow.ID_FLAGS);
        return (byte2 & 0x1) != 0x0;
    }
    
    public boolean shotFromCrossbow() {
        final byte byte2 = this.entityData.<Byte>get(AbstractArrow.ID_FLAGS);
        return (byte2 & 0x4) != 0x0;
    }
    
    public byte getPierceLevel() {
        return this.entityData.<Byte>get(AbstractArrow.PIERCE_LEVEL);
    }
    
    public void setEnchantmentEffectsFromEntity(final LivingEntity akz, final float float2) {
        final int integer4 = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER_ARROWS, akz);
        final int integer5 = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH_ARROWS, akz);
        this.setBaseDamage(float2 * 2.0f + (this.random.nextGaussian() * 0.25 + this.level.getDifficulty().getId() * 0.11f));
        if (integer4 > 0) {
            this.setBaseDamage(this.getBaseDamage() + integer4 * 0.5 + 0.5);
        }
        if (integer5 > 0) {
            this.setKnockback(integer5);
        }
        if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAMING_ARROWS, akz) > 0) {
            this.setSecondsOnFire(100);
        }
    }
    
    protected float getWaterInertia() {
        return 0.6f;
    }
    
    public void setNoPhysics(final boolean boolean1) {
        this.setFlag(2, this.noPhysics = boolean1);
    }
    
    public boolean isNoPhysics() {
        if (!this.level.isClientSide) {
            return this.noPhysics;
        }
        return (this.entityData.<Byte>get(AbstractArrow.ID_FLAGS) & 0x2) != 0x0;
    }
    
    public void setShotFromCrossbow(final boolean boolean1) {
        this.setFlag(4, boolean1);
    }
    
    @Override
    public Packet<?> getAddEntityPacket() {
        final Entity akq2 = this.getOwner();
        return new ClientboundAddEntityPacket(this, (akq2 == null) ? 0 : akq2.getId());
    }
    
    static {
        ID_FLAGS = SynchedEntityData.<Byte>defineId(AbstractArrow.class, EntityDataSerializers.BYTE);
        DATA_OWNERUUID_ID = SynchedEntityData.<Optional<UUID>>defineId(AbstractArrow.class, EntityDataSerializers.OPTIONAL_UUID);
        PIERCE_LEVEL = SynchedEntityData.<Byte>defineId(AbstractArrow.class, EntityDataSerializers.BYTE);
    }
    
    public enum Pickup {
        DISALLOWED, 
        ALLOWED, 
        CREATIVE_ONLY;
        
        public static Pickup byOrdinal(int integer) {
            if (integer < 0 || integer > values().length) {
                integer = 0;
            }
            return values()[integer];
        }
    }
}
