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/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
index 949fa7099198fdd00a0626ff53f75f3f2cada7f4..8a6a0825e7d4cc42f4325d2882461065b11a3202 100644
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
@@ -1037,6 +1037,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
 
     @Nullable
     private IronGolem trySpawnGolem(ServerLevel world) {
+        if (world.purpurConfig.villagerSpawnIronGolemRadius > 0 && world.getEntitiesOfClass(IronGolem.class, getBoundingBox().inflate(world.purpurConfig.villagerSpawnIronGolemRadius)).size() > world.purpurConfig.villagerSpawnIronGolemLimit) return null; // Purpur
         BlockPos blockposition = this.blockPosition();
 
         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 af80a7d516fa5669fe7406ab3b07b39ee643928f..18a6cc3765813868e624b8be8bd02fb057354637 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -1242,6 +1242,8 @@ public class PurpurWorldConfig {
     public boolean villagerUseBrainTicksOnlyWhenLagging = true;
     public boolean villagerFollowEmeraldBlock = false;
     public boolean villagerCanBeLeashed = false;
+    public int villagerSpawnIronGolemRadius = 0;
+    public int villagerSpawnIronGolemLimit = 0;
     private void villagerSettings() {
         villagerRidable = getBoolean("mobs.villager.ridable", villagerRidable);
         villagerRidableInWater = getBoolean("mobs.villager.ridable-in-water", villagerRidableInWater);
@@ -1255,6 +1257,8 @@ public class PurpurWorldConfig {
         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);
+        villagerSpawnIronGolemRadius = getInt("mobs.villager.spawn-iron-golem.radius", villagerSpawnIronGolemRadius);
+        villagerSpawnIronGolemLimit = getInt("mobs.villager.spawn-iron-golem.limit", villagerSpawnIronGolemLimit);
     }
 
     public boolean vindicatorRidable = false;
