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/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 4af25f8d4d48a8d886c9ec823b65fdd0dd199066..b0ac198041a319d33fa65398c1564dfa57aaf8e1 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1221,6 +1221,7 @@ public abstract class Mob extends LivingEntity {
         if (!this.isAlive()) {
             return InteractionResult.PASS;
         } else if (this.getLeashHolder() == player) {
+            if (hand == InteractionHand.OFF_HAND && (level.purpurConfig.villagerCanBeLeashed || level.purpurConfig.wanderingTraderCanBeLeashed) && this instanceof net.minecraft.world.entity.npc.AbstractVillager) return InteractionResult.CONSUME; // Purpur
             // CraftBukkit start - fire PlayerUnleashEntityEvent
             // Paper start - drop leash variable
             org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(this, player, !player.getAbilities().instabuild);
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
index d5605663b40b613bf688dc8f7506f6c83b1c9085..949fa7099198fdd00a0626ff53f75f3f2cada7f4 100644
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
@@ -180,6 +180,11 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
     public void initAttributes() {
         this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(this.level.purpurConfig.villagerMaxHealth);
     }
+
+    @Override
+    public boolean canBeLeashed(Player player) {
+        return level.purpurConfig.villagerCanBeLeashed && !this.isLeashed();
+    }
     // Purpur end
 
     @Override
diff --git a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
index 393061e13375bf7a7ee57973b4abac83ffa15fa3..c48935d35a6141c41db22e3ec172d5994fd317a2 100644
--- a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
+++ b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
@@ -82,6 +82,11 @@ public class WanderingTrader extends net.minecraft.world.entity.npc.AbstractVill
     public void initAttributes() {
         this.getAttribute(net.minecraft.world.entity.ai.attributes.Attributes.MAX_HEALTH).setBaseValue(this.level.purpurConfig.wanderingTraderMaxHealth);
     }
+
+    @Override
+    public boolean canBeLeashed(Player player) {
+        return level.purpurConfig.wanderingTraderCanBeLeashed && !this.isLeashed();
+    }
     // Purpur end
 
     @Override
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index a70ea41a56edf5a52c96feb0bdebccaee0b89f04..af80a7d516fa5669fe7406ab3b07b39ee643928f 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -1241,6 +1241,7 @@ public class PurpurWorldConfig {
     public int villagerBrainTicks = 1;
     public boolean villagerUseBrainTicksOnlyWhenLagging = true;
     public boolean villagerFollowEmeraldBlock = false;
+    public boolean villagerCanBeLeashed = false;
     private void villagerSettings() {
         villagerRidable = getBoolean("mobs.villager.ridable", villagerRidable);
         villagerRidableInWater = getBoolean("mobs.villager.ridable-in-water", villagerRidableInWater);
@@ -1253,6 +1254,7 @@ public class PurpurWorldConfig {
         villagerBrainTicks = getInt("mobs.villager.brain-ticks", villagerBrainTicks);
         villagerUseBrainTicksOnlyWhenLagging = getBoolean("mobs.villager.use-brain-ticks-only-when-lagging", villagerUseBrainTicksOnlyWhenLagging);
         villagerFollowEmeraldBlock = getBoolean("mobs.villager.follow-emerald-blocks", villagerFollowEmeraldBlock);
+        villagerCanBeLeashed = getBoolean("mobs.villager.can-be-leashed", villagerCanBeLeashed);
     }
 
     public boolean vindicatorRidable = false;
@@ -1273,6 +1275,7 @@ public class PurpurWorldConfig {
     public boolean wanderingTraderRidableInWater = false;
     public double wanderingTraderMaxHealth = 20.0D;
     public boolean wanderingTraderFollowEmeraldBlock = false;
+    public boolean wanderingTraderCanBeLeashed = false;
     private void wanderingTraderSettings() {
         wanderingTraderRidable = getBoolean("mobs.wandering_trader.ridable", wanderingTraderRidable);
         wanderingTraderRidableInWater = getBoolean("mobs.wandering_trader.ridable-in-water", wanderingTraderRidableInWater);
@@ -1283,6 +1286,7 @@ public class PurpurWorldConfig {
         }
         wanderingTraderMaxHealth = getDouble("mobs.wandering_trader.attributes.max_health", wanderingTraderMaxHealth);
         wanderingTraderFollowEmeraldBlock = getBoolean("mobs.wandering_trader.follow-emerald-blocks", wanderingTraderFollowEmeraldBlock);
+        wanderingTraderCanBeLeashed = getBoolean("mobs.wandering_trader.can-be-leashed", wanderingTraderCanBeLeashed);
     }
 
     public boolean witchRidable = false;
