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/world/entity/npc/EntityVillager.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
index 5539c4cbea46398e92ab6ec56bb9b821e5f01e02..2464f1a5a922a5557e2d00233033714533acad76 100644
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillager.java
@@ -59,6 +59,7 @@ import net.minecraft.world.entity.ai.BehaviorController;
 import net.minecraft.world.entity.ai.attributes.AttributeProvider;
 import net.minecraft.world.entity.ai.attributes.GenericAttributes;
 import net.minecraft.world.entity.ai.behavior.Behaviors;
+import net.minecraft.world.entity.ai.goal.PathfinderGoalTempt;
 import net.minecraft.world.entity.ai.gossip.Reputation;
 import net.minecraft.world.entity.ai.gossip.ReputationType;
 import net.minecraft.world.entity.ai.memory.MemoryModuleType;
@@ -143,6 +144,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/world/entity/npc/EntityVillagerAbstract.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
index 49821f0f26864c35be84a4a4288857a04668fbba..91142526187f96615b5cbd3ed3b68d9175cb9f8b 100644
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerAbstract.java
@@ -25,11 +25,13 @@ import net.minecraft.world.entity.EnumMobSpawn;
 import net.minecraft.world.entity.GroupDataEntity;
 import net.minecraft.world.entity.player.EntityHuman;
 import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.crafting.RecipeItemStack;
 import net.minecraft.world.item.trading.IMerchant;
 import net.minecraft.world.item.trading.MerchantRecipe;
 import net.minecraft.world.item.trading.MerchantRecipeList;
 import net.minecraft.world.level.World;
 import net.minecraft.world.level.WorldAccess;
+import net.minecraft.world.level.block.Blocks;
 import net.minecraft.world.level.pathfinder.PathType;
 
 // CraftBukkit start
@@ -45,6 +47,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/world/entity/npc/EntityVillagerTrader.java b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
index 37e1b2bf33510c3603efadf219b462e667f573c2..6c13a34a7ab220a3bba1c091f4f6a9e1340212f6 100644
--- a/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
+++ b/src/main/java/net/minecraft/world/entity/npc/EntityVillagerTrader.java
@@ -26,6 +26,7 @@ import net.minecraft.world.entity.ai.goal.PathfinderGoalLookAtTradingPlayer;
 import net.minecraft.world.entity.ai.goal.PathfinderGoalMoveTowardsRestriction;
 import net.minecraft.world.entity.ai.goal.PathfinderGoalPanic;
 import net.minecraft.world.entity.ai.goal.PathfinderGoalRandomStrollLand;
+import net.minecraft.world.entity.ai.goal.PathfinderGoalTempt;
 import net.minecraft.world.entity.ai.goal.PathfinderGoalTradeWithPlayer;
 import net.minecraft.world.entity.ai.goal.PathfinderGoalUseItem;
 import net.minecraft.world.entity.monster.EntityEvoker;
@@ -85,6 +86,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 c51628f1f30bcd0206fc2b04ed83aca4ab7fd51a..7d66e253391522d754146275024ffb017a685e6f 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;
