package net.minecraft.world.entity.decoration;

import java.util.AbstractList;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.global.LightningBolt;
import javax.annotation.Nullable;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.ItemLike;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.Items;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.entity.player.Player;
import java.util.List;
import java.util.Iterator;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.NonNullList;
import net.minecraft.world.entity.Entity;
import java.util.function.Predicate;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.core.Rotations;
import net.minecraft.world.entity.LivingEntity;

public class ArmorStand extends LivingEntity {
    private static final Rotations DEFAULT_HEAD_POSE;
    private static final Rotations DEFAULT_BODY_POSE;
    private static final Rotations DEFAULT_LEFT_ARM_POSE;
    private static final Rotations DEFAULT_RIGHT_ARM_POSE;
    private static final Rotations DEFAULT_LEFT_LEG_POSE;
    private static final Rotations DEFAULT_RIGHT_LEG_POSE;
    public static final EntityDataAccessor<Byte> DATA_CLIENT_FLAGS;
    public static final EntityDataAccessor<Rotations> DATA_HEAD_POSE;
    public static final EntityDataAccessor<Rotations> DATA_BODY_POSE;
    public static final EntityDataAccessor<Rotations> DATA_LEFT_ARM_POSE;
    public static final EntityDataAccessor<Rotations> DATA_RIGHT_ARM_POSE;
    public static final EntityDataAccessor<Rotations> DATA_LEFT_LEG_POSE;
    public static final EntityDataAccessor<Rotations> DATA_RIGHT_LEG_POSE;
    private static final Predicate<Entity> RIDABLE_MINECARTS;
    private final NonNullList<ItemStack> handItems;
    private final NonNullList<ItemStack> armorItems;
    private boolean invisible;
    public long lastHit;
    private int disabledSlots;
    private Rotations headPose;
    private Rotations bodyPose;
    private Rotations leftArmPose;
    private Rotations rightArmPose;
    private Rotations leftLegPose;
    private Rotations rightLegPose;
    
    public ArmorStand(final EntityType<? extends ArmorStand> aku, final Level bjw) {
        super(aku, bjw);
        this.handItems = NonNullList.<ItemStack>withSize(2, ItemStack.EMPTY);
        this.armorItems = NonNullList.<ItemStack>withSize(4, ItemStack.EMPTY);
        this.headPose = ArmorStand.DEFAULT_HEAD_POSE;
        this.bodyPose = ArmorStand.DEFAULT_BODY_POSE;
        this.leftArmPose = ArmorStand.DEFAULT_LEFT_ARM_POSE;
        this.rightArmPose = ArmorStand.DEFAULT_RIGHT_ARM_POSE;
        this.leftLegPose = ArmorStand.DEFAULT_LEFT_LEG_POSE;
        this.rightLegPose = ArmorStand.DEFAULT_RIGHT_LEG_POSE;
        this.maxUpStep = 0.0f;
    }
    
    public ArmorStand(final Level bjw, final double double2, final double double3, final double double4) {
        this(EntityType.ARMOR_STAND, bjw);
        this.setPos(double2, double3, double4);
    }
    
    @Override
    public void refreshDimensions() {
        final double double2 = this.getX();
        final double double3 = this.getY();
        final double double4 = this.getZ();
        super.refreshDimensions();
        this.setPos(double2, double3, double4);
    }
    
    private boolean hasPhysics() {
        return !this.isMarker() && !this.isNoGravity();
    }
    
    @Override
    public boolean isEffectiveAi() {
        return super.isEffectiveAi() && this.hasPhysics();
    }
    
    @Override
    protected void defineSynchedData() {
        super.defineSynchedData();
        this.entityData.<Byte>define(ArmorStand.DATA_CLIENT_FLAGS, (Byte)0);
        this.entityData.<Rotations>define(ArmorStand.DATA_HEAD_POSE, ArmorStand.DEFAULT_HEAD_POSE);
        this.entityData.<Rotations>define(ArmorStand.DATA_BODY_POSE, ArmorStand.DEFAULT_BODY_POSE);
        this.entityData.<Rotations>define(ArmorStand.DATA_LEFT_ARM_POSE, ArmorStand.DEFAULT_LEFT_ARM_POSE);
        this.entityData.<Rotations>define(ArmorStand.DATA_RIGHT_ARM_POSE, ArmorStand.DEFAULT_RIGHT_ARM_POSE);
        this.entityData.<Rotations>define(ArmorStand.DATA_LEFT_LEG_POSE, ArmorStand.DEFAULT_LEFT_LEG_POSE);
        this.entityData.<Rotations>define(ArmorStand.DATA_RIGHT_LEG_POSE, ArmorStand.DEFAULT_RIGHT_LEG_POSE);
    }
    
    @Override
    public Iterable<ItemStack> getHandSlots() {
        return this.handItems;
    }
    
    @Override
    public Iterable<ItemStack> getArmorSlots() {
        return this.armorItems;
    }
    
    @Override
    public ItemStack getItemBySlot(final EquipmentSlot akv) {
        switch (akv.getType()) {
            case HAND: {
                return this.handItems.get(akv.getIndex());
            }
            case ARMOR: {
                return this.armorItems.get(akv.getIndex());
            }
            default: {
                return ItemStack.EMPTY;
            }
        }
    }
    
    @Override
    public void setItemSlot(final EquipmentSlot akv, final ItemStack ben) {
        switch (akv.getType()) {
            case HAND: {
                this.playEquipSound(ben);
                this.handItems.set(akv.getIndex(), ben);
                break;
            }
            case ARMOR: {
                this.playEquipSound(ben);
                this.armorItems.set(akv.getIndex(), ben);
                break;
            }
        }
    }
    
    @Override
    public boolean setSlot(final int integer, final ItemStack ben) {
        EquipmentSlot akv4;
        if (integer == 98) {
            akv4 = EquipmentSlot.MAINHAND;
        }
        else if (integer == 99) {
            akv4 = EquipmentSlot.OFFHAND;
        }
        else if (integer == 100 + EquipmentSlot.HEAD.getIndex()) {
            akv4 = EquipmentSlot.HEAD;
        }
        else if (integer == 100 + EquipmentSlot.CHEST.getIndex()) {
            akv4 = EquipmentSlot.CHEST;
        }
        else if (integer == 100 + EquipmentSlot.LEGS.getIndex()) {
            akv4 = EquipmentSlot.LEGS;
        }
        else {
            if (integer != 100 + EquipmentSlot.FEET.getIndex()) {
                return false;
            }
            akv4 = EquipmentSlot.FEET;
        }
        if (ben.isEmpty() || Mob.isValidSlotForItem(akv4, ben) || akv4 == EquipmentSlot.HEAD) {
            this.setItemSlot(akv4, ben);
            return true;
        }
        return false;
    }
    
    @Override
    public boolean canTakeItem(final ItemStack ben) {
        final EquipmentSlot akv3 = Mob.getEquipmentSlotForItem(ben);
        return this.getItemBySlot(akv3).isEmpty() && !this.isDisabled(akv3);
    }
    
    @Override
    public void addAdditionalSaveData(final CompoundTag jt) {
        super.addAdditionalSaveData(jt);
        final ListTag jz3 = new ListTag();
        for (final ItemStack ben5 : this.armorItems) {
            final CompoundTag jt2 = new CompoundTag();
            if (!ben5.isEmpty()) {
                ben5.save(jt2);
            }
            ((AbstractList<CompoundTag>)jz3).add(jt2);
        }
        jt.put("ArmorItems", jz3);
        final ListTag jz4 = new ListTag();
        for (final ItemStack ben6 : this.handItems) {
            final CompoundTag jt3 = new CompoundTag();
            if (!ben6.isEmpty()) {
                ben6.save(jt3);
            }
            ((AbstractList<CompoundTag>)jz4).add(jt3);
        }
        jt.put("HandItems", jz4);
        jt.putBoolean("Invisible", this.isInvisible());
        jt.putBoolean("Small", this.isSmall());
        jt.putBoolean("ShowArms", this.isShowArms());
        jt.putInt("DisabledSlots", this.disabledSlots);
        jt.putBoolean("NoBasePlate", this.isNoBasePlate());
        if (this.isMarker()) {
            jt.putBoolean("Marker", this.isMarker());
        }
        jt.put("Pose", this.writePose());
    }
    
    @Override
    public void readAdditionalSaveData(final CompoundTag jt) {
        super.readAdditionalSaveData(jt);
        if (jt.contains("ArmorItems", 9)) {
            final ListTag jz3 = jt.getList("ArmorItems", 10);
            for (int integer4 = 0; integer4 < this.armorItems.size(); ++integer4) {
                this.armorItems.set(integer4, ItemStack.of(jz3.getCompound(integer4)));
            }
        }
        if (jt.contains("HandItems", 9)) {
            final ListTag jz3 = jt.getList("HandItems", 10);
            for (int integer4 = 0; integer4 < this.handItems.size(); ++integer4) {
                this.handItems.set(integer4, ItemStack.of(jz3.getCompound(integer4)));
            }
        }
        this.setInvisible(jt.getBoolean("Invisible"));
        this.setSmall(jt.getBoolean("Small"));
        this.setShowArms(jt.getBoolean("ShowArms"));
        this.disabledSlots = jt.getInt("DisabledSlots");
        this.setNoBasePlate(jt.getBoolean("NoBasePlate"));
        this.setMarker(jt.getBoolean("Marker"));
        this.noPhysics = !this.hasPhysics();
        final CompoundTag jt2 = jt.getCompound("Pose");
        this.readPose(jt2);
    }
    
    private void readPose(final CompoundTag jt) {
        final ListTag jz3 = jt.getList("Head", 5);
        this.setHeadPose(jz3.isEmpty() ? ArmorStand.DEFAULT_HEAD_POSE : new Rotations(jz3));
        final ListTag jz4 = jt.getList("Body", 5);
        this.setBodyPose(jz4.isEmpty() ? ArmorStand.DEFAULT_BODY_POSE : new Rotations(jz4));
        final ListTag jz5 = jt.getList("LeftArm", 5);
        this.setLeftArmPose(jz5.isEmpty() ? ArmorStand.DEFAULT_LEFT_ARM_POSE : new Rotations(jz5));
        final ListTag jz6 = jt.getList("RightArm", 5);
        this.setRightArmPose(jz6.isEmpty() ? ArmorStand.DEFAULT_RIGHT_ARM_POSE : new Rotations(jz6));
        final ListTag jz7 = jt.getList("LeftLeg", 5);
        this.setLeftLegPose(jz7.isEmpty() ? ArmorStand.DEFAULT_LEFT_LEG_POSE : new Rotations(jz7));
        final ListTag jz8 = jt.getList("RightLeg", 5);
        this.setRightLegPose(jz8.isEmpty() ? ArmorStand.DEFAULT_RIGHT_LEG_POSE : new Rotations(jz8));
    }
    
    private CompoundTag writePose() {
        final CompoundTag jt2 = new CompoundTag();
        if (!ArmorStand.DEFAULT_HEAD_POSE.equals(this.headPose)) {
            jt2.put("Head", this.headPose.save());
        }
        if (!ArmorStand.DEFAULT_BODY_POSE.equals(this.bodyPose)) {
            jt2.put("Body", this.bodyPose.save());
        }
        if (!ArmorStand.DEFAULT_LEFT_ARM_POSE.equals(this.leftArmPose)) {
            jt2.put("LeftArm", this.leftArmPose.save());
        }
        if (!ArmorStand.DEFAULT_RIGHT_ARM_POSE.equals(this.rightArmPose)) {
            jt2.put("RightArm", this.rightArmPose.save());
        }
        if (!ArmorStand.DEFAULT_LEFT_LEG_POSE.equals(this.leftLegPose)) {
            jt2.put("LeftLeg", this.leftLegPose.save());
        }
        if (!ArmorStand.DEFAULT_RIGHT_LEG_POSE.equals(this.rightLegPose)) {
            jt2.put("RightLeg", this.rightLegPose.save());
        }
        return jt2;
    }
    
    @Override
    public boolean isPushable() {
        return false;
    }
    
    @Override
    protected void doPush(final Entity akq) {
    }
    
    @Override
    protected void pushEntities() {
        final List<Entity> list2 = this.level.getEntities(this, this.getBoundingBox(), ArmorStand.RIDABLE_MINECARTS);
        for (int integer3 = 0; integer3 < list2.size(); ++integer3) {
            final Entity akq4 = list2.get(integer3);
            if (this.distanceToSqr(akq4) <= 0.2) {
                akq4.push(this);
            }
        }
    }
    
    @Override
    public InteractionResult interactAt(final Player ayj, final Vec3 cvl, final InteractionHand ajk) {
        final ItemStack ben5 = ayj.getItemInHand(ajk);
        if (this.isMarker() || ben5.getItem() == Items.NAME_TAG) {
            return InteractionResult.PASS;
        }
        if (ayj.isSpectator()) {
            return InteractionResult.SUCCESS;
        }
        if (ayj.level.isClientSide) {
            return InteractionResult.CONSUME;
        }
        final EquipmentSlot akv6 = Mob.getEquipmentSlotForItem(ben5);
        if (ben5.isEmpty()) {
            final EquipmentSlot akv7 = this.getClickedSlot(cvl);
            final EquipmentSlot akv8 = this.isDisabled(akv7) ? akv6 : akv7;
            if (this.hasItemInSlot(akv8) && this.swapItem(ayj, akv8, ben5, ajk)) {
                return InteractionResult.SUCCESS;
            }
        }
        else {
            if (this.isDisabled(akv6)) {
                return InteractionResult.FAIL;
            }
            if (akv6.getType() == EquipmentSlot.Type.HAND && !this.isShowArms()) {
                return InteractionResult.FAIL;
            }
            if (this.swapItem(ayj, akv6, ben5, ajk)) {
                return InteractionResult.SUCCESS;
            }
        }
        return InteractionResult.PASS;
    }
    
    private EquipmentSlot getClickedSlot(final Vec3 cvl) {
        EquipmentSlot akv3 = EquipmentSlot.MAINHAND;
        final boolean boolean4 = this.isSmall();
        final double double5 = boolean4 ? (cvl.y * 2.0) : cvl.y;
        final EquipmentSlot akv4 = EquipmentSlot.FEET;
        if (double5 >= 0.1 && double5 < 0.1 + (boolean4 ? 0.8 : 0.45) && this.hasItemInSlot(akv4)) {
            akv3 = EquipmentSlot.FEET;
        }
        else if (double5 >= 0.9 + (boolean4 ? 0.3 : 0.0) && double5 < 0.9 + (boolean4 ? 1.0 : 0.7) && this.hasItemInSlot(EquipmentSlot.CHEST)) {
            akv3 = EquipmentSlot.CHEST;
        }
        else if (double5 >= 0.4 && double5 < 0.4 + (boolean4 ? 1.0 : 0.8) && this.hasItemInSlot(EquipmentSlot.LEGS)) {
            akv3 = EquipmentSlot.LEGS;
        }
        else if (double5 >= 1.6 && this.hasItemInSlot(EquipmentSlot.HEAD)) {
            akv3 = EquipmentSlot.HEAD;
        }
        else if (!this.hasItemInSlot(EquipmentSlot.MAINHAND) && this.hasItemInSlot(EquipmentSlot.OFFHAND)) {
            akv3 = EquipmentSlot.OFFHAND;
        }
        return akv3;
    }
    
    private boolean isDisabled(final EquipmentSlot akv) {
        return (this.disabledSlots & 1 << akv.getFilterFlag()) != 0x0 || (akv.getType() == EquipmentSlot.Type.HAND && !this.isShowArms());
    }
    
    private boolean swapItem(final Player ayj, final EquipmentSlot akv, final ItemStack ben, final InteractionHand ajk) {
        final ItemStack ben2 = this.getItemBySlot(akv);
        if (!ben2.isEmpty() && (this.disabledSlots & 1 << akv.getFilterFlag() + 8) != 0x0) {
            return false;
        }
        if (ben2.isEmpty() && (this.disabledSlots & 1 << akv.getFilterFlag() + 16) != 0x0) {
            return false;
        }
        if (ayj.abilities.instabuild && ben2.isEmpty() && !ben.isEmpty()) {
            final ItemStack ben3 = ben.copy();
            ben3.setCount(1);
            this.setItemSlot(akv, ben3);
            return true;
        }
        if (ben.isEmpty() || ben.getCount() <= 1) {
            this.setItemSlot(akv, ben);
            ayj.setItemInHand(ajk, ben2);
            return true;
        }
        if (!ben2.isEmpty()) {
            return false;
        }
        final ItemStack ben3 = ben.copy();
        ben3.setCount(1);
        this.setItemSlot(akv, ben3);
        ben.shrink(1);
        return true;
    }
    
    @Override
    public boolean hurt(final DamageSource ajz, final float float2) {
        if (this.level.isClientSide || this.removed) {
            return false;
        }
        if (DamageSource.OUT_OF_WORLD.equals(ajz)) {
            this.remove();
            return false;
        }
        if (this.isInvulnerableTo(ajz) || this.invisible || this.isMarker()) {
            return false;
        }
        if (ajz.isExplosion()) {
            this.brokenByAnything(ajz);
            this.remove();
            return false;
        }
        if (DamageSource.IN_FIRE.equals(ajz)) {
            if (this.isOnFire()) {
                this.causeDamage(ajz, 0.15f);
            }
            else {
                this.setSecondsOnFire(5);
            }
            return false;
        }
        if (DamageSource.ON_FIRE.equals(ajz) && this.getHealth() > 0.5f) {
            this.causeDamage(ajz, 4.0f);
            return false;
        }
        final boolean boolean4 = ajz.getDirectEntity() instanceof AbstractArrow;
        final boolean boolean5 = boolean4 && ((AbstractArrow)ajz.getDirectEntity()).getPierceLevel() > 0;
        final boolean boolean6 = "player".equals(ajz.getMsgId());
        if (!boolean6 && !boolean4) {
            return false;
        }
        if (ajz.getEntity() instanceof Player && !((Player)ajz.getEntity()).abilities.mayBuild) {
            return false;
        }
        if (ajz.isCreativePlayer()) {
            this.playBrokenSound();
            this.showBreakingParticles();
            this.remove();
            return boolean5;
        }
        final long long7 = this.level.getGameTime();
        if (long7 - this.lastHit <= 5L || boolean4) {
            this.brokenByPlayer(ajz);
            this.showBreakingParticles();
            this.remove();
        }
        else {
            this.level.broadcastEntityEvent(this, (byte)32);
            this.lastHit = long7;
        }
        return true;
    }
    
    @Override
    public void handleEntityEvent(final byte byte1) {
        if (byte1 == 32) {
            if (this.level.isClientSide) {
                this.level.playLocalSound(this.getX(), this.getY(), this.getZ(), SoundEvents.ARMOR_STAND_HIT, this.getSoundSource(), 0.3f, 1.0f, false);
                this.lastHit = this.level.getGameTime();
            }
        }
        else {
            super.handleEntityEvent(byte1);
        }
    }
    
    @Override
    public boolean shouldRenderAtSqrDistance(final double double1) {
        double double2 = this.getBoundingBox().getSize() * 4.0;
        if (Double.isNaN(double2) || double2 == 0.0) {
            double2 = 4.0;
        }
        double2 *= 64.0;
        return double1 < double2 * double2;
    }
    
    private void showBreakingParticles() {
        if (this.level instanceof ServerLevel) {
            ((ServerLevel)this.level).<BlockParticleOption>sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, Blocks.OAK_PLANKS.defaultBlockState()), this.getX(), this.getY(0.6666666666666666), this.getZ(), 10, this.getBbWidth() / 4.0f, this.getBbHeight() / 4.0f, this.getBbWidth() / 4.0f, 0.05);
        }
    }
    
    private void causeDamage(final DamageSource ajz, final float float2) {
        float float3 = this.getHealth();
        float3 -= float2;
        if (float3 <= 0.5f) {
            this.brokenByAnything(ajz);
            this.remove();
        }
        else {
            this.setHealth(float3);
        }
    }
    
    private void brokenByPlayer(final DamageSource ajz) {
        Block.popResource(this.level, new BlockPos(this), new ItemStack(Items.ARMOR_STAND));
        this.brokenByAnything(ajz);
    }
    
    private void brokenByAnything(final DamageSource ajz) {
        this.playBrokenSound();
        this.dropAllDeathLoot(ajz);
        for (int integer3 = 0; integer3 < this.handItems.size(); ++integer3) {
            final ItemStack ben4 = this.handItems.get(integer3);
            if (!ben4.isEmpty()) {
                Block.popResource(this.level, new BlockPos(this).above(), ben4);
                this.handItems.set(integer3, ItemStack.EMPTY);
            }
        }
        for (int integer3 = 0; integer3 < this.armorItems.size(); ++integer3) {
            final ItemStack ben4 = this.armorItems.get(integer3);
            if (!ben4.isEmpty()) {
                Block.popResource(this.level, new BlockPos(this).above(), ben4);
                this.armorItems.set(integer3, ItemStack.EMPTY);
            }
        }
    }
    
    private void playBrokenSound() {
        this.level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.ARMOR_STAND_BREAK, this.getSoundSource(), 1.0f, 1.0f);
    }
    
    @Override
    protected float tickHeadTurn(final float float1, final float float2) {
        this.yBodyRotO = this.yRotO;
        this.yBodyRot = this.yRot;
        return 0.0f;
    }
    
    @Override
    protected float getStandingEyeHeight(final Pose alj, final EntityDimensions akr) {
        return akr.height * (this.isBaby() ? 0.5f : 0.9f);
    }
    
    @Override
    public double getRidingHeight() {
        return this.isMarker() ? 0.0 : 0.10000000149011612;
    }
    
    @Override
    public void travel(final Vec3 cvl) {
        if (!this.hasPhysics()) {
            return;
        }
        super.travel(cvl);
    }
    
    @Override
    public void setYBodyRot(final float float1) {
        this.yRotO = float1;
        this.yBodyRotO = float1;
        this.yHeadRot = float1;
        this.yHeadRotO = float1;
    }
    
    @Override
    public void setYHeadRot(final float float1) {
        this.yRotO = float1;
        this.yBodyRotO = float1;
        this.yHeadRot = float1;
        this.yHeadRotO = float1;
    }
    
    @Override
    public void tick() {
        super.tick();
        final Rotations gc2 = this.entityData.<Rotations>get(ArmorStand.DATA_HEAD_POSE);
        if (!this.headPose.equals(gc2)) {
            this.setHeadPose(gc2);
        }
        final Rotations gc3 = this.entityData.<Rotations>get(ArmorStand.DATA_BODY_POSE);
        if (!this.bodyPose.equals(gc3)) {
            this.setBodyPose(gc3);
        }
        final Rotations gc4 = this.entityData.<Rotations>get(ArmorStand.DATA_LEFT_ARM_POSE);
        if (!this.leftArmPose.equals(gc4)) {
            this.setLeftArmPose(gc4);
        }
        final Rotations gc5 = this.entityData.<Rotations>get(ArmorStand.DATA_RIGHT_ARM_POSE);
        if (!this.rightArmPose.equals(gc5)) {
            this.setRightArmPose(gc5);
        }
        final Rotations gc6 = this.entityData.<Rotations>get(ArmorStand.DATA_LEFT_LEG_POSE);
        if (!this.leftLegPose.equals(gc6)) {
            this.setLeftLegPose(gc6);
        }
        final Rotations gc7 = this.entityData.<Rotations>get(ArmorStand.DATA_RIGHT_LEG_POSE);
        if (!this.rightLegPose.equals(gc7)) {
            this.setRightLegPose(gc7);
        }
    }
    
    @Override
    protected void updateInvisibilityStatus() {
        this.setInvisible(this.invisible);
    }
    
    @Override
    public void setInvisible(final boolean boolean1) {
        super.setInvisible(this.invisible = boolean1);
    }
    
    @Override
    public boolean isBaby() {
        return this.isSmall();
    }
    
    @Override
    public void kill() {
        this.remove();
    }
    
    @Override
    public boolean ignoreExplosion() {
        return this.isInvisible();
    }
    
    @Override
    public PushReaction getPistonPushReaction() {
        if (this.isMarker()) {
            return PushReaction.IGNORE;
        }
        return super.getPistonPushReaction();
    }
    
    private void setSmall(final boolean boolean1) {
        this.entityData.<Byte>set(ArmorStand.DATA_CLIENT_FLAGS, this.setBit(this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS), 1, boolean1));
    }
    
    public boolean isSmall() {
        return (this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS) & 0x1) != 0x0;
    }
    
    private void setShowArms(final boolean boolean1) {
        this.entityData.<Byte>set(ArmorStand.DATA_CLIENT_FLAGS, this.setBit(this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS), 4, boolean1));
    }
    
    public boolean isShowArms() {
        return (this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS) & 0x4) != 0x0;
    }
    
    private void setNoBasePlate(final boolean boolean1) {
        this.entityData.<Byte>set(ArmorStand.DATA_CLIENT_FLAGS, this.setBit(this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS), 8, boolean1));
    }
    
    public boolean isNoBasePlate() {
        return (this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS) & 0x8) != 0x0;
    }
    
    private void setMarker(final boolean boolean1) {
        this.entityData.<Byte>set(ArmorStand.DATA_CLIENT_FLAGS, this.setBit(this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS), 16, boolean1));
    }
    
    public boolean isMarker() {
        return (this.entityData.<Byte>get(ArmorStand.DATA_CLIENT_FLAGS) & 0x10) != 0x0;
    }
    
    private byte setBit(byte byte1, final int integer, final boolean boolean3) {
        if (boolean3) {
            byte1 |= (byte)integer;
        }
        else {
            byte1 &= (byte)~integer;
        }
        return byte1;
    }
    
    public void setHeadPose(final Rotations gc) {
        this.headPose = gc;
        this.entityData.<Rotations>set(ArmorStand.DATA_HEAD_POSE, gc);
    }
    
    public void setBodyPose(final Rotations gc) {
        this.bodyPose = gc;
        this.entityData.<Rotations>set(ArmorStand.DATA_BODY_POSE, gc);
    }
    
    public void setLeftArmPose(final Rotations gc) {
        this.leftArmPose = gc;
        this.entityData.<Rotations>set(ArmorStand.DATA_LEFT_ARM_POSE, gc);
    }
    
    public void setRightArmPose(final Rotations gc) {
        this.rightArmPose = gc;
        this.entityData.<Rotations>set(ArmorStand.DATA_RIGHT_ARM_POSE, gc);
    }
    
    public void setLeftLegPose(final Rotations gc) {
        this.leftLegPose = gc;
        this.entityData.<Rotations>set(ArmorStand.DATA_LEFT_LEG_POSE, gc);
    }
    
    public void setRightLegPose(final Rotations gc) {
        this.rightLegPose = gc;
        this.entityData.<Rotations>set(ArmorStand.DATA_RIGHT_LEG_POSE, gc);
    }
    
    public Rotations getHeadPose() {
        return this.headPose;
    }
    
    public Rotations getBodyPose() {
        return this.bodyPose;
    }
    
    public Rotations getLeftArmPose() {
        return this.leftArmPose;
    }
    
    public Rotations getRightArmPose() {
        return this.rightArmPose;
    }
    
    public Rotations getLeftLegPose() {
        return this.leftLegPose;
    }
    
    public Rotations getRightLegPose() {
        return this.rightLegPose;
    }
    
    @Override
    public boolean isPickable() {
        return super.isPickable() && !this.isMarker();
    }
    
    @Override
    public boolean skipAttackInteraction(final Entity akq) {
        return akq instanceof Player && !this.level.mayInteract((Player)akq, new BlockPos(this));
    }
    
    @Override
    public HumanoidArm getMainArm() {
        return HumanoidArm.RIGHT;
    }
    
    @Override
    protected SoundEvent getFallDamageSound(final int integer) {
        return SoundEvents.ARMOR_STAND_FALL;
    }
    
    @Nullable
    @Override
    protected SoundEvent getHurtSound(final DamageSource ajz) {
        return SoundEvents.ARMOR_STAND_HIT;
    }
    
    @Nullable
    @Override
    protected SoundEvent getDeathSound() {
        return SoundEvents.ARMOR_STAND_BREAK;
    }
    
    @Override
    public void thunderHit(final LightningBolt avy) {
    }
    
    @Override
    public boolean isAffectedByPotions() {
        return false;
    }
    
    @Override
    public void onSyncedDataUpdated(final EntityDataAccessor<?> sb) {
        if (ArmorStand.DATA_CLIENT_FLAGS.equals(sb)) {
            this.refreshDimensions();
            this.blocksBuilding = !this.isMarker();
        }
        super.onSyncedDataUpdated(sb);
    }
    
    @Override
    public boolean attackable() {
        return false;
    }
    
    @Override
    public EntityDimensions getDimensions(final Pose alj) {
        final float float3 = this.isMarker() ? 0.0f : (this.isBaby() ? 0.5f : 1.0f);
        return this.getType().getDimensions().scale(float3);
    }
    
    static {
        DEFAULT_HEAD_POSE = new Rotations(0.0f, 0.0f, 0.0f);
        DEFAULT_BODY_POSE = new Rotations(0.0f, 0.0f, 0.0f);
        DEFAULT_LEFT_ARM_POSE = new Rotations(-10.0f, 0.0f, -10.0f);
        DEFAULT_RIGHT_ARM_POSE = new Rotations(-15.0f, 0.0f, 10.0f);
        DEFAULT_LEFT_LEG_POSE = new Rotations(-1.0f, 0.0f, -1.0f);
        DEFAULT_RIGHT_LEG_POSE = new Rotations(1.0f, 0.0f, 1.0f);
        DATA_CLIENT_FLAGS = SynchedEntityData.<Byte>defineId(ArmorStand.class, EntityDataSerializers.BYTE);
        DATA_HEAD_POSE = SynchedEntityData.<Rotations>defineId(ArmorStand.class, EntityDataSerializers.ROTATIONS);
        DATA_BODY_POSE = SynchedEntityData.<Rotations>defineId(ArmorStand.class, EntityDataSerializers.ROTATIONS);
        DATA_LEFT_ARM_POSE = SynchedEntityData.<Rotations>defineId(ArmorStand.class, EntityDataSerializers.ROTATIONS);
        DATA_RIGHT_ARM_POSE = SynchedEntityData.<Rotations>defineId(ArmorStand.class, EntityDataSerializers.ROTATIONS);
        DATA_LEFT_LEG_POSE = SynchedEntityData.<Rotations>defineId(ArmorStand.class, EntityDataSerializers.ROTATIONS);
        DATA_RIGHT_LEG_POSE = SynchedEntityData.<Rotations>defineId(ArmorStand.class, EntityDataSerializers.ROTATIONS);
        RIDABLE_MINECARTS = (akq -> akq instanceof AbstractMinecart && akq.getMinecartType() == AbstractMinecart.Type.RIDEABLE);
    }
}
