From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Fri, 29 Nov 2019 22:10:12 -0600
Subject: [PATCH] Villagers follow emerald blocks


diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
index 1c87bc91515490e2f8579a5321058845c7d30a56..3ae6e9fceb8feea8340fc542727423379a3f8863 100644
--- a/src/main/java/net/minecraft/server/EntityVillager.java
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
@@ -72,6 +72,13 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
         this.brainTickOffset = getRandom().nextInt(100); // Purpur
     }
 
+    // Purpur start
+    @Override
+    protected void initPathfinder() {
+        if (world.purpurConfig.villagerFollowEmeraldBlock) this.goalSelector.a(3, new PathfinderGoalTempt(this, 1.0D, false, TEMPT_ITEMS));
+    }
+    // Purpur end
+
     @Override
     public BehaviorController<EntityVillager> getBehaviorController() {
         return (BehaviorController<EntityVillager>) super.getBehaviorController(); // CraftBukkit - decompile error
diff --git a/src/main/java/net/minecraft/server/EntityVillagerAbstract.java b/src/main/java/net/minecraft/server/EntityVillagerAbstract.java
index e0cc45a7494cd6f06169b64ee8ffc16aa1932f8f..baf74566ec8569677e6f03aef96645c13ec94d89 100644
--- a/src/main/java/net/minecraft/server/EntityVillagerAbstract.java
+++ b/src/main/java/net/minecraft/server/EntityVillagerAbstract.java
@@ -18,6 +18,8 @@ import io.papermc.paper.event.player.PlayerTradeEvent;
 
 public abstract class EntityVillagerAbstract extends EntityAgeable implements NPC, IMerchant {
 
+    static final RecipeItemStack TEMPT_ITEMS = RecipeItemStack.a(Blocks.EMERALD_BLOCK.getItem()); // Purpur
+
     // CraftBukkit start
     private CraftMerchant craftMerchant;
 
diff --git a/src/main/java/net/minecraft/server/EntityVillagerTrader.java b/src/main/java/net/minecraft/server/EntityVillagerTrader.java
index 250a4e5ddd626794482678a64023f0f5459520e1..d990aae60e5a6056b44249cb7039470c6757b7fb 100644
--- a/src/main/java/net/minecraft/server/EntityVillagerTrader.java
+++ b/src/main/java/net/minecraft/server/EntityVillagerTrader.java
@@ -42,6 +42,7 @@ public class EntityVillagerTrader extends EntityVillagerAbstract {
         this.goalSelector.a(1, new PathfinderGoalPanic(this, 0.5D));
         this.goalSelector.a(1, new PathfinderGoalLookAtTradingPlayer(this));
         this.goalSelector.a(2, new EntityVillagerTrader.a(this, 2.0D, 0.35D));
+        if (world.purpurConfig.villagerTraderFollowEmeraldBlock) this.goalSelector.a(3, new PathfinderGoalTempt(this, 1.0D, false, TEMPT_ITEMS)); // Purpur
         this.goalSelector.a(4, new PathfinderGoalMoveTowardsRestriction(this, 0.35D));
         this.goalSelector.a(8, new PathfinderGoalRandomStrollLand(this, 0.35D));
         this.goalSelector.a(9, new PathfinderGoalInteract(this, EntityHuman.class, 3.0F, 1.0F));
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index edcbec38dfb5b32f4b8ba40c7a1ac6e26f0a4c3b..a1f85ef007f2ed410f1662405b0b1175c544e0b6 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -286,10 +286,17 @@ public class PurpurWorldConfig {
     public int villagerBrainTicks = 1;
     public boolean villagerUseBrainTicksOnlyWhenLagging = true;
     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);
         villagerFarmingBypassMobGriefing = getBoolean("mobs.villager.bypass-mob-griefing", villagerFarmingBypassMobGriefing);
+        villagerFollowEmeraldBlock = getBoolean("mobs.villager.follow-emerald-blocks", villagerFollowEmeraldBlock);
+    }
+
+    public boolean villagerTraderFollowEmeraldBlock = false;
+    private void villagerTraderSettings() {
+        villagerTraderFollowEmeraldBlock = getBoolean("mobs.wandering_trader.follow-emerald-blocks", villagerTraderFollowEmeraldBlock);
     }
 
     public boolean witherSkeletonTakesWitherDamage = false;
