From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Mon, 22 Jul 2019 17:32:17 -0500
Subject: [PATCH] Implement configurable search radius for villagers to spawn
 iron golems


diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
index 1fa6cf564099323c8332e68cadf64c28dfc84998..8002c55497f772eadae3242cad06d529571e97bf 100644
--- a/src/main/java/net/minecraft/server/EntityVillager.java
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
@@ -892,6 +892,7 @@ public class EntityVillager extends EntityVillagerAbstract implements Reputation
 
     @Nullable
     private EntityIronGolem d(WorldServer worldserver) {
+        if (world.purpurConfig.villagerSpawnIronGolemRadius > 0 && world.a(EntityIronGolem.class, getBoundingBox().grow(world.purpurConfig.villagerSpawnIronGolemRadius)).size() > world.purpurConfig.villagerSpawnIronGolemLimit) return null; // Purpur
         BlockPosition blockposition = this.getChunkCoordinates();
 
         for (int i = 0; i < 10; ++i) {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index a9e7ddd55aa2b9b2c8f172069353b070c427b806..0de099d29b5e351822e59af6e389dc91c67eb2b2 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -288,12 +288,16 @@ public class PurpurWorldConfig {
     public boolean villagerCanBeLeashed = false;
     public boolean villagerFarmingBypassMobGriefing = false;
     public boolean villagerFollowEmeraldBlock = false;
+    public int villagerSpawnIronGolemRadius = 0;
+    public int villagerSpawnIronGolemLimit = 0;
     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);
+        villagerSpawnIronGolemRadius = getInt("mobs.villager.spawn-iron-golem.radius", villagerSpawnIronGolemRadius);
+        villagerSpawnIronGolemLimit = getInt("mobs.villager.spawn-iron-golem.limit", villagerSpawnIronGolemLimit);
     }
 
     public boolean villagerTraderCanBeLeashed = false;
