From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Thu, 3 Oct 2019 18:08:03 -0500
Subject: [PATCH] Allow leashing villagers


diff --git a/src/main/java/net/minecraft/world/entity/EntityInsentient.java b/src/main/java/net/minecraft/world/entity/EntityInsentient.java
index d8a627ed1fad1fca37d8f8a3a344b80a60fc5e2f..1a1561ab4276bd3654adc2cc2219f3bdb3924b88 100644
--- a/src/main/java/net/minecraft/world/entity/EntityInsentient.java
+++ b/src/main/java/net/minecraft/world/entity/EntityInsentient.java
@@ -49,6 +49,7 @@ import net.minecraft.world.entity.item.EntityItem;
 import net.minecraft.world.entity.monster.EntityBlaze;
 import net.minecraft.world.entity.monster.EntityEnderman;
 import net.minecraft.world.entity.monster.IMonster;
+import net.minecraft.world.entity.npc.EntityVillagerAbstract;
 import net.minecraft.world.entity.player.EntityHuman;
 import net.minecraft.world.entity.vehicle.EntityBoat;
 import net.minecraft.world.item.Item;
@@ -1217,6 +1218,7 @@ public abstract class EntityInsentient extends EntityLiving {
         if (!this.isAlive()) {
             return EnumInteractionResult.PASS;
         } else if (this.getLeashHolder() == entityhuman) {
+            if (enumhand == EnumHand.OFF_HAND && (world.purpurConfig.villagerCanBeLeashed || world.purpurConfig.villagerTraderCanBeLeashed) && this instanceof EntityVillagerAbstract) return EnumInteractionResult.CONSUME; // Purpur
             // CraftBukkit start - fire PlayerUnleashEntityEvent
             // Paper start - drop leash variable
             PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(this, entityhuman, !entityhuman.abilities.canInstantlyBuild);
diff --git a/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
index 2464f1a5a922a5557e2d00233033714533acad76..aeb3c82afeda3f1688b1b6617c6d05da2e7a3c76 100644
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
@@ -149,6 +149,11 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
     protected void initPathfinder() {
         if (world.purpurConfig.villagerFollowEmeraldBlock) this.goalSelector.a(3, new PathfinderGoalTempt(this, 1.0D, false, TEMPT_ITEMS));
     }
+
+    @Override
+    public boolean a(EntityHuman entityhuman) {
+        return world.purpurConfig.villagerCanBeLeashed && !this.isLeashed();
+    }
     // Purpur end
 
     @Override
diff --git a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
index 6c13a34a7ab220a3bba1c091f4f6a9e1340212f6..e0324cdb2d4c85714eaad490a7a5c826b38e6b16 100644
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
@@ -93,6 +93,13 @@ public class EntityVillagerTrader extends EntityVillagerAbstract {
         this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityInsentient.class, 8.0F));
     }
 
+    // Purpur - start
+    @Override
+    public boolean a(EntityHuman entityhuman) {
+        return world.purpurConfig.villagerTraderCanBeLeashed && !this.isLeashed();
+    }
+    // Purpur - end
+
     @Nullable
     @Override
     public EntityAgeable createChild(WorldServer worldserver, EntityAgeable entityageable) {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 7d66e253391522d754146275024ffb017a685e6f..b6d6685f135ee66a25f29c0f00a63bbe78d0c3a5 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -285,17 +285,21 @@ public class PurpurWorldConfig {
 
     public int villagerBrainTicks = 1;
     public boolean villagerUseBrainTicksOnlyWhenLagging = true;
+    public boolean villagerCanBeLeashed = false;
     public boolean villagerFarmingBypassMobGriefing = false;
     public boolean villagerFollowEmeraldBlock = false;
     private void villagerSettings() {
         villagerBrainTicks = getInt("mobs.villager.brain-ticks", villagerBrainTicks);
         villagerUseBrainTicksOnlyWhenLagging = getBoolean("mobs.villager.use-brain-ticks-only-when-lagging", villagerUseBrainTicksOnlyWhenLagging);
+        villagerCanBeLeashed = getBoolean("mobs.villager.can-be-leashed", villagerCanBeLeashed);
         villagerFarmingBypassMobGriefing = getBoolean("mobs.villager.bypass-mob-griefing", villagerFarmingBypassMobGriefing);
         villagerFollowEmeraldBlock = getBoolean("mobs.villager.follow-emerald-blocks", villagerFollowEmeraldBlock);
     }
 
+    public boolean villagerTraderCanBeLeashed = false;
     public boolean villagerTraderFollowEmeraldBlock = false;
     private void villagerTraderSettings() {
+        villagerTraderCanBeLeashed = getBoolean("mobs.wandering_trader.can-be-leashed", villagerTraderCanBeLeashed);
         villagerTraderFollowEmeraldBlock = getBoolean("mobs.wandering_trader.follow-emerald-blocks", villagerTraderFollowEmeraldBlock);
     }
 
