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.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.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> aoq, final Level bqb) {
        super(aoq, bqb);
        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 bqb, final double double2, final double double3, final double double4) {
        this(EntityType.ARMOR_STAND, bqb);
        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 aor) {
        switch (aor.getType()) {
            case HAND: {
                return this.handItems.get(aor.getIndex());
            }
            case ARMOR: {
                return this.armorItems.get(aor.getIndex());
            }
            default: {
                return ItemStack.EMPTY;
            }
        }
    }
    
    @Override
    public void setItemSlot(final EquipmentSlot aor, final ItemStack bki) {
        switch (aor.getType()) {
            case HAND: {
                this.playEquipSound(bki);
                this.handItems.set(aor.getIndex(), bki);
                break;
            }
            case ARMOR: {
                this.playEquipSound(bki);
                this.armorItems.set(aor.getIndex(), bki);
                break;
            }
        }
    }
    
    @Override
    public boolean setSlot(final int integer, final ItemStack bki) {
        EquipmentSlot aor4;
        if (integer == 98) {
            aor4 = EquipmentSlot.MAINHAND;
        }
        else if (integer == 99) {
            aor4 = EquipmentSlot.OFFHAND;
        }
        else if (integer == 100 + EquipmentSlot.HEAD.getIndex()) {
            aor4 = EquipmentSlot.HEAD;
        }
        else if (integer == 100 + EquipmentSlot.CHEST.getIndex()) {
            aor4 = EquipmentSlot.CHEST;
        }
        else if (integer == 100 + EquipmentSlot.LEGS.getIndex()) {
            aor4 = EquipmentSlot.LEGS;
        }
        else {
            if (integer != 100 + EquipmentSlot.FEET.getIndex()) {
                return false;
            }
            aor4 = EquipmentSlot.FEET;
        }
        if (bki.isEmpty() || Mob.isValidSlotForItem(aor4, bki) || aor4 == EquipmentSlot.HEAD) {
            this.setItemSlot(aor4, bki);
            return true;
        }
        return false;
    }
    
    @Override
    public boolean canTakeItem(final ItemStack bki) {
        final EquipmentSlot aor3 = Mob.getEquipmentSlotForItem(bki);
        return this.getItemBySlot(aor3).isEmpty() && !this.isDisabled(aor3);
    }
    
    @Override
    public void addAdditionalSaveData(final CompoundTag le) {
        super.addAdditionalSaveData(le);
        final ListTag lk3 = new ListTag();
        for (final ItemStack bki5 : this.armorItems) {
            final CompoundTag le2 = new CompoundTag();
            if (!bki5.isEmpty()) {
                bki5.save(le2);
            }
            ((AbstractList<CompoundTag>)lk3).add(le2);
        }
        le.put("ArmorItems", lk3);
        final ListTag lk4 = new ListTag();
        for (final ItemStack bki6 : this.handItems) {
            final CompoundTag le3 = new CompoundTag();
            if (!bki6.isEmpty()) {
                bki6.save(le3);
            }
            ((AbstractList<CompoundTag>)lk4).add(le3);
        }
        le.put("HandItems", lk4);
        le.putBoolean("Invisible", this.isInvisible());
        le.putBoolean("Small", this.isSmall());
        le.putBoolean("ShowArms", this.isShowArms());
        le.putInt("DisabledSlots", this.disabledSlots);
        le.putBoolean("NoBasePlate", this.isNoBasePlate());
        if (this.isMarker()) {
            le.putBoolean("Marker", this.isMarker());
        }
        le.put("Pose", this.writePose());
    }
    
    @Override
    public void readAdditionalSaveData(final CompoundTag le) {
        super.readAdditionalSaveData(le);
        if (le.contains("ArmorItems", 9)) {
            final ListTag lk3 = le.getList("ArmorItems", 10);
            for (int integer4 = 0; integer4 < this.armorItems.size(); ++integer4) {
                this.armorItems.set(integer4, ItemStack.of(lk3.getCompound(integer4)));
            }
        }
        if (le.contains("HandItems", 9)) {
            final ListTag lk3 = le.getList("HandItems", 10);
            for (int integer4 = 0; integer4 < this.handItems.size(); ++integer4) {
                this.handItems.set(integer4, ItemStack.of(lk3.getCompound(integer4)));
            }
        }
        this.setInvisible(le.getBoolean("Invisible"));
        this.setSmall(le.getBoolean("Small"));
        this.setShowArms(le.getBoolean("ShowArms"));
        this.disabledSlots = le.getInt("DisabledSlots");
        this.setNoBasePlate(le.getBoolean("NoBasePlate"));
        this.setMarker(le.getBoolean("Marker"));
        this.noPhysics = !this.hasPhysics();
        final CompoundTag le2 = le.getCompound("Pose");
        this.readPose(le2);
    }
    
    private void readPose(final CompoundTag le) {
        final ListTag lk3 = le.getList("Head", 5);
        this.setHeadPose(lk3.isEmpty() ? ArmorStand.DEFAULT_HEAD_POSE : new Rotations(lk3));
        final ListTag lk4 = le.getList("Body", 5);
        this.setBodyPose(lk4.isEmpty() ? ArmorStand.DEFAULT_BODY_POSE : new Rotations(lk4));
        final ListTag lk5 = le.getList("LeftArm", 5);
        this.setLeftArmPose(lk5.isEmpty() ? ArmorStand.DEFAULT_LEFT_ARM_POSE : new Rotations(lk5));
        final ListTag lk6 = le.getList("RightArm", 5);
        this.setRightArmPose(lk6.isEmpty() ? ArmorStand.DEFAULT_RIGHT_ARM_POSE : new Rotations(lk6));
        final ListTag lk7 = le.getList("LeftLeg", 5);
        this.setLeftLegPose(lk7.isEmpty() ? ArmorStand.DEFAULT_LEFT_LEG_POSE : new Rotations(lk7));
        final ListTag lk8 = le.getList("RightLeg", 5);
        this.setRightLegPose(lk8.isEmpty() ? ArmorStand.DEFAULT_RIGHT_LEG_POSE : new Rotations(lk8));
    }
    
    private CompoundTag writePose() {
        final CompoundTag le2 = new CompoundTag();
        if (!ArmorStand.DEFAULT_HEAD_POSE.equals(this.headPose)) {
            le2.put("Head", this.headPose.save());
        }
        if (!ArmorStand.DEFAULT_BODY_POSE.equals(this.bodyPose)) {
            le2.put("Body", this.bodyPose.save());
        }
        if (!ArmorStand.DEFAULT_LEFT_ARM_POSE.equals(this.leftArmPose)) {
            le2.put("LeftArm", this.leftArmPose.save());
        }
        if (!ArmorStand.DEFAULT_RIGHT_ARM_POSE.equals(this.rightArmPose)) {
            le2.put("RightArm", this.rightArmPose.save());
        }
        if (!ArmorStand.DEFAULT_LEFT_LEG_POSE.equals(this.leftLegPose)) {
            le2.put("LeftLeg", this.leftLegPose.save());
        }
        if (!ArmorStand.DEFAULT_RIGHT_LEG_POSE.equals(this.rightLegPose)) {
            le2.put("RightLeg", this.rightLegPose.save());
        }
        return le2;
    }
    
    @Override
    public boolean isPushable() {
        return false;
    }
    
    @Override
    protected void doPush(final Entity aom) {
    }
    
    @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 aom4 = list2.get(integer3);
            if (this.distanceToSqr(aom4) <= 0.2) {
                aom4.push(this);
            }
        }
    }
    
    @Override
    public InteractionResult interactAt(final Player bec, final Vec3 dem, final InteractionHand anf) {
        final ItemStack bki5 = bec.getItemInHand(anf);
        if (this.isMarker() || bki5.getItem() == Items.NAME_TAG) {
            return InteractionResult.PASS;
        }
        if (bec.isSpectator()) {
            return InteractionResult.SUCCESS;
        }
        if (bec.level.isClientSide) {
            return InteractionResult.CONSUME;
        }
        final EquipmentSlot aor6 = Mob.getEquipmentSlotForItem(bki5);
        if (bki5.isEmpty()) {
            final EquipmentSlot aor7 = this.getClickedSlot(dem);
            final EquipmentSlot aor8 = this.isDisabled(aor7) ? aor6 : aor7;
            if (this.hasItemInSlot(aor8) && this.swapItem(bec, aor8, bki5, anf)) {
                return InteractionResult.SUCCESS;
            }
        }
        else {
            if (this.isDisabled(aor6)) {
                return InteractionResult.FAIL;
            }
            if (aor6.getType() == EquipmentSlot.Type.HAND && !this.isShowArms()) {
                return InteractionResult.FAIL;
            }
            if (this.swapItem(bec, aor6, bki5, anf)) {
                return InteractionResult.SUCCESS;
            }
        }
        return InteractionResult.PASS;
    }
    
    private EquipmentSlot getClickedSlot(final Vec3 dem) {
        EquipmentSlot aor3 = EquipmentSlot.MAINHAND;
        final boolean boolean4 = this.isSmall();
        final double double5 = boolean4 ? (dem.y * 2.0) : dem.y;
        final EquipmentSlot aor4 = EquipmentSlot.FEET;
        if (double5 >= 0.1 && double5 < 0.1 + (boolean4 ? 0.8 : 0.45) && this.hasItemInSlot(aor4)) {
            aor3 = EquipmentSlot.FEET;
        }
        else if (double5 >= 0.9 + (boolean4 ? 0.3 : 0.0) && double5 < 0.9 + (boolean4 ? 1.0 : 0.7) && this.hasItemInSlot(EquipmentSlot.CHEST)) {
            aor3 = EquipmentSlot.CHEST;
        }
        else if (double5 >= 0.4 && double5 < 0.4 + (boolean4 ? 1.0 : 0.8) && this.hasItemInSlot(EquipmentSlot.LEGS)) {
            aor3 = EquipmentSlot.LEGS;
        }
        else if (double5 >= 1.6 && this.hasItemInSlot(EquipmentSlot.HEAD)) {
            aor3 = EquipmentSlot.HEAD;
        }
        else if (!this.hasItemInSlot(EquipmentSlot.MAINHAND) && this.hasItemInSlot(EquipmentSlot.OFFHAND)) {
            aor3 = EquipmentSlot.OFFHAND;
        }
        return aor3;
    }
    
    private boolean isDisabled(final EquipmentSlot aor) {
        return (this.disabledSlots & 1 << aor.getFilterFlag()) != 0x0 || (aor.getType() == EquipmentSlot.Type.HAND && !this.isShowArms());
    }
    
    private boolean swapItem(final Player bec, final EquipmentSlot aor, final ItemStack bki, final InteractionHand anf) {
        final ItemStack bki2 = this.getItemBySlot(aor);
        if (!bki2.isEmpty() && (this.disabledSlots & 1 << aor.getFilterFlag() + 8) != 0x0) {
            return false;
        }
        if (bki2.isEmpty() && (this.disabledSlots & 1 << aor.getFilterFlag() + 16) != 0x0) {
            return false;
        }
        if (bec.abilities.instabuild && bki2.isEmpty() && !bki.isEmpty()) {
            final ItemStack bki3 = bki.copy();
            bki3.setCount(1);
            this.setItemSlot(aor, bki3);
            return true;
        }
        if (bki.isEmpty() || bki.getCount() <= 1) {
            this.setItemSlot(aor, bki);
            bec.setItemInHand(anf, bki2);
            return true;
        }
        if (!bki2.isEmpty()) {
            return false;
        }
        final ItemStack bki3 = bki.copy();
        bki3.setCount(1);
        this.setItemSlot(aor, bki3);
        bki.shrink(1);
        return true;
    }
    
    @Override
    public boolean hurt(final DamageSource anw, final float float2) {
        if (this.level.isClientSide || this.removed) {
            return false;
        }
        if (DamageSource.OUT_OF_WORLD.equals(anw)) {
            this.remove();
            return false;
        }
        if (this.isInvulnerableTo(anw) || this.invisible || this.isMarker()) {
            return false;
        }
        if (anw.isExplosion()) {
            this.brokenByAnything(anw);
            this.remove();
            return false;
        }
        if (DamageSource.IN_FIRE.equals(anw)) {
            if (this.isOnFire()) {
                this.causeDamage(anw, 0.15f);
            }
            else {
                this.setSecondsOnFire(5);
            }
            return false;
        }
        if (DamageSource.ON_FIRE.equals(anw) && this.getHealth() > 0.5f) {
            this.causeDamage(anw, 4.0f);
            return false;
        }
        final boolean boolean4 = anw.getDirectEntity() instanceof AbstractArrow;
        final boolean boolean5 = boolean4 && ((AbstractArrow)anw.getDirectEntity()).getPierceLevel() > 0;
        final boolean boolean6 = "player".equals(anw.getMsgId());
        if (!boolean6 && !boolean4) {
            return false;
        }
        if (anw.getEntity() instanceof Player && !((Player)anw.getEntity()).abilities.mayBuild) {
            return false;
        }
        if (anw.isCreativePlayer()) {
            this.playBrokenSound();
            this.showBreakingParticles();
            this.remove();
            return boolean5;
        }
        final long long7 = this.level.getGameTime();
        if (long7 - this.lastHit <= 5L || boolean4) {
            this.brokenByPlayer(anw);
            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 anw, final float float2) {
        float float3 = this.getHealth();
        float3 -= float2;
        if (float3 <= 0.5f) {
            this.brokenByAnything(anw);
            this.remove();
        }
        else {
            this.setHealth(float3);
        }
    }
    
    private void brokenByPlayer(final DamageSource anw) {
        Block.popResource(this.level, this.blockPosition(), new ItemStack(Items.ARMOR_STAND));
        this.brokenByAnything(anw);
    }
    
    private void brokenByAnything(final DamageSource anw) {
        this.playBrokenSound();
        this.dropAllDeathLoot(anw);
        for (int integer3 = 0; integer3 < this.handItems.size(); ++integer3) {
            final ItemStack bki4 = this.handItems.get(integer3);
            if (!bki4.isEmpty()) {
                Block.popResource(this.level, this.blockPosition().above(), bki4);
                this.handItems.set(integer3, ItemStack.EMPTY);
            }
        }
        for (int integer3 = 0; integer3 < this.armorItems.size(); ++integer3) {
            final ItemStack bki4 = this.armorItems.get(integer3);
            if (!bki4.isEmpty()) {
                Block.popResource(this.level, this.blockPosition().above(), bki4);
                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 apj, final EntityDimensions aon) {
        return aon.height * (this.isBaby() ? 0.5f : 0.9f);
    }
    
    @Override
    public double getMyRidingOffset() {
        return this.isMarker() ? 0.0 : 0.10000000149011612;
    }
    
    @Override
    public void travel(final Vec3 dem) {
        if (!this.hasPhysics()) {
            return;
        }
        super.travel(dem);
    }
    
    @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 gn2 = this.entityData.<Rotations>get(ArmorStand.DATA_HEAD_POSE);
        if (!this.headPose.equals(gn2)) {
            this.setHeadPose(gn2);
        }
        final Rotations gn3 = this.entityData.<Rotations>get(ArmorStand.DATA_BODY_POSE);
        if (!this.bodyPose.equals(gn3)) {
            this.setBodyPose(gn3);
        }
        final Rotations gn4 = this.entityData.<Rotations>get(ArmorStand.DATA_LEFT_ARM_POSE);
        if (!this.leftArmPose.equals(gn4)) {
            this.setLeftArmPose(gn4);
        }
        final Rotations gn5 = this.entityData.<Rotations>get(ArmorStand.DATA_RIGHT_ARM_POSE);
        if (!this.rightArmPose.equals(gn5)) {
            this.setRightArmPose(gn5);
        }
        final Rotations gn6 = this.entityData.<Rotations>get(ArmorStand.DATA_LEFT_LEG_POSE);
        if (!this.leftLegPose.equals(gn6)) {
            this.setLeftLegPose(gn6);
        }
        final Rotations gn7 = this.entityData.<Rotations>get(ArmorStand.DATA_RIGHT_LEG_POSE);
        if (!this.rightLegPose.equals(gn7)) {
            this.setRightLegPose(gn7);
        }
    }
    
    @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 gn) {
        this.headPose = gn;
        this.entityData.<Rotations>set(ArmorStand.DATA_HEAD_POSE, gn);
    }
    
    public void setBodyPose(final Rotations gn) {
        this.bodyPose = gn;
        this.entityData.<Rotations>set(ArmorStand.DATA_BODY_POSE, gn);
    }
    
    public void setLeftArmPose(final Rotations gn) {
        this.leftArmPose = gn;
        this.entityData.<Rotations>set(ArmorStand.DATA_LEFT_ARM_POSE, gn);
    }
    
    public void setRightArmPose(final Rotations gn) {
        this.rightArmPose = gn;
        this.entityData.<Rotations>set(ArmorStand.DATA_RIGHT_ARM_POSE, gn);
    }
    
    public void setLeftLegPose(final Rotations gn) {
        this.leftLegPose = gn;
        this.entityData.<Rotations>set(ArmorStand.DATA_LEFT_LEG_POSE, gn);
    }
    
    public void setRightLegPose(final Rotations gn) {
        this.rightLegPose = gn;
        this.entityData.<Rotations>set(ArmorStand.DATA_RIGHT_LEG_POSE, gn);
    }
    
    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 aom) {
        return aom instanceof Player && !this.level.mayInteract((Player)aom, this.blockPosition());
    }
    
    @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 anw) {
        return SoundEvents.ARMOR_STAND_HIT;
    }
    
    @Nullable
    @Override
    protected SoundEvent getDeathSound() {
        return SoundEvents.ARMOR_STAND_BREAK;
    }
    
    @Override
    public void thunderHit(final LightningBolt aox) {
    }
    
    @Override
    public boolean isAffectedByPotions() {
        return false;
    }
    
    @Override
    public void onSyncedDataUpdated(final EntityDataAccessor<?> tq) {
        if (ArmorStand.DATA_CLIENT_FLAGS.equals(tq)) {
            this.refreshDimensions();
            this.blocksBuilding = !this.isMarker();
        }
        super.onSyncedDataUpdated(tq);
    }
    
    @Override
    public boolean attackable() {
        return false;
    }
    
    @Override
    public EntityDimensions getDimensions(final Pose apj) {
        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 = (aom -> aom instanceof AbstractMinecart && aom.getMinecartType() == AbstractMinecart.Type.RIDEABLE);
    }
}
