From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Encode42 <me@encode42.dev>
Date: Tue, 9 Feb 2021 21:23:37 -0500
Subject: [PATCH] Config to always tame in Creative

Adds a configuration option that ensures a player in Creative always tames a tameable entity.
This essentially allows Creative mode players to tame animals on their first try.

diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
index d285f5aa66fa81a2f56920c05afb4506cb82fa54..39e348847bcecd91013452e71ef1672994a1bfa7 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java
@@ -63,7 +63,7 @@ public class PathfinderGoalTame extends PathfinderGoal {
                 int j = this.entity.getMaxDomestication();
 
                 // CraftBukkit - fire EntityTameEvent
-                if (j > 0 && this.entity.getRandom().nextInt(j) < i && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this.entity, ((org.bukkit.craftbukkit.entity.CraftHumanEntity) this.entity.getBukkitEntity().getPassenger()).getHandle()).isCancelled()) {
+                if ((this.entity.world.purpurConfig.alwaysTameInCreative && ((EntityHuman) entity).abilities.canInstantlyBuild) || (j > 0 && this.entity.getRandom().nextInt(j) < i && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this.entity, ((org.bukkit.craftbukkit.entity.CraftHumanEntity) this.entity.getBukkitEntity().getPassenger()).getHandle()).isCancelled())) { // Purpur
                     this.entity.i((EntityHuman) entity);
                     return;
                 }
diff --git a/src/main/java/net/minecraft/world/entity/animal/EntityCat.java b/src/main/java/net/minecraft/world/entity/animal/EntityCat.java
index 7143b0801be7877762e41da336ea5e4e57f2e463..a099d8e0c5a3e4b804c8af978161ec1747ee7fa3 100644
--- a/src/main/java/net/minecraft/world/entity/animal/EntityCat.java
+++ b/src/main/java/net/minecraft/world/entity/animal/EntityCat.java
@@ -439,7 +439,7 @@ public class EntityCat extends EntityTameableAnimal {
                 }
             } else if (this.k(itemstack)) {
                 this.a(entityhuman, itemstack);
-                if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { // CraftBukkit
+                if ((this.world.purpurConfig.alwaysTameInCreative && entityhuman.abilities.canInstantlyBuild) || (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled())) { // CraftBukkit // Purpur
                     this.tame(entityhuman);
                     this.setWillSit(true);
                     this.world.broadcastEntityEffect(this, (byte) 7);
diff --git a/src/main/java/net/minecraft/world/entity/animal/EntityParrot.java b/src/main/java/net/minecraft/world/entity/animal/EntityParrot.java
index efa4318989893c946e9d7671d0dead6c4a6e315f..b2a8bfc3e53a2071ab7451fbdb3d49d97f0c430a 100644
--- a/src/main/java/net/minecraft/world/entity/animal/EntityParrot.java
+++ b/src/main/java/net/minecraft/world/entity/animal/EntityParrot.java
@@ -301,7 +301,7 @@ public class EntityParrot extends EntityPerchable implements EntityBird {
             }
 
             if (!this.world.isClientSide) {
-                if (this.random.nextInt(10) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { // CraftBukkit
+                if ((this.world.purpurConfig.alwaysTameInCreative && entityhuman.abilities.canInstantlyBuild) || (this.random.nextInt(10) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled())) { // CraftBukkit // Purpur
                     this.tame(entityhuman);
                     this.world.broadcastEntityEffect(this, (byte) 7);
                 } else {
diff --git a/src/main/java/net/minecraft/world/entity/animal/EntityWolf.java b/src/main/java/net/minecraft/world/entity/animal/EntityWolf.java
index 090903fbc8f6cd1522c7afb358f708f5ae3395f4..884a3f03c73efb8fb0863976615fba5ec10f716c 100644
--- a/src/main/java/net/minecraft/world/entity/animal/EntityWolf.java
+++ b/src/main/java/net/minecraft/world/entity/animal/EntityWolf.java
@@ -482,7 +482,7 @@ public class EntityWolf extends EntityTameableAnimal implements IEntityAngerable
                 }
 
                 // CraftBukkit - added event call and isCancelled check.
-                if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) {
+                if ((this.world.purpurConfig.alwaysTameInCreative && entityhuman.abilities.canInstantlyBuild) || (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled())) { // Purpur
                     this.tame(entityhuman);
                     this.navigation.o();
                     this.setGoalTarget((EntityLiving) null);
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 6036f39cd3aaeee459cbb45d9e3bd7450b6f08b0..71566df66d763c2e05442a75a940cc50011fee7a 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -255,6 +255,7 @@ public class PurpurWorldConfig {
     }
 
     public boolean useBetterMending = false;
+    public boolean alwaysTameInCreative = false;
     public boolean boatEjectPlayersOnLand = false;
     public boolean boatsDoFallDamage = true;
     public boolean disableDropsOnCrammingDeath = false;
@@ -271,6 +272,7 @@ public class PurpurWorldConfig {
     public int animalBreedingCooldownSeconds = 0;
     private void miscGameplayMechanicsSettings() {
         useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
+        alwaysTameInCreative = getBoolean("gameplay-mechanics.always-tame-in-creative", alwaysTameInCreative);
         boatEjectPlayersOnLand = getBoolean("gameplay-mechanics.boat.eject-players-on-land", boatEjectPlayersOnLand);
         boatsDoFallDamage = getBoolean("gameplay-mechanics.boat.do-fall-damage", boatsDoFallDamage);
         disableDropsOnCrammingDeath = getBoolean("gameplay-mechanics.disable-drops-on-cramming-death", disableDropsOnCrammingDeath);
