--- 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;
@@ -17,6 +18,7 @@
 import net.minecraft.world.InteractionResult;
 import net.minecraft.world.damagesource.DamageSource;
 import net.minecraft.world.entity.AgeableMob;
+import net.minecraft.world.entity.Entity;
 import net.minecraft.world.entity.EntityType;
 import net.minecraft.world.entity.EquipmentSlot;
 import net.minecraft.world.entity.ItemBasedSteering;
@@ -41,48 +43,69 @@
 import net.minecraft.world.entity.vehicle.DismountHelper;
 import net.minecraft.world.item.ItemStack;
 import net.minecraft.world.item.Items;
+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.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRemoveEvent;
+// 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);
-    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
     protected void registerGoals() {
         this.goalSelector.addGoal(0, new FloatGoal(this));
-        this.goalSelector.addGoal(1, new PanicGoal(this, 1.25));
-        this.goalSelector.addGoal(3, new BreedGoal(this, 1.0));
-        this.goalSelector.addGoal(4, new TemptGoal(this, 1.2, stack -> stack.is(Items.CARROT_ON_A_STICK), false));
-        this.goalSelector.addGoal(4, new TemptGoal(this, 1.2, stack -> stack.is(ItemTags.PIG_FOOD), false));
-        this.goalSelector.addGoal(5, new FollowParentGoal(this, 1.1));
-        this.goalSelector.addGoal(6, new WaterAvoidingRandomStrollGoal(this, 1.0));
+        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, (itemstack) -> {
+            return itemstack.is(Items.CARROT_ON_A_STICK);
+        }, false));
+        this.goalSelector.addGoal(4, new TemptGoal(this, 1.2D, (itemstack) -> {
+            return itemstack.is(ItemTags.PIG_FOOD);
+        }, 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));
         this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
     }
 
     public static AttributeSupplier.Builder createAttributes() {
-        return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 10.0).add(Attributes.MOVEMENT_SPEED, 0.25);
+        return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 10.0D).add(Attributes.MOVEMENT_SPEED, 0.25D);
     }
 
     @Nullable
     @Override
     public LivingEntity getControllingPassenger() {
-        return (LivingEntity)(this.isSaddled() && this.getFirstPassenger() instanceof Player player && player.isHolding(Items.CARROT_ON_A_STICK)
-            ? player
-            : super.getControllingPassenger());
+        if (this.isSaddled()) {
+            Entity entity = this.getFirstPassenger();
+
+            if (entity instanceof Player) {
+                Player entityhuman = (Player) entity;
+
+                if (entityhuman.isHolding(Items.CARROT_ON_A_STICK)) {
+                    return entityhuman;
+                }
+            }
+        }
+
+        return super.getControllingPassenger();
     }
 
     @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();
         }
 
@@ -92,8 +115,8 @@
     @Override
     protected void defineSynchedData(SynchedEntityData.Builder builder) {
         super.defineSynchedData(builder);
-        builder.define(DATA_SADDLE_ID, false);
-        builder.define(DATA_BOOST_TIME, 0);
+        builder.define(Pig.DATA_SADDLE_ID, false);
+        builder.define(Pig.DATA_BOOST_TIME, 0);
     }
 
     @Override
@@ -130,20 +153,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;
             }
         }
     }
@@ -157,8 +183,9 @@
     protected void dropEquipment() {
         super.dropEquipment();
         if (this.isSaddled()) {
-            this.spawnAtLocation(Items.SADDLE);
+            this.spawnAtLocation((ItemLike) Items.SADDLE);
         }
+
     }
 
     @Override
@@ -170,31 +197,41 @@
     public void equipSaddle(@Nullable SoundSource sound) {
         this.steering.setSaddle(true);
         if (sound != null) {
-            this.level().playSound(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;
                         }
                     }
                 }
@@ -207,26 +244,34 @@
     @Override
     public void thunderHit(ServerLevel world, LightningBolt lightning) {
         if (world.getDifficulty() != Difficulty.PEACEFUL) {
-            ZombifiedPiglin zombifiedPiglin = EntityType.ZOMBIFIED_PIGLIN.create(world);
-            if (zombifiedPiglin != null) {
-                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);
+
+            if (entitypigzombie != null) {
+                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);
-                this.discard();
+                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(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause
             } else {
                 super.thunderHit(world, lightning);
             }
         } else {
             super.thunderHit(world, lightning);
         }
+
     }
 
     @Override
@@ -239,12 +284,12 @@
 
     @Override
     protected Vec3 getRiddenInput(Player controllingPlayer, Vec3 movementInput) {
-        return new Vec3(0.0, 0.0, 1.0);
+        return new Vec3(0.0D, 0.0D, 1.0D);
     }
 
     @Override
     protected float getRiddenSpeed(Player controllingPlayer) {
-        return (float)(this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 0.225 * (double)this.steering.boostFactor());
+        return (float) (this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 0.225D * (double) this.steering.boostFactor());
     }
 
     @Override
@@ -254,8 +299,8 @@
 
     @Nullable
     @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
@@ -265,6 +310,6 @@
 
     @Override
     public Vec3 getLeashOffset() {
-        return new Vec3(0.0, (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));
     }
 }
