From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sat, 13 Jul 2019 15:56:22 -0500
Subject: [PATCH] Tulips change fox type


diff --git a/src/main/java/net/minecraft/world/entity/animal/Fox.java b/src/main/java/net/minecraft/world/entity/animal/Fox.java
index 80749df5d00df415a1b9e7c0e8586625b6453ffb..406b6ed8084c18da1062d8e8049bdfff65101565 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Fox.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Fox.java
@@ -34,6 +34,7 @@ import net.minecraft.tags.Tag;
 import net.minecraft.util.Mth;
 import net.minecraft.world.DifficultyInstance;
 import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
 import net.minecraft.world.damagesource.DamageSource;
 import net.minecraft.world.entity.AgeableMob;
 import net.minecraft.world.entity.Entity;
@@ -85,6 +86,7 @@ import net.minecraft.world.level.block.Blocks;
 import net.minecraft.world.level.block.CaveVines;
 import net.minecraft.world.level.block.SweetBerryBushBlock;
 import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.gameevent.GameEvent;
 import net.minecraft.world.level.pathfinder.BlockPathTypes;
 import net.minecraft.world.phys.Vec3;
 
@@ -368,6 +370,11 @@ public class Fox extends Animal {
     }
 
     private void setTargetGoals() {
+        // Purpur start - do not add duplicate goals
+        this.targetSelector.removeGoal(this.landTargetGoal);
+        this.targetSelector.removeGoal(this.turtleEggTargetGoal);
+        this.targetSelector.removeGoal(this.fishTargetGoal);
+        // Purpur end
         if (this.getFoxType() == Fox.Type.RED) {
             this.targetSelector.addGoal(4, this.landTargetGoal);
             this.targetSelector.addGoal(4, this.turtleEggTargetGoal);
@@ -400,6 +407,7 @@ public class Fox extends Animal {
 
     public void setFoxType(Fox.Type type) {
         this.entityData.set(Fox.DATA_TYPE_ID, type.getId());
+        this.setTargetGoals(); // Purpur - fix API bug not updating pathfinders on type change
     }
 
     List<UUID> getTrustedUUIDs() {
@@ -730,6 +738,29 @@ public class Fox extends Animal {
         return this.getTrustedUUIDs().contains(uuid);
     }
 
+    // Purpur start
+    @Override
+    public InteractionResult mobInteract(Player player, InteractionHand hand) {
+        if (level.purpurConfig.foxTypeChangesWithTulips) {
+            ItemStack itemstack = player.getItemInHand(hand);
+            if (getFoxType() == Type.RED && itemstack.getItem() == Items.WHITE_TULIP) {
+                setFoxType(Type.SNOW);
+                if (!player.getAbilities().instabuild) {
+                    itemstack.shrink(1);
+                }
+                return InteractionResult.SUCCESS;
+            } else if (getFoxType() == Type.SNOW && itemstack.getItem() == Items.ORANGE_TULIP) {
+                setFoxType(Type.RED);
+                if (!player.getAbilities().instabuild) {
+                    itemstack.shrink(1);
+                }
+                return InteractionResult.SUCCESS;
+            }
+        }
+        return super.mobInteract(player, hand);
+    }
+    // Purpur end
+
     @Override
     // Paper start - Cancellable death event
     protected org.bukkit.event.entity.EntityDeathEvent dropAllDeathLoot(DamageSource source) {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 60319614be9696d80bbbc147e529ad662dec0460..523ce8f7fff9a98b6646d1035849faeb23ead5ae 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -430,6 +430,7 @@ public class PurpurWorldConfig {
     public boolean foxRidable = false;
     public boolean foxRidableInWater = false;
     public double foxMaxHealth = 10.0D;
+    public boolean foxTypeChangesWithTulips = false;
     private void foxSettings() {
         foxRidable = getBoolean("mobs.fox.ridable", foxRidable);
         foxRidableInWater = getBoolean("mobs.fox.ridable-in-water", foxRidableInWater);
@@ -439,6 +440,7 @@ public class PurpurWorldConfig {
             set("mobs.fox.attributes.max_health", oldValue);
         }
         foxMaxHealth = getDouble("mobs.fox.attributes.max_health", foxMaxHealth);
+        foxTypeChangesWithTulips = getBoolean("mobs.fox.tulips-change-type", foxTypeChangesWithTulips);
     }
 
     public boolean ghastRidable = false;
