--- a/net/minecraft/world/entity/animal/Pig.java
+++ b/net/minecraft/world/entity/animal/Pig.java
@@ -1,5 +1,6 @@
 package net.minecraft.world.entity.animal;
 
+import com.google.common.collect.UnmodifiableIterator;
 import javax.annotation.Nullable;
 import net.minecraft.core.BlockPos;
 import net.minecraft.core.Direction;
@@ -42,19 +43,25 @@
 import net.minecraft.world.item.ItemStack;
 import net.minecraft.world.item.Items;
 import net.minecraft.world.item.crafting.Ingredient;
+import net.minecraft.world.level.ItemLike;
 import net.minecraft.world.level.Level;
 import net.minecraft.world.level.block.state.BlockState;
 import net.minecraft.world.phys.AABB;
 import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory;
+// CraftBukkit end
 
 public class Pig extends Animal implements ItemSteerable, Saddleable {
+
     private static final EntityDataAccessor<Boolean> DATA_SADDLE_ID = SynchedEntityData.defineId(Pig.class, EntityDataSerializers.BOOLEAN);
     private static final EntityDataAccessor<Integer> DATA_BOOST_TIME = SynchedEntityData.defineId(Pig.class, EntityDataSerializers.INT);
     private static final Ingredient FOOD_ITEMS = Ingredient.of(Items.CARROT, Items.POTATO, Items.BEETROOT);
-    public final ItemBasedSteering steering = new ItemBasedSteering(this.entityData, DATA_BOOST_TIME, DATA_SADDLE_ID);
+    public final ItemBasedSteering steering;
 
     public Pig(EntityType<? extends Pig> type, Level world) {
         super(type, world);
+        this.steering = new ItemBasedSteering(this.entityData, Pig.DATA_BOOST_TIME, Pig.DATA_SADDLE_ID);
     }
 
     @Override
@@ -63,7 +70,7 @@
         this.goalSelector.addGoal(1, new PanicGoal(this, 1.25D));
         this.goalSelector.addGoal(3, new BreedGoal(this, 1.0D));
         this.goalSelector.addGoal(4, new TemptGoal(this, 1.2D, Ingredient.of(Items.CARROT_ON_A_STICK), false));
-        this.goalSelector.addGoal(4, new TemptGoal(this, 1.2D, FOOD_ITEMS, false));
+        this.goalSelector.addGoal(4, new TemptGoal(this, 1.2D, Pig.FOOD_ITEMS, false));
         this.goalSelector.addGoal(5, new FollowParentGoal(this, 1.1D));
         this.goalSelector.addGoal(6, new WaterAvoidingRandomStrollGoal(this, 1.0D));
         this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 6.0F));
@@ -78,12 +85,15 @@
     @Override
     public Entity getControllingPassenger() {
         Entity entity = this.getFirstPassenger();
+
         return entity != null && this.canBeControlledBy(entity) ? entity : null;
     }
 
     private boolean canBeControlledBy(Entity entity) {
-        if (this.isSaddled() && entity instanceof Player player) {
-            return player.getMainHandItem().is(Items.CARROT_ON_A_STICK) || player.getOffhandItem().is(Items.CARROT_ON_A_STICK);
+        if (this.isSaddled() && entity instanceof Player) {
+            Player entityhuman = (Player) entity;
+
+            return entityhuman.getMainHandItem().is(Items.CARROT_ON_A_STICK) || entityhuman.getOffhandItem().is(Items.CARROT_ON_A_STICK);
         } else {
             return false;
         }
@@ -91,7 +101,7 @@
 
     @Override
     public void onSyncedDataUpdated(EntityDataAccessor<?> data) {
-        if (DATA_BOOST_TIME.equals(data) && this.level.isClientSide) {
+        if (Pig.DATA_BOOST_TIME.equals(data) && this.level.isClientSide) {
             this.steering.onSynced();
         }
 
@@ -101,8 +111,8 @@
     @Override
     protected void defineSynchedData() {
         super.defineSynchedData();
-        this.entityData.define(DATA_SADDLE_ID, false);
-        this.entityData.define(DATA_BOOST_TIME, 0);
+        this.entityData.define(Pig.DATA_SADDLE_ID, false);
+        this.entityData.define(Pig.DATA_BOOST_TIME, 0);
     }
 
     @Override
@@ -139,20 +149,23 @@
 
     @Override
     public InteractionResult mobInteract(Player player, InteractionHand hand) {
-        boolean bl = this.isFood(player.getItemInHand(hand));
-        if (!bl && this.isSaddled() && !this.isVehicle() && !player.isSecondaryUseActive()) {
+        boolean flag = this.isFood(player.getItemInHand(hand));
+
+        if (!flag && this.isSaddled() && !this.isVehicle() && !player.isSecondaryUseActive()) {
             if (!this.level.isClientSide) {
                 player.startRiding(this);
             }
 
             return InteractionResult.sidedSuccess(this.level.isClientSide);
         } else {
-            InteractionResult interactionResult = super.mobInteract(player, hand);
-            if (!interactionResult.consumesAction()) {
-                ItemStack itemStack = player.getItemInHand(hand);
-                return itemStack.is(Items.SADDLE) ? itemStack.interactLivingEntity(player, this, hand) : InteractionResult.PASS;
+            InteractionResult enuminteractionresult = super.mobInteract(player, hand);
+
+            if (!enuminteractionresult.consumesAction()) {
+                ItemStack itemstack = player.getItemInHand(hand);
+
+                return itemstack.is(Items.SADDLE) ? itemstack.interactLivingEntity(player, this, hand) : InteractionResult.PASS;
             } else {
-                return interactionResult;
+                return enuminteractionresult;
             }
         }
     }
@@ -166,7 +179,7 @@
     protected void dropEquipment() {
         super.dropEquipment();
         if (this.isSaddled()) {
-            this.spawnAtLocation(Items.SADDLE);
+            this.spawnAtLocation((ItemLike) Items.SADDLE);
         }
 
     }
@@ -180,32 +193,41 @@
     public void equipSaddle(@Nullable SoundSource sound) {
         this.steering.setSaddle(true);
         if (sound != null) {
-            this.level.playSound((Player)null, this, SoundEvents.PIG_SADDLE, sound, 0.5F, 1.0F);
+            this.level.playSound((Player) null, (Entity) this, SoundEvents.PIG_SADDLE, sound, 0.5F, 1.0F);
         }
 
     }
 
     @Override
     public Vec3 getDismountLocationForPassenger(LivingEntity passenger) {
-        Direction direction = this.getMotionDirection();
-        if (direction.getAxis() == Direction.Axis.Y) {
+        Direction enumdirection = this.getMotionDirection();
+
+        if (enumdirection.getAxis() == Direction.Axis.Y) {
             return super.getDismountLocationForPassenger(passenger);
         } else {
-            int[][] is = DismountHelper.offsetsForDirection(direction);
-            BlockPos blockPos = this.blockPosition();
-            BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
+            int[][] aint = DismountHelper.offsetsForDirection(enumdirection);
+            BlockPos blockposition = this.blockPosition();
+            BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
+            UnmodifiableIterator unmodifiableiterator = passenger.getDismountPoses().iterator();
 
-            for(Pose pose : passenger.getDismountPoses()) {
-                AABB aABB = passenger.getLocalBoundsForPose(pose);
+            while (unmodifiableiterator.hasNext()) {
+                Pose entitypose = (Pose) unmodifiableiterator.next();
+                AABB axisalignedbb = passenger.getLocalBoundsForPose(entitypose);
+                int[][] aint1 = aint;
+                int i = aint.length;
 
-                for(int[] js : is) {
-                    mutableBlockPos.set(blockPos.getX() + js[0], blockPos.getY(), blockPos.getZ() + js[1]);
-                    double d = this.level.getBlockFloorHeight(mutableBlockPos);
-                    if (DismountHelper.isBlockFloorValid(d)) {
-                        Vec3 vec3 = Vec3.upFromBottomCenterOf(mutableBlockPos, d);
-                        if (DismountHelper.canDismountTo(this.level, passenger, aABB.move(vec3))) {
-                            passenger.setPose(pose);
-                            return vec3;
+                for (int j = 0; j < i; ++j) {
+                    int[] aint2 = aint1[j];
+
+                    blockposition_mutableblockposition.set(blockposition.getX() + aint2[0], blockposition.getY(), blockposition.getZ() + aint2[1]);
+                    double d0 = this.level.getBlockFloorHeight(blockposition_mutableblockposition);
+
+                    if (DismountHelper.isBlockFloorValid(d0)) {
+                        Vec3 vec3d = Vec3.upFromBottomCenterOf(blockposition_mutableblockposition, d0);
+
+                        if (DismountHelper.canDismountTo(this.level, passenger, axisalignedbb.move(vec3d))) {
+                            passenger.setPose(entitypose);
+                            return vec3d;
                         }
                     }
                 }
@@ -218,18 +240,25 @@
     @Override
     public void thunderHit(ServerLevel world, LightningBolt lightning) {
         if (world.getDifficulty() != Difficulty.PEACEFUL) {
-            ZombifiedPiglin zombifiedPiglin = EntityType.ZOMBIFIED_PIGLIN.create(world);
-            zombifiedPiglin.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.GOLDEN_SWORD));
-            zombifiedPiglin.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
-            zombifiedPiglin.setNoAi(this.isNoAi());
-            zombifiedPiglin.setBaby(this.isBaby());
+            ZombifiedPiglin entitypigzombie = (ZombifiedPiglin) EntityType.ZOMBIFIED_PIGLIN.create(world);
+
+            entitypigzombie.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.GOLDEN_SWORD));
+            entitypigzombie.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
+            entitypigzombie.setNoAi(this.isNoAi());
+            entitypigzombie.setBaby(this.isBaby());
             if (this.hasCustomName()) {
-                zombifiedPiglin.setCustomName(this.getCustomName());
-                zombifiedPiglin.setCustomNameVisible(this.isCustomNameVisible());
+                entitypigzombie.setCustomName(this.getCustomName());
+                entitypigzombie.setCustomNameVisible(this.isCustomNameVisible());
             }
 
-            zombifiedPiglin.setPersistenceRequired();
-            world.addFreshEntity(zombifiedPiglin);
+            entitypigzombie.setPersistenceRequired();
+            // CraftBukkit start
+            if (CraftEventFactory.callPigZapEvent(this, lightning, entitypigzombie).isCancelled()) {
+                return;
+            }
+            // CraftBukkit - added a reason for spawning this creature
+            world.addFreshEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING);
+            // CraftBukkit end
             this.discard();
         } else {
             super.thunderHit(world, lightning);
@@ -244,7 +273,7 @@
 
     @Override
     public float getSteeringSpeed() {
-        return (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 0.225F;
+        return (float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 0.225F;
     }
 
     @Override
@@ -258,17 +287,17 @@
     }
 
     @Override
-    public Pig getBreedOffspring(ServerLevel serverLevel, AgeableMob ageableMob) {
-        return EntityType.PIG.create(serverLevel);
+    public Pig getBreedOffspring(ServerLevel world, AgeableMob entity) {
+        return (Pig) EntityType.PIG.create(world);
     }
 
     @Override
     public boolean isFood(ItemStack stack) {
-        return FOOD_ITEMS.test(stack);
+        return Pig.FOOD_ITEMS.test(stack);
     }
 
     @Override
     public Vec3 getLeashOffset() {
-        return new Vec3(0.0D, (double)(0.6F * this.getEyeHeight()), (double)(this.getBbWidth() * 0.4F));
+        return new Vec3(0.0D, (double) (0.6F * this.getEyeHeight()), (double) (this.getBbWidth() * 0.4F));
     }
 }
