From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <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/PathfinderGoalBreakDoor.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.java
index 10ee8a0a717354f50b29e7ebeab0ee2aa7bf42f7..d785066e2a52699c18315f7244d80db6cab0c736 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.java
@@ -3,7 +3,9 @@ package net.minecraft.world.entity.ai.goal;
 import java.util.function.Predicate;
 import net.minecraft.core.IPosition;
 import net.minecraft.world.EnumDifficulty;
+import net.minecraft.world.entity.Entity;
 import net.minecraft.world.entity.EntityInsentient;
+import net.minecraft.world.entity.monster.EntityZombie;
 import net.minecraft.world.level.GameRules;
 import net.minecraft.world.level.block.Block;
 
@@ -18,7 +20,7 @@ public class PathfinderGoalBreakDoor extends PathfinderGoalDoorInteract {
         super(entityinsentient);
         this.b = -1;
         this.c = -1;
-        this.g = predicate;
+        this.g = entityinsentient instanceof EntityZombie ? difficulty -> testDifficulty(entity) : predicate; // Purpur
     }
 
     public PathfinderGoalBreakDoor(EntityInsentient entityinsentient, int i, Predicate<EnumDifficulty> predicate) {
@@ -87,4 +89,21 @@ public class PathfinderGoalBreakDoor extends PathfinderGoalDoorInteract {
     private boolean a(EnumDifficulty enumdifficulty) {
         return this.g.test(enumdifficulty);
     }
+
+    // Purpur start
+    private boolean testDifficulty(Entity entity) {
+        EnumDifficulty difficulty = entity.world.getDifficulty();
+        switch (entity.world.purpurConfig.zombieBreakDoorMinDifficulty) {
+            case PEACEFUL:
+                return difficulty == EnumDifficulty.HARD || difficulty == EnumDifficulty.NORMAL || difficulty == EnumDifficulty.EASY || difficulty == EnumDifficulty.PEACEFUL;
+            case EASY:
+                return difficulty == EnumDifficulty.HARD || difficulty == EnumDifficulty.NORMAL || difficulty == EnumDifficulty.EASY;
+            case NORMAL:
+                return difficulty == EnumDifficulty.HARD || difficulty == EnumDifficulty.NORMAL;
+            case HARD:
+            default:
+                return difficulty == EnumDifficulty.HARD;
+        }
+    }
+    // Purpur end
 }
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index fd0abfef98944c8ce4cf91c1ddb401d62f82c4e5..55b64126f3fc586fefae9a16e7f1b5d28cffc14d 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -1,6 +1,7 @@
 package net.pl3x.purpur;
 
 import net.minecraft.core.IRegistry;
+import net.minecraft.world.EnumDifficulty;
 import net.minecraft.world.level.Explosion;
 import net.minecraft.world.level.block.Block;
 import net.minecraft.world.level.block.Blocks;
@@ -1144,6 +1145,7 @@ public class PurpurWorldConfig {
     public double zombieJockeyChance = 0.05D;
     public boolean zombieJockeyTryExistingChickens = true;
     public boolean zombieAggressiveTowardsVillagerWhenLagging = true;
+    public EnumDifficulty zombieBreakDoorMinDifficulty = EnumDifficulty.HARD;
     private void zombieSettings() {
         zombieRidable = getBoolean("mobs.zombie.ridable", zombieRidable);
         zombieRidableInWater = getBoolean("mobs.zombie.ridable-in-water", zombieRidableInWater);
@@ -1151,6 +1153,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 = EnumDifficulty.valueOf(getString("mobs.zombie.break-door-minimum-difficulty", zombieBreakDoorMinDifficulty.name()));
+        } catch (IllegalArgumentException ignore) {
+            zombieBreakDoorMinDifficulty = EnumDifficulty.HARD;
+        }
     }
 
     public boolean zombieHorseCanSwim = false;
