--- a/net/minecraft/world/entity/animal/Panda.java
+++ b/net/minecraft/world/entity/animal/Panda.java
@@ -1,7 +1,9 @@
 package net.minecraft.world.entity.animal;
 
 import java.util.EnumSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Objects;
 import java.util.function.IntFunction;
 import java.util.function.Predicate;
 import javax.annotation.Nullable;
@@ -56,6 +58,7 @@
 import net.minecraft.world.item.Items;
 import net.minecraft.world.item.crafting.Ingredient;
 import net.minecraft.world.level.GameRules;
+import net.minecraft.world.level.ItemLike;
 import net.minecraft.world.level.Level;
 import net.minecraft.world.level.ServerLevelAccessor;
 import net.minecraft.world.level.block.Blocks;
@@ -64,7 +67,13 @@
 import net.minecraft.world.phys.Vec3;
 import org.joml.Vector3f;
 
+// CraftBukkit start;
+import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetEvent;
+// CraftBukkit end
+
 public class Panda extends Animal {
+
     private static final EntityDataAccessor<Integer> UNHAPPY_COUNTER = SynchedEntityData.defineId(Panda.class, EntityDataSerializers.INT);
     private static final EntityDataAccessor<Integer> SNEEZE_COUNTER = SynchedEntityData.defineId(Panda.class, EntityDataSerializers.INT);
     private static final EntityDataAccessor<Integer> EAT_COUNTER = SynchedEntityData.defineId(Panda.class, EntityDataSerializers.INT);
@@ -90,9 +99,10 @@
     private float rollAmount;
     private float rollAmountO;
     Panda.PandaLookAtPlayerGoal lookAtPlayerGoal;
-    static final Predicate<ItemEntity> PANDA_ITEMS = (item) -> {
-        ItemStack itemStack = item.getItem();
-        return (itemStack.is(Blocks.BAMBOO.asItem()) || itemStack.is(Blocks.CAKE.asItem())) && item.isAlive() && !item.hasPickUpDelay();
+    static final Predicate<ItemEntity> PANDA_ITEMS = (entityitem) -> {
+        ItemStack itemstack = entityitem.getItem();
+
+        return (itemstack.is(Blocks.BAMBOO.asItem()) || itemstack.is(Blocks.CAKE.asItem())) && entityitem.isAlive() && !entityitem.hasPickUpDelay();
     };
 
     public Panda(EntityType<? extends Panda> type, Level world) {
@@ -106,20 +116,17 @@
 
     @Override
     public boolean canTakeItem(ItemStack stack) {
-        EquipmentSlot equipmentSlot = Mob.getEquipmentSlotForItem(stack);
-        if (!this.getItemBySlot(equipmentSlot).isEmpty()) {
-            return false;
-        } else {
-            return equipmentSlot == EquipmentSlot.MAINHAND && super.canTakeItem(stack);
-        }
+        EquipmentSlot enumitemslot = Mob.getEquipmentSlotForItem(stack);
+
+        return !this.getItemBySlot(enumitemslot).isEmpty() ? false : enumitemslot == EquipmentSlot.MAINHAND && super.canTakeItem(stack);
     }
 
     public int getUnhappyCounter() {
-        return this.entityData.get(UNHAPPY_COUNTER);
+        return (Integer) this.entityData.get(Panda.UNHAPPY_COUNTER);
     }
 
     public void setUnhappyCounter(int askForBambooTicks) {
-        this.entityData.set(UNHAPPY_COUNTER, askForBambooTicks);
+        this.entityData.set(Panda.UNHAPPY_COUNTER, askForBambooTicks);
     }
 
     public boolean isSneezing() {
@@ -131,6 +138,7 @@
     }
 
     public void sit(boolean sitting) {
+        if (!new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), sitting).callEvent()) return; // Paper start - call EntityToggleSitEvent
         this.setFlag(8, sitting);
     }
 
@@ -143,19 +151,19 @@
     }
 
     public boolean isEating() {
-        return this.entityData.get(EAT_COUNTER) > 0;
+        return (Integer) this.entityData.get(Panda.EAT_COUNTER) > 0;
     }
 
     public void eat(boolean eating) {
-        this.entityData.set(EAT_COUNTER, eating ? 1 : 0);
+        this.entityData.set(Panda.EAT_COUNTER, eating ? 1 : 0);
     }
 
     public int getEatCounter() {
-        return this.entityData.get(EAT_COUNTER);
+        return (Integer) this.entityData.get(Panda.EAT_COUNTER);
     }
 
     public void setEatCounter(int eatingTicks) {
-        this.entityData.set(EAT_COUNTER, eatingTicks);
+        this.entityData.set(Panda.EAT_COUNTER, eatingTicks);
     }
 
     public void sneeze(boolean sneezing) {
@@ -167,15 +175,15 @@
     }
 
     public int getSneezeCounter() {
-        return this.entityData.get(SNEEZE_COUNTER);
+        return (Integer) this.entityData.get(Panda.SNEEZE_COUNTER);
     }
 
     public void setSneezeCounter(int sneezeProgress) {
-        this.entityData.set(SNEEZE_COUNTER, sneezeProgress);
+        this.entityData.set(Panda.SNEEZE_COUNTER, sneezeProgress);
     }
 
     public Panda.Gene getMainGene() {
-        return Panda.Gene.byId(this.entityData.get(MAIN_GENE_ID));
+        return Panda.Gene.byId((Byte) this.entityData.get(Panda.MAIN_GENE_ID));
     }
 
     public void setMainGene(Panda.Gene gene) {
@@ -183,11 +191,11 @@
             gene = Panda.Gene.getRandom(this.random);
         }
 
-        this.entityData.set(MAIN_GENE_ID, (byte)gene.getId());
+        this.entityData.set(Panda.MAIN_GENE_ID, (byte) gene.getId());
     }
 
     public Panda.Gene getHiddenGene() {
-        return Panda.Gene.byId(this.entityData.get(HIDDEN_GENE_ID));
+        return Panda.Gene.byId((Byte) this.entityData.get(Panda.HIDDEN_GENE_ID));
     }
 
     public void setHiddenGene(Panda.Gene gene) {
@@ -195,7 +203,7 @@
             gene = Panda.Gene.getRandom(this.random);
         }
 
-        this.entityData.set(HIDDEN_GENE_ID, (byte)gene.getId());
+        this.entityData.set(Panda.HIDDEN_GENE_ID, (byte) gene.getId());
     }
 
     public boolean isRolling() {
@@ -209,24 +217,25 @@
     @Override
     protected void defineSynchedData() {
         super.defineSynchedData();
-        this.entityData.define(UNHAPPY_COUNTER, 0);
-        this.entityData.define(SNEEZE_COUNTER, 0);
-        this.entityData.define(MAIN_GENE_ID, (byte)0);
-        this.entityData.define(HIDDEN_GENE_ID, (byte)0);
-        this.entityData.define(DATA_ID_FLAGS, (byte)0);
-        this.entityData.define(EAT_COUNTER, 0);
+        this.entityData.define(Panda.UNHAPPY_COUNTER, 0);
+        this.entityData.define(Panda.SNEEZE_COUNTER, 0);
+        this.entityData.define(Panda.MAIN_GENE_ID, (byte) 0);
+        this.entityData.define(Panda.HIDDEN_GENE_ID, (byte) 0);
+        this.entityData.define(Panda.DATA_ID_FLAGS, (byte) 0);
+        this.entityData.define(Panda.EAT_COUNTER, 0);
     }
 
     private boolean getFlag(int bitmask) {
-        return (this.entityData.get(DATA_ID_FLAGS) & bitmask) != 0;
+        return ((Byte) this.entityData.get(Panda.DATA_ID_FLAGS) & bitmask) != 0;
     }
 
     private void setFlag(int mask, boolean value) {
-        byte b = this.entityData.get(DATA_ID_FLAGS);
+        byte b0 = (Byte) this.entityData.get(Panda.DATA_ID_FLAGS);
+
         if (value) {
-            this.entityData.set(DATA_ID_FLAGS, (byte)(b | mask));
+            this.entityData.set(Panda.DATA_ID_FLAGS, (byte) (b0 | mask));
         } else {
-            this.entityData.set(DATA_ID_FLAGS, (byte)(b & ~mask));
+            this.entityData.set(Panda.DATA_ID_FLAGS, (byte) (b0 & ~mask));
         }
 
     }
@@ -248,17 +257,19 @@
     @Nullable
     @Override
     public AgeableMob getBreedOffspring(ServerLevel world, AgeableMob entity) {
-        Panda panda = EntityType.PANDA.create(world);
-        if (panda != null) {
+        Panda entitypanda = (Panda) EntityType.PANDA.create(world);
+
+        if (entitypanda != null) {
             if (entity instanceof Panda) {
-                Panda panda2 = (Panda)entity;
-                panda.setGeneFromParents(this, panda2);
+                Panda entitypanda1 = (Panda) entity;
+
+                entitypanda.setGeneFromParents(this, entitypanda1);
             }
 
-            panda.setAttributes();
+            entitypanda.setAttributes();
         }
 
-        return panda;
+        return entitypanda;
     }
 
     @Override
@@ -266,7 +277,7 @@
         this.goalSelector.addGoal(0, new FloatGoal(this));
         this.goalSelector.addGoal(2, new Panda.PandaPanicGoal(this, 2.0D));
         this.goalSelector.addGoal(2, new Panda.PandaBreedGoal(this, 1.0D));
-        this.goalSelector.addGoal(3, new Panda.PandaAttackGoal(this, (double)1.2F, true));
+        this.goalSelector.addGoal(3, new Panda.PandaAttackGoal(this, 1.2000000476837158D, true));
         this.goalSelector.addGoal(4, new TemptGoal(this, 1.0D, Ingredient.of(Blocks.BAMBOO.asItem()), false));
         this.goalSelector.addGoal(6, new Panda.PandaAvoidGoal<>(this, Player.class, 8.0F, 2.0D, 2.0D));
         this.goalSelector.addGoal(6, new Panda.PandaAvoidGoal<>(this, Monster.class, 4.0F, 2.0D, 2.0D));
@@ -279,11 +290,11 @@
         this.goalSelector.addGoal(12, new Panda.PandaRollGoal(this));
         this.goalSelector.addGoal(13, new FollowParentGoal(this, 1.25D));
         this.goalSelector.addGoal(14, new WaterAvoidingRandomStrollGoal(this, 1.0D));
-        this.targetSelector.addGoal(1, (new Panda.PandaHurtByTargetGoal(this)).setAlertOthers(new Class[0]));
+        this.targetSelector.addGoal(1, (new Panda.PandaHurtByTargetGoal(this, new Class[0])).setAlertOthers(new Class[0]));
     }
 
     public static AttributeSupplier.Builder createAttributes() {
-        return Mob.createMobAttributes().add(Attributes.MOVEMENT_SPEED, (double)0.15F).add(Attributes.ATTACK_DAMAGE, 6.0D);
+        return Mob.createMobAttributes().add(Attributes.MOVEMENT_SPEED, 0.15000000596046448D).add(Attributes.ATTACK_DAMAGE, 6.0D);
     }
 
     public Panda.Gene getVariant() {
@@ -342,15 +353,16 @@
             }
         }
 
-        LivingEntity livingEntity = this.getTarget();
-        if (livingEntity == null) {
+        LivingEntity entityliving = this.getTarget();
+
+        if (entityliving == null) {
             this.gotBamboo = false;
             this.didBite = false;
         }
 
         if (this.getUnhappyCounter() > 0) {
-            if (livingEntity != null) {
-                this.lookAt(livingEntity, 90.0F, 90.0F);
+            if (entityliving != null) {
+                this.lookAt(entityliving, 90.0F, 90.0F);
             }
 
             if (this.getUnhappyCounter() == 29 || this.getUnhappyCounter() == 14) {
@@ -420,17 +432,19 @@
 
     private void addEatingParticles() {
         if (this.getEatCounter() % 5 == 0) {
-            this.playSound(SoundEvents.PANDA_EAT, 0.5F + 0.5F * (float)this.random.nextInt(2), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
+            this.playSound(SoundEvents.PANDA_EAT, 0.5F + 0.5F * (float) this.random.nextInt(2), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
 
-            for(int i = 0; i < 6; ++i) {
-                Vec3 vec3 = new Vec3(((double)this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, ((double)this.random.nextFloat() - 0.5D) * 0.1D);
-                vec3 = vec3.xRot(-this.getXRot() * ((float)Math.PI / 180F));
-                vec3 = vec3.yRot(-this.getYRot() * ((float)Math.PI / 180F));
-                double d = (double)(-this.random.nextFloat()) * 0.6D - 0.3D;
-                Vec3 vec32 = new Vec3(((double)this.random.nextFloat() - 0.5D) * 0.8D, d, 1.0D + ((double)this.random.nextFloat() - 0.5D) * 0.4D);
-                vec32 = vec32.yRot(-this.yBodyRot * ((float)Math.PI / 180F));
-                vec32 = vec32.add(this.getX(), this.getEyeY() + 1.0D, this.getZ());
-                this.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, this.getItemBySlot(EquipmentSlot.MAINHAND)), vec32.x, vec32.y, vec32.z, vec3.x, vec3.y + 0.05D, vec3.z);
+            for (int i = 0; i < 6; ++i) {
+                Vec3 vec3d = new Vec3(((double) this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, ((double) this.random.nextFloat() - 0.5D) * 0.1D);
+
+                vec3d = vec3d.xRot(-this.getXRot() * 0.017453292F);
+                vec3d = vec3d.yRot(-this.getYRot() * 0.017453292F);
+                double d0 = (double) (-this.random.nextFloat()) * 0.6D - 0.3D;
+                Vec3 vec3d1 = new Vec3(((double) this.random.nextFloat() - 0.5D) * 0.8D, d0, 1.0D + ((double) this.random.nextFloat() - 0.5D) * 0.4D);
+
+                vec3d1 = vec3d1.yRot(-this.yBodyRot * 0.017453292F);
+                vec3d1 = vec3d1.add(this.getX(), this.getEyeY() + 1.0D, this.getZ());
+                this.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, this.getItemBySlot(EquipmentSlot.MAINHAND)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z);
             }
         }
 
@@ -484,16 +498,18 @@
             this.roll(false);
         } else {
             if (!this.level().isClientSide) {
-                Vec3 vec3 = this.getDeltaMovement();
+                Vec3 vec3d = this.getDeltaMovement();
+
                 if (this.rollCounter == 1) {
-                    float f = this.getYRot() * ((float)Math.PI / 180F);
-                    float g = this.isBaby() ? 0.1F : 0.2F;
-                    this.rollDelta = new Vec3(vec3.x + (double)(-Mth.sin(f) * g), 0.0D, vec3.z + (double)(Mth.cos(f) * g));
+                    float f = this.getYRot() * 0.017453292F;
+                    float f1 = this.isBaby() ? 0.1F : 0.2F;
+
+                    this.rollDelta = new Vec3(vec3d.x + (double) (-Mth.sin(f) * f1), 0.0D, vec3d.z + (double) (Mth.cos(f) * f1));
                     this.setDeltaMovement(this.rollDelta.add(0.0D, 0.27D, 0.0D));
-                } else if ((float)this.rollCounter != 7.0F && (float)this.rollCounter != 15.0F && (float)this.rollCounter != 23.0F) {
-                    this.setDeltaMovement(this.rollDelta.x, vec3.y, this.rollDelta.z);
+                } else if ((float) this.rollCounter != 7.0F && (float) this.rollCounter != 15.0F && (float) this.rollCounter != 23.0F) {
+                    this.setDeltaMovement(this.rollDelta.x, vec3d.y, this.rollDelta.z);
                 } else {
-                    this.setDeltaMovement(0.0D, this.onGround() ? 0.27D : vec3.y, 0.0D);
+                    this.setDeltaMovement(0.0D, this.onGround() ? 0.27D : vec3d.y, 0.0D);
                 }
             }
 
@@ -501,30 +517,40 @@
     }
 
     private void afterSneeze() {
-        Vec3 vec3 = this.getDeltaMovement();
-        this.level().addParticle(ParticleTypes.SNEEZE, this.getX() - (double)(this.getBbWidth() + 1.0F) * 0.5D * (double)Mth.sin(this.yBodyRot * ((float)Math.PI / 180F)), this.getEyeY() - (double)0.1F, this.getZ() + (double)(this.getBbWidth() + 1.0F) * 0.5D * (double)Mth.cos(this.yBodyRot * ((float)Math.PI / 180F)), vec3.x, 0.0D, vec3.z);
+        Vec3 vec3d = this.getDeltaMovement();
+
+        this.level().addParticle(ParticleTypes.SNEEZE, this.getX() - (double) (this.getBbWidth() + 1.0F) * 0.5D * (double) Mth.sin(this.yBodyRot * 0.017453292F), this.getEyeY() - 0.10000000149011612D, this.getZ() + (double) (this.getBbWidth() + 1.0F) * 0.5D * (double) Mth.cos(this.yBodyRot * 0.017453292F), vec3d.x, 0.0D, vec3d.z);
         this.playSound(SoundEvents.PANDA_SNEEZE, 1.0F, 1.0F);
+        List<Panda> list = this.level().getEntitiesOfClass(Panda.class, this.getBoundingBox().inflate(10.0D));
+        Iterator iterator = list.iterator();
 
-        for(Panda panda : this.level().getEntitiesOfClass(Panda.class, this.getBoundingBox().inflate(10.0D))) {
-            if (!panda.isBaby() && panda.onGround() && !panda.isInWater() && panda.canPerformAction()) {
-                panda.jumpFromGround();
+        while (iterator.hasNext()) {
+            Panda entitypanda = (Panda) iterator.next();
+
+            if (!entitypanda.isBaby() && entitypanda.onGround() && !entitypanda.isInWater() && entitypanda.canPerformAction()) {
+                if (new com.destroystokyo.paper.event.entity.EntityJumpEvent(getBukkitLivingEntity()).callEvent()) { // Paper
+                entitypanda.jumpFromGround();
+                } else { this.setJumping(false); } // Paper - setJumping(false) stops a potential loop
             }
         }
 
         if (!this.level().isClientSide() && this.random.nextInt(700) == 0 && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
-            this.spawnAtLocation(Items.SLIME_BALL);
+            this.forceDrops = true; // Paper
+            this.spawnAtLocation((ItemLike) Items.SLIME_BALL);
+            this.forceDrops = false; // Paper
         }
 
     }
 
     @Override
     protected void pickUpItem(ItemEntity item) {
-        if (this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty() && PANDA_ITEMS.test(item)) {
+        if (!CraftEventFactory.callEntityPickupItemEvent(this, item, 0, !(this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty() && Panda.PANDA_ITEMS.test(item))).isCancelled()) { // CraftBukkit
             this.onItemPickup(item);
-            ItemStack itemStack = item.getItem();
-            this.setItemSlot(EquipmentSlot.MAINHAND, itemStack);
+            ItemStack itemstack = item.getItem();
+
+            this.setItemSlot(EquipmentSlot.MAINHAND, itemstack);
             this.setGuaranteedDrop(EquipmentSlot.MAINHAND);
-            this.take(item, itemStack.getCount());
+            this.take(item, itemstack.getCount());
             item.discard();
         }
 
@@ -542,15 +568,16 @@
     @Nullable
     @Override
     public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType spawnReason, @Nullable SpawnGroupData entityData, @Nullable CompoundTag entityNbt) {
-        RandomSource randomSource = world.getRandom();
-        this.setMainGene(Panda.Gene.getRandom(randomSource));
-        this.setHiddenGene(Panda.Gene.getRandom(randomSource));
+        RandomSource randomsource = world.getRandom();
+
+        this.setMainGene(Panda.Gene.getRandom(randomsource));
+        this.setHiddenGene(Panda.Gene.getRandom(randomsource));
         this.setAttributes();
         if (entityData == null) {
             entityData = new AgeableMob.AgeableMobGroupData(0.2F);
         }
 
-        return super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityNbt);
+        return super.finalizeSpawn(world, difficulty, spawnReason, (SpawnGroupData) entityData, entityNbt);
     }
 
     public void setGeneFromParents(Panda mother, @Nullable Panda father) {
@@ -590,7 +617,7 @@
         }
 
         if (this.isLazy()) {
-            this.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue((double)0.07F);
+            this.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.07000000029802322D);
         }
 
     }
@@ -606,22 +633,23 @@
 
     @Override
     public InteractionResult mobInteract(Player player, InteractionHand hand) {
-        ItemStack itemStack = player.getItemInHand(hand);
+        ItemStack itemstack = player.getItemInHand(hand);
+
         if (this.isScared()) {
             return InteractionResult.PASS;
         } else if (this.isOnBack()) {
             this.setOnBack(false);
             return InteractionResult.sidedSuccess(this.level().isClientSide);
-        } else if (this.isFood(itemStack)) {
+        } else if (this.isFood(itemstack)) {
             if (this.getTarget() != null) {
                 this.gotBamboo = true;
             }
 
             if (this.isBaby()) {
-                this.usePlayerItem(player, hand, itemStack);
-                this.ageUp((int)((float)(-this.getAge() / 20) * 0.1F), true);
+                this.usePlayerItem(player, hand, itemstack);
+                this.ageUp((int) ((float) (-this.getAge() / 20) * 0.1F), true);
             } else if (!this.level().isClientSide && this.getAge() == 0 && this.canFallInLove()) {
-                this.usePlayerItem(player, hand, itemStack);
+                this.usePlayerItem(player, hand, itemstack);
                 this.setInLove(player);
             } else {
                 if (this.level().isClientSide || this.isSitting() || this.isInWater()) {
@@ -630,13 +658,16 @@
 
                 this.tryToSit();
                 this.eat(true);
-                ItemStack itemStack2 = this.getItemBySlot(EquipmentSlot.MAINHAND);
-                if (!itemStack2.isEmpty() && !player.getAbilities().instabuild) {
-                    this.spawnAtLocation(itemStack2);
+                ItemStack itemstack1 = this.getItemBySlot(EquipmentSlot.MAINHAND);
+
+                if (!itemstack1.isEmpty() && !player.getAbilities().instabuild) {
+                    this.forceDrops = true; // Paper
+                    this.spawnAtLocation(itemstack1);
+                    this.forceDrops = false; // Paper
                 }
 
-                this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(itemStack.getItem(), 1));
-                this.usePlayerItem(player, hand, itemStack);
+                this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(itemstack.getItem(), 1));
+                this.usePlayerItem(player, hand, itemstack);
             }
 
             return InteractionResult.SUCCESS;
@@ -648,11 +679,7 @@
     @Nullable
     @Override
     protected SoundEvent getAmbientSound() {
-        if (this.isAggressive()) {
-            return SoundEvents.PANDA_AGGRESSIVE_AMBIENT;
-        } else {
-            return this.isWorried() ? SoundEvents.PANDA_WORRIED_AMBIENT : SoundEvents.PANDA_AMBIENT;
-        }
+        return this.isAggressive() ? SoundEvents.PANDA_AGGRESSIVE_AMBIENT : (this.isWorried() ? SoundEvents.PANDA_WORRIED_AMBIENT : SoundEvents.PANDA_AMBIENT);
     }
 
     @Override
@@ -690,14 +717,26 @@
         return new Vector3f(0.0F, dimensions.height - (this.isBaby() ? 0.4375F : 0.0F) * scaleFactor, 0.0F);
     }
 
+    private static class PandaMoveControl extends MoveControl {
+
+        private final Panda panda;
+
+        public PandaMoveControl(Panda panda) {
+            super(panda);
+            this.panda = panda;
+        }
+
+        @Override
+        public void tick() {
+            if (this.panda.canPerformAction()) {
+                super.tick();
+            }
+        }
+    }
+
     public static enum Gene implements StringRepresentable {
-        NORMAL(0, "normal", false),
-        LAZY(1, "lazy", false),
-        WORRIED(2, "worried", false),
-        PLAYFUL(3, "playful", false),
-        BROWN(4, "brown", true),
-        WEAK(5, "weak", true),
-        AGGRESSIVE(6, "aggressive", false);
+
+        NORMAL(0, "normal", false), LAZY(1, "lazy", false), WORRIED(2, "worried", false), PLAYFUL(3, "playful", false), BROWN(4, "brown", true), WEAK(5, "weak", true), AGGRESSIVE(6, "aggressive", false);
 
         public static final StringRepresentable.EnumCodec<Panda.Gene> CODEC = StringRepresentable.fromEnum(Panda.Gene::values);
         private static final IntFunction<Panda.Gene> BY_ID = ByIdMap.continuous(Panda.Gene::getId, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
@@ -706,10 +745,10 @@
         private final String name;
         private final boolean isRecessive;
 
-        private Gene(int id, String name, boolean recessive) {
-            this.id = id;
-            this.name = name;
-            this.isRecessive = recessive;
+        private Gene(int i, String s, boolean flag) {
+            this.id = i;
+            this.name = s;
+            this.isRecessive = flag;
         }
 
         public int getId() {
@@ -726,68 +765,51 @@
         }
 
         static Panda.Gene getVariantFromGenes(Panda.Gene mainGene, Panda.Gene hiddenGene) {
-            if (mainGene.isRecessive()) {
-                return mainGene == hiddenGene ? mainGene : NORMAL;
-            } else {
-                return mainGene;
-            }
+            return mainGene.isRecessive() ? (mainGene == hiddenGene ? mainGene : Panda.Gene.NORMAL) : mainGene;
         }
 
         public static Panda.Gene byId(int id) {
-            return BY_ID.apply(id);
+            return (Panda.Gene) Panda.Gene.BY_ID.apply(id);
         }
 
         public static Panda.Gene byName(String name) {
-            return CODEC.byName(name, NORMAL);
+            return (Panda.Gene) Panda.Gene.CODEC.byName(name, Panda.Gene.NORMAL);
         }
 
         public static Panda.Gene getRandom(RandomSource random) {
             int i = random.nextInt(16);
-            if (i == 0) {
-                return LAZY;
-            } else if (i == 1) {
-                return WORRIED;
-            } else if (i == 2) {
-                return PLAYFUL;
-            } else if (i == 4) {
-                return AGGRESSIVE;
-            } else if (i < 9) {
-                return WEAK;
-            } else {
-                return i < 11 ? BROWN : NORMAL;
-            }
+
+            return i == 0 ? Panda.Gene.LAZY : (i == 1 ? Panda.Gene.WORRIED : (i == 2 ? Panda.Gene.PLAYFUL : (i == 4 ? Panda.Gene.AGGRESSIVE : (i < 9 ? Panda.Gene.WEAK : (i < 11 ? Panda.Gene.BROWN : Panda.Gene.NORMAL)))));
         }
     }
 
-    static class PandaAttackGoal extends MeleeAttackGoal {
+    private static class PandaPanicGoal extends PanicGoal {
+
         private final Panda panda;
 
-        public PandaAttackGoal(Panda panda, double speed, boolean pauseWhenMobIdle) {
-            super(panda, speed, pauseWhenMobIdle);
+        public PandaPanicGoal(Panda panda, double speed) {
+            super(panda, speed);
             this.panda = panda;
         }
 
         @Override
-        public boolean canUse() {
-            return this.panda.canPerformAction() && super.canUse();
-        }
-    }
-
-    static class PandaAvoidGoal<T extends LivingEntity> extends AvoidEntityGoal<T> {
-        private final Panda panda;
-
-        public PandaAvoidGoal(Panda panda, Class<T> fleeFromType, float distance, double slowSpeed, double fastSpeed) {
-            super(panda, fleeFromType, distance, slowSpeed, fastSpeed, EntitySelector.NO_SPECTATORS::test);
-            this.panda = panda;
+        protected boolean shouldPanic() {
+            return this.mob.isFreezing() || this.mob.isOnFire();
         }
 
         @Override
-        public boolean canUse() {
-            return this.panda.isWorried() && this.panda.canPerformAction() && super.canUse();
+        public boolean canContinueToUse() {
+            if (this.panda.isSitting()) {
+                this.panda.getNavigation().stop();
+                return false;
+            } else {
+                return super.canContinueToUse();
+            }
         }
     }
 
-    static class PandaBreedGoal extends BreedGoal {
+    private static class PandaBreedGoal extends BreedGoal {
+
         private final Panda panda;
         private int unhappyCooldown;
 
@@ -804,8 +826,9 @@
                         this.panda.setUnhappyCounter(32);
                         this.unhappyCooldown = this.panda.tickCount + 600;
                         if (this.panda.isEffectiveAi()) {
-                            Player player = this.level.getNearestPlayer(Panda.BREED_TARGETING, this.panda);
-                            this.panda.lookAtPlayerGoal.setTarget(player);
+                            Player entityhuman = this.level.getNearestPlayer(Panda.BREED_TARGETING, this.panda);
+
+                            this.panda.lookAtPlayerGoal.setTarget(entityhuman);
                         }
                     }
 
@@ -819,15 +842,15 @@
         }
 
         private boolean canFindBamboo() {
-            BlockPos blockPos = this.panda.blockPosition();
-            BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
+            BlockPos blockposition = this.panda.blockPosition();
+            BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
 
-            for(int i = 0; i < 3; ++i) {
-                for(int j = 0; j < 8; ++j) {
-                    for(int k = 0; k <= j; k = k > 0 ? -k : 1 - k) {
-                        for(int l = k < j && k > -j ? j : 0; l <= j; l = l > 0 ? -l : 1 - l) {
-                            mutableBlockPos.setWithOffset(blockPos, k, i, l);
-                            if (this.level.getBlockState(mutableBlockPos).is(Blocks.BAMBOO)) {
+            for (int i = 0; i < 3; ++i) {
+                for (int j = 0; j < 8; ++j) {
+                    for (int k = 0; k <= j; k = k > 0 ? -k : 1 - k) {
+                        for (int l = k < j && k > -j ? j : 0; l <= j; l = l > 0 ? -l : 1 - l) {
+                            blockposition_mutableblockposition.setWithOffset(blockposition, k, i, l);
+                            if (this.level.getBlockState(blockposition_mutableblockposition).is(Blocks.BAMBOO)) {
                                 return true;
                             }
                         }
@@ -839,34 +862,104 @@
         }
     }
 
-    static class PandaHurtByTargetGoal extends HurtByTargetGoal {
+    private static class PandaAttackGoal extends MeleeAttackGoal {
+
         private final Panda panda;
 
-        public PandaHurtByTargetGoal(Panda panda, Class<?>... noRevengeTypes) {
-            super(panda, noRevengeTypes);
+        public PandaAttackGoal(Panda panda, double speed, boolean pauseWhenMobIdle) {
+            super(panda, speed, pauseWhenMobIdle);
             this.panda = panda;
         }
 
         @Override
-        public boolean canContinueToUse() {
-            if (!this.panda.gotBamboo && !this.panda.didBite) {
-                return super.canContinueToUse();
+        public boolean canUse() {
+            return this.panda.canPerformAction() && super.canUse();
+        }
+    }
+
+    private static class PandaAvoidGoal<T extends LivingEntity> extends AvoidEntityGoal<T> {
+
+        private final Panda panda;
+
+        public PandaAvoidGoal(Panda panda, Class<T> fleeFromType, float distance, double slowSpeed, double fastSpeed) {
+            // Predicate predicate = IEntitySelector.NO_SPECTATORS;
+
+            // Objects.requireNonNull(predicate);
+            super(panda, fleeFromType, distance, slowSpeed, fastSpeed, EntitySelector.NO_SPECTATORS::test);
+            this.panda = panda;
+        }
+
+        @Override
+        public boolean canUse() {
+            return this.panda.isWorried() && this.panda.canPerformAction() && super.canUse();
+        }
+    }
+
+    private class PandaSitGoal extends Goal {
+
+        private int cooldown;
+
+        public PandaSitGoal() {
+            this.setFlags(EnumSet.of(Goal.Flag.MOVE));
+        }
+
+        @Override
+        public boolean canUse() {
+            if (this.cooldown <= Panda.this.tickCount && !Panda.this.isBaby() && !Panda.this.isInWater() && Panda.this.canPerformAction() && Panda.this.getUnhappyCounter() <= 0) {
+                List<ItemEntity> list = Panda.this.level().getEntitiesOfClass(ItemEntity.class, Panda.this.getBoundingBox().inflate(6.0D, 6.0D, 6.0D), Panda.PANDA_ITEMS);
+
+                return !list.isEmpty() || !Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty();
             } else {
-                this.panda.setTarget((LivingEntity)null);
                 return false;
             }
         }
 
         @Override
-        protected void alertOther(Mob mob, LivingEntity target) {
-            if (mob instanceof Panda && mob.isAggressive()) {
-                mob.setTarget(target);
+        public boolean canContinueToUse() {
+            return !Panda.this.isInWater() && (Panda.this.isLazy() || Panda.this.random.nextInt(reducedTickDelay(600)) != 1) ? Panda.this.random.nextInt(reducedTickDelay(2000)) != 1 : false;
+        }
+
+        @Override
+        public void tick() {
+            if (!Panda.this.isSitting() && !Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty()) {
+                Panda.this.tryToSit();
+            }
+
+        }
+
+        @Override
+        public void start() {
+            List<ItemEntity> list = Panda.this.level().getEntitiesOfClass(ItemEntity.class, Panda.this.getBoundingBox().inflate(8.0D, 8.0D, 8.0D), Panda.PANDA_ITEMS);
+
+            if (!list.isEmpty() && Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty()) {
+                Panda.this.getNavigation().moveTo((Entity) list.get(0), 1.2000000476837158D);
+            } else if (!Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty()) {
+                Panda.this.tryToSit();
+            }
+
+            this.cooldown = 0;
+        }
+
+        @Override
+        public void stop() {
+            ItemStack itemstack = Panda.this.getItemBySlot(EquipmentSlot.MAINHAND);
+
+            if (!itemstack.isEmpty()) {
+                Panda.this.forceDrops = true; // Paper
+                Panda.this.spawnAtLocation(itemstack);
+                Panda.this.forceDrops = false; // Paper
+                Panda.this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
+                int i = Panda.this.isLazy() ? Panda.this.random.nextInt(50) + 10 : Panda.this.random.nextInt(150) + 10;
+
+                this.cooldown = Panda.this.tickCount + i * 20;
             }
 
+            Panda.this.sit(false);
         }
     }
 
-    static class PandaLieOnBackGoal extends Goal {
+    private static class PandaLieOnBackGoal extends Goal {
+
         private final Panda panda;
         private int cooldown;
 
@@ -881,11 +974,7 @@
 
         @Override
         public boolean canContinueToUse() {
-            if (!this.panda.isInWater() && (this.panda.isLazy() || this.panda.random.nextInt(reducedTickDelay(600)) != 1)) {
-                return this.panda.random.nextInt(reducedTickDelay(2000)) != 1;
-            } else {
-                return false;
-            }
+            return !this.panda.isInWater() && (this.panda.isLazy() || this.panda.random.nextInt(reducedTickDelay(600)) != 1) ? this.panda.random.nextInt(reducedTickDelay(2000)) != 1 : false;
         }
 
         @Override
@@ -901,7 +990,32 @@
         }
     }
 
-    static class PandaLookAtPlayerGoal extends LookAtPlayerGoal {
+    private static class PandaSneezeGoal extends Goal {
+
+        private final Panda panda;
+
+        public PandaSneezeGoal(Panda panda) {
+            this.panda = panda;
+        }
+
+        @Override
+        public boolean canUse() {
+            return this.panda.isBaby() && this.panda.canPerformAction() ? (this.panda.isWeak() && this.panda.random.nextInt(reducedTickDelay(500)) == 1 ? true : this.panda.random.nextInt(reducedTickDelay(6000)) == 1) : false;
+        }
+
+        @Override
+        public boolean canContinueToUse() {
+            return false;
+        }
+
+        @Override
+        public void start() {
+            this.panda.sneeze(true);
+        }
+    }
+
+    private static class PandaLookAtPlayerGoal extends LookAtPlayerGoal {
+
         private final Panda panda;
 
         public PandaLookAtPlayerGoal(Panda panda, Class<? extends LivingEntity> targetType, float range) {
@@ -927,7 +1041,7 @@
                     if (this.lookAtType == Player.class) {
                         this.lookAt = this.mob.level().getNearestPlayer(this.lookAtContext, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ());
                     } else {
-                        this.lookAt = this.mob.level().getNearestEntity(this.mob.level().getEntitiesOfClass(this.lookAtType, this.mob.getBoundingBox().inflate((double)this.lookDistance, 3.0D, (double)this.lookDistance), (livingEntity) -> {
+                        this.lookAt = this.mob.level().getNearestEntity(this.mob.level().getEntitiesOfClass(this.lookAtType, this.mob.getBoundingBox().inflate((double) this.lookDistance, 3.0D, (double) this.lookDistance), (entityliving) -> {
                             return true;
                         }), this.lookAtContext, this.mob, this.mob.getX(), this.mob.getEyeY(), this.mob.getZ());
                     }
@@ -946,47 +1060,8 @@
         }
     }
 
-    static class PandaMoveControl extends MoveControl {
-        private final Panda panda;
-
-        public PandaMoveControl(Panda panda) {
-            super(panda);
-            this.panda = panda;
-        }
-
-        @Override
-        public void tick() {
-            if (this.panda.canPerformAction()) {
-                super.tick();
-            }
-        }
-    }
-
-    static class PandaPanicGoal extends PanicGoal {
-        private final Panda panda;
-
-        public PandaPanicGoal(Panda panda, double speed) {
-            super(panda, speed);
-            this.panda = panda;
-        }
-
-        @Override
-        protected boolean shouldPanic() {
-            return this.mob.isFreezing() || this.mob.isOnFire();
-        }
-
-        @Override
-        public boolean canContinueToUse() {
-            if (this.panda.isSitting()) {
-                this.panda.getNavigation().stop();
-                return false;
-            } else {
-                return super.canContinueToUse();
-            }
-        }
-    }
+    private static class PandaRollGoal extends Goal {
 
-    static class PandaRollGoal extends Goal {
         private final Panda panda;
 
         public PandaRollGoal(Panda panda) {
@@ -1000,18 +1075,13 @@
                 if (!this.panda.canPerformAction()) {
                     return false;
                 } else {
-                    float f = this.panda.getYRot() * ((float)Math.PI / 180F);
-                    float g = -Mth.sin(f);
-                    float h = Mth.cos(f);
-                    int i = (double)Math.abs(g) > 0.5D ? Mth.sign((double)g) : 0;
-                    int j = (double)Math.abs(h) > 0.5D ? Mth.sign((double)h) : 0;
-                    if (this.panda.level().getBlockState(this.panda.blockPosition().offset(i, -1, j)).isAir()) {
-                        return true;
-                    } else if (this.panda.isPlayful() && this.panda.random.nextInt(reducedTickDelay(60)) == 1) {
-                        return true;
-                    } else {
-                        return this.panda.random.nextInt(reducedTickDelay(500)) == 1;
-                    }
+                    float f = this.panda.getYRot() * 0.017453292F;
+                    float f1 = -Mth.sin(f);
+                    float f2 = Mth.cos(f);
+                    int i = (double) Math.abs(f1) > 0.5D ? Mth.sign((double) f1) : 0;
+                    int j = (double) Math.abs(f2) > 0.5D ? Mth.sign((double) f2) : 0;
+
+                    return this.panda.level().getBlockState(this.panda.blockPosition().offset(i, -1, j)).isAir() ? true : (this.panda.isPlayful() && this.panda.random.nextInt(reducedTickDelay(60)) == 1 ? true : this.panda.random.nextInt(reducedTickDelay(500)) == 1);
                 }
             } else {
                 return false;
@@ -1034,94 +1104,31 @@
         }
     }
 
-    class PandaSitGoal extends Goal {
-        private int cooldown;
-
-        public PandaSitGoal() {
-            this.setFlags(EnumSet.of(Goal.Flag.MOVE));
-        }
-
-        @Override
-        public boolean canUse() {
-            if (this.cooldown <= Panda.this.tickCount && !Panda.this.isBaby() && !Panda.this.isInWater() && Panda.this.canPerformAction() && Panda.this.getUnhappyCounter() <= 0) {
-                List<ItemEntity> list = Panda.this.level().getEntitiesOfClass(ItemEntity.class, Panda.this.getBoundingBox().inflate(6.0D, 6.0D, 6.0D), Panda.PANDA_ITEMS);
-                return !list.isEmpty() || !Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty();
-            } else {
-                return false;
-            }
-        }
-
-        @Override
-        public boolean canContinueToUse() {
-            if (!Panda.this.isInWater() && (Panda.this.isLazy() || Panda.this.random.nextInt(reducedTickDelay(600)) != 1)) {
-                return Panda.this.random.nextInt(reducedTickDelay(2000)) != 1;
-            } else {
-                return false;
-            }
-        }
-
-        @Override
-        public void tick() {
-            if (!Panda.this.isSitting() && !Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty()) {
-                Panda.this.tryToSit();
-            }
-
-        }
-
-        @Override
-        public void start() {
-            List<ItemEntity> list = Panda.this.level().getEntitiesOfClass(ItemEntity.class, Panda.this.getBoundingBox().inflate(8.0D, 8.0D, 8.0D), Panda.PANDA_ITEMS);
-            if (!list.isEmpty() && Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty()) {
-                Panda.this.getNavigation().moveTo(list.get(0), (double)1.2F);
-            } else if (!Panda.this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty()) {
-                Panda.this.tryToSit();
-            }
-
-            this.cooldown = 0;
-        }
-
-        @Override
-        public void stop() {
-            ItemStack itemStack = Panda.this.getItemBySlot(EquipmentSlot.MAINHAND);
-            if (!itemStack.isEmpty()) {
-                Panda.this.spawnAtLocation(itemStack);
-                Panda.this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
-                int i = Panda.this.isLazy() ? Panda.this.random.nextInt(50) + 10 : Panda.this.random.nextInt(150) + 10;
-                this.cooldown = Panda.this.tickCount + i * 20;
-            }
-
-            Panda.this.sit(false);
-        }
-    }
+    private static class PandaHurtByTargetGoal extends HurtByTargetGoal {
 
-    static class PandaSneezeGoal extends Goal {
         private final Panda panda;
 
-        public PandaSneezeGoal(Panda panda) {
+        public PandaHurtByTargetGoal(Panda panda, Class<?>... noRevengeTypes) {
+            super(panda, noRevengeTypes);
             this.panda = panda;
         }
 
         @Override
-        public boolean canUse() {
-            if (this.panda.isBaby() && this.panda.canPerformAction()) {
-                if (this.panda.isWeak() && this.panda.random.nextInt(reducedTickDelay(500)) == 1) {
-                    return true;
-                } else {
-                    return this.panda.random.nextInt(reducedTickDelay(6000)) == 1;
-                }
+        public boolean canContinueToUse() {
+            if (!this.panda.gotBamboo && !this.panda.didBite) {
+                return super.canContinueToUse();
             } else {
+                this.panda.setTarget((LivingEntity) null);
                 return false;
             }
         }
 
         @Override
-        public boolean canContinueToUse() {
-            return false;
-        }
+        protected void alertOther(Mob mob, LivingEntity target) {
+            if (mob instanceof Panda && mob.isAggressive()) {
+                mob.setTarget(target, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY, true); // CraftBukkit
+            }
 
-        @Override
-        public void start() {
-            this.panda.sneeze(true);
         }
     }
 }
