From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Fri, 27 Nov 2020 10:33:33 -0600
Subject: [PATCH] Zombie break door minimum difficulty option


diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java
index fe045f8e35fe2aac51032a67ce52b27a53a8eff0..03bc86c776596ca5964c22adb757115d60980311 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/BreakDoorGoal.java
@@ -7,6 +7,8 @@ import net.minecraft.world.entity.Mob;
 import net.minecraft.world.level.GameRules;
 import net.minecraft.world.level.block.Block;
 
+import static net.minecraft.world.Difficulty.*; // Purpur
+
 public class BreakDoorGoal extends DoorInteractGoal {
 
     private static final int DEFAULT_DOOR_BREAK_TIME = 240;
@@ -19,7 +21,7 @@ public class BreakDoorGoal extends DoorInteractGoal {
         super(mob);
         this.lastBreakProgress = -1;
         this.doorBreakTime = -1;
-        this.validDifficulties = difficultySufficientPredicate;
+        this.validDifficulties = mob instanceof net.minecraft.world.entity.monster.Zombie ? difficulty -> testDifficulty(mob) : difficultySufficientPredicate; // Purpur
     }
 
     public BreakDoorGoal(Mob mob, int maxProgress, Predicate<Difficulty> difficultySufficientPredicate) {
@@ -88,4 +90,16 @@ public class BreakDoorGoal extends DoorInteractGoal {
     private boolean isValidDifficulty(Difficulty difficulty) {
         return this.validDifficulties.test(difficulty);
     }
+
+    // Purpur start
+    private boolean testDifficulty(Mob entity) {
+        Difficulty d = entity.level.getDifficulty();
+        return switch (entity.level.purpurConfig.zombieBreakDoorMinDifficulty) {
+            case PEACEFUL -> d == HARD || d == NORMAL || d == EASY || d == PEACEFUL;
+            case EASY     -> d == HARD || d == NORMAL || d == EASY;
+            case NORMAL   -> d == HARD || d == NORMAL;
+            default       -> d == HARD;
+        };
+    }
+    // Purpur end
 }
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 14f7fb59c2b5840254afe7695e1b7413ec5909e8..a589e2292aae4402cef2a6a6cea68ab1f81d7f5a 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -1783,6 +1783,7 @@ public class PurpurWorldConfig {
     public double zombieJockeyChance = 0.05D;
     public boolean zombieJockeyTryExistingChickens = true;
     public boolean zombieAggressiveTowardsVillagerWhenLagging = true;
+    public Difficulty zombieBreakDoorMinDifficulty = Difficulty.HARD;
     private void zombieSettings() {
         zombieRidable = getBoolean("mobs.zombie.ridable", zombieRidable);
         zombieRidableInWater = getBoolean("mobs.zombie.ridable-in-water", zombieRidableInWater);
@@ -1797,6 +1798,11 @@ public class PurpurWorldConfig {
         zombieJockeyChance = getDouble("mobs.zombie.jockey.chance", zombieJockeyChance);
         zombieJockeyTryExistingChickens = getBoolean("mobs.zombie.jockey.try-existing-chickens", zombieJockeyTryExistingChickens);
         zombieAggressiveTowardsVillagerWhenLagging = getBoolean("mobs.zombie.aggressive-towards-villager-when-lagging", zombieAggressiveTowardsVillagerWhenLagging);
+        try {
+            zombieBreakDoorMinDifficulty = Difficulty.valueOf(getString("mobs.zombie.break-door-minimum-difficulty", zombieBreakDoorMinDifficulty.name()));
+        } catch (IllegalArgumentException ignore) {
+            zombieBreakDoorMinDifficulty = Difficulty.HARD;
+        }
     }
 
     public boolean zombieHorseRidableInWater = false;
