From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Encode42 <me@encode42.dev>
Date: Tue, 16 Mar 2021 19:50:58 -0400
Subject: [PATCH] Config to make Creepers explode on death

Creepers exploded after being killed in the alpha days. This brings that back.

diff --git a/src/main/java/net/minecraft/world/entity/monster/Creeper.java b/src/main/java/net/minecraft/world/entity/monster/Creeper.java
index c550b8c19837ed9bf730a3eb777bc00de4e7ceb2..02494dcc8a342f65b2855612aebeb019095abf65 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Creeper.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Creeper.java
@@ -64,6 +64,7 @@ public class Creeper extends Monster implements PowerableMob {
     private int spacebarCharge = 0;
     private int prevSpacebarCharge = 0;
     private int powerToggleDelay = 0;
+    private boolean exploding = false;
     // Purpur end
 
     public Creeper(EntityType<? extends Creeper> type, Level world) {
@@ -142,6 +143,14 @@ public class Creeper extends Monster implements PowerableMob {
         }
         return super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityNbt);
     }
+
+    @Override
+    protected org.bukkit.event.entity.EntityDeathEvent dropAllDeathLoot(DamageSource damagesource) {
+        if (!exploding && this.level.purpurConfig.creeperExplodeWhenKilled && damagesource.getEntity() instanceof net.minecraft.server.level.ServerPlayer) {
+            this.explodeCreeper();
+        }
+        return super.dropAllDeathLoot(damagesource);
+    }
     // Purpur end
 
     @Override
@@ -339,6 +348,7 @@ public class Creeper extends Monster implements PowerableMob {
     }
 
     public void explodeCreeper() {
+        this.exploding = true; // Purpur
         if (!this.level.isClientSide) {
             Explosion.BlockInteraction explosion_effect = (this.level.purpurConfig.creeperBypassMobGriefing || this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && level.purpurConfig.creeperAllowGriefing ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.NONE; // Purpur
             float f = this.isPowered() ? 2.0F : 1.0F;
@@ -357,7 +367,7 @@ public class Creeper extends Monster implements PowerableMob {
             }
             // CraftBukkit end
         }
-
+        this.exploding = false; // Purpur
     }
 
     private void spawnLingeringCloud() {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 1b3b2a94cd33661c913706a297e6660cf7c93086..580f2a28adc946643951d16403ff53ebccbe7982 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -792,6 +792,7 @@ public class PurpurWorldConfig {
     public double creeperChargedChance = 0.0D;
     public boolean creeperAllowGriefing = true;
     public boolean creeperBypassMobGriefing = false;
+    public boolean creeperExplodeWhenKilled = false;
     private void creeperSettings() {
         creeperRidable = getBoolean("mobs.creeper.ridable", creeperRidable);
         creeperRidableInWater = getBoolean("mobs.creeper.ridable-in-water", creeperRidableInWater);
@@ -804,6 +805,7 @@ public class PurpurWorldConfig {
         creeperChargedChance = getDouble("mobs.creeper.naturally-charged-chance", creeperChargedChance);
         creeperAllowGriefing = getBoolean("mobs.creeper.allow-griefing", creeperAllowGriefing);
         creeperBypassMobGriefing = getBoolean("mobs.creeper.bypass-mob-griefing", creeperBypassMobGriefing);
+        creeperExplodeWhenKilled = getBoolean("mobs.creeper.explode-when-killed", creeperExplodeWhenKilled);
     }
 
     public boolean dolphinRidable = false;
