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/server/EntityFox.java b/src/main/java/net/minecraft/server/EntityFox.java
index 56c119e8d11c5ffb1f90ac4249bce434b3e78884..8845afd83d47902d5192ec1a9146b6f20c5667d3 100644
--- a/src/main/java/net/minecraft/server/EntityFox.java
+++ b/src/main/java/net/minecraft/server/EntityFox.java
@@ -37,9 +37,9 @@ public class EntityFox extends EntityAnimal {
     private static final Predicate<Entity> bv = (entity) -> {
         return !entity.bx() && IEntitySelector.e.test(entity);
     };
-    private PathfinderGoal bw;
-    private PathfinderGoal bx;
-    private PathfinderGoal by;
+    private PathfinderGoal bw; private PathfinderGoal attackAnimalGoal() { return bw; } // Purpur - OBFHELPER
+    private PathfinderGoal bx; private PathfinderGoal attackTurtleGoal() { return bx; } // Purpur - OBFHELPER
+    private PathfinderGoal by; private PathfinderGoal attackFishGoal() { return by; } // Purpur - OBFHELPER
     private float bz;
     private float bA;
     private float bB;
@@ -227,6 +227,11 @@ public class EntityFox extends EntityAnimal {
     }
 
     private void initializePathFinderGoals() {
+        // Purpur start - do not add duplicate goals
+        this.targetSelector.a(attackAnimalGoal());
+        this.targetSelector.a(attackTurtleGoal());
+        this.targetSelector.a(attackFishGoal());
+        // Purpur end
         if (this.getFoxType() == EntityFox.Type.RED) {
             this.targetSelector.a(4, this.bw);
             this.targetSelector.a(4, this.bx);
@@ -259,6 +264,7 @@ public class EntityFox extends EntityAnimal {
 
     public void setFoxType(EntityFox.Type entityfox_type) {
         this.datawatcher.set(EntityFox.bo, entityfox_type.b());
+        initializePathFinderGoals(); // Purpur - fix API bug not updating pathfinders on type change
     }
 
     private List<UUID> fa() {
@@ -576,6 +582,27 @@ public class EntityFox extends EntityAnimal {
         return this.fa().contains(uuid);
     }
 
+    @Override
+    public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) {
+        if (world.purpurConfig.foxTypeChangesWithTulips) {
+            ItemStack itemstack = entityhuman.b(enumhand);
+            if (getFoxType() == Type.RED && itemstack.getItem() == Items.whiteTulip()) {
+                setFoxType(Type.SNOW);
+                if (!entityhuman.abilities.canInstantlyBuild) {
+                    itemstack.subtract(1);
+                }
+                return EnumInteractionResult.SUCCESS;
+            } else if (getFoxType() == Type.SNOW && itemstack.getItem() == Items.orangeTulip()) {
+                setFoxType(Type.RED);
+                if (!entityhuman.abilities.canInstantlyBuild) {
+                    itemstack.subtract(1);
+                }
+                return EnumInteractionResult.SUCCESS;
+            }
+        }
+        return super.b(entityhuman, enumhand);
+    }
+
     @Override
     protected org.bukkit.event.entity.EntityDeathEvent d(DamageSource damagesource) { // Paper
         ItemStack itemstack = this.getEquipment(EnumItemSlot.MAINHAND).cloneItemStack(); // Paper
diff --git a/src/main/java/net/minecraft/server/Items.java b/src/main/java/net/minecraft/server/Items.java
index 67ebcbe4daa1ef3cef6ca43ec92befbe4156842e..4c379916d8d7797038d2980761c49f44c010dea8 100644
--- a/src/main/java/net/minecraft/server/Items.java
+++ b/src/main/java/net/minecraft/server/Items.java
@@ -119,8 +119,8 @@ public class Items {
     public static final Item bk = a(Blocks.ALLIUM, CreativeModeTab.c);
     public static final Item bl = a(Blocks.AZURE_BLUET, CreativeModeTab.c);
     public static final Item bm = a(Blocks.RED_TULIP, CreativeModeTab.c);
-    public static final Item bn = a(Blocks.ORANGE_TULIP, CreativeModeTab.c);
-    public static final Item bo = a(Blocks.WHITE_TULIP, CreativeModeTab.c);
+    public static final Item bn = a(Blocks.ORANGE_TULIP, CreativeModeTab.c); public static Item orangeTulip() { return bn; } // Purpur - OBFHELPER
+    public static final Item bo = a(Blocks.WHITE_TULIP, CreativeModeTab.c); public static Item whiteTulip() { return bo; } // Purpur - OBFHELPER
     public static final Item bp = a(Blocks.PINK_TULIP, CreativeModeTab.c);
     public static final Item bq = a(Blocks.OXEYE_DAISY, CreativeModeTab.c);
     public static final Item br = a(Blocks.CORNFLOWER, CreativeModeTab.c);
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 3ec33a96396e49d1ddb9f7eea804e4ae8080efbd..459ff8ffe7c0bf09fe93d89b3433bc930bb52f06 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -118,6 +118,11 @@ public class PurpurWorldConfig {
         creeperChargedChance = getDouble("mobs.creeper.naturally-charged-chance", creeperChargedChance);
     }
 
+    public boolean foxTypeChangesWithTulips = false;
+    private void foxSettings() {
+        foxTypeChangesWithTulips = getBoolean("mobs.fox.tulips-change-type", foxTypeChangesWithTulips);
+    }
+
     public float giantStepHeight = 2.0F;
     public float giantJumpHeight = 1.0F;
     public double giantMovementSpeed = 0.5D;
