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/EntityCreeper.java b/src/main/java/net/minecraft/world/entity/monster/EntityCreeper.java
index 62d40f726355283baddde349c52bee0599bb293c..014091f35ee5aac0ee2f155ccec2daf586e4d3d3 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EntityCreeper.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EntityCreeper.java
@@ -7,6 +7,7 @@ import net.minecraft.network.syncher.DataWatcher;
 import net.minecraft.network.syncher.DataWatcherObject;
 import net.minecraft.network.syncher.DataWatcherRegistry;
 import net.minecraft.server.PathfinderGoalHasRider;
+import net.minecraft.server.level.EntityPlayer;
 import net.minecraft.server.level.WorldServer;
 import net.minecraft.sounds.SoundEffect;
 import net.minecraft.sounds.SoundEffects;
@@ -63,6 +64,7 @@ public class EntityCreeper extends EntityMonster {
     private int spacebarCharge = 0;
     private int prevSpacebarCharge = 0;
     private int powerToggleDelay = 0;
+    private boolean exploding = false;
     // Purpur end
 
     public EntityCreeper(EntityTypes<? extends EntityCreeper> entitytypes, World world) {
@@ -142,6 +144,14 @@ public class EntityCreeper extends EntityMonster {
     public void initAttributes() {
         this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(this.world.purpurConfig.creeperMaxHealth);
     }
+
+    protected org.bukkit.event.entity.EntityDeathEvent d(DamageSource damagesource) {
+        if (!exploding && this.world.purpurConfig.creeperExplodeWhenKilled && damagesource.getEntity() instanceof EntityPlayer) {
+            this.explode();
+        }
+
+        return super.d(damagesource);
+    }
     // Purpur end
 
     @Override
@@ -327,6 +337,7 @@ public class EntityCreeper extends EntityMonster {
     }
 
     public void explode() {
+        this.exploding = true; // Purpur
         if (!this.world.isClientSide) {
             Explosion.Effect explosion_effect = this.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING) && world.purpurConfig.creeperAllowGriefing ? Explosion.Effect.DESTROY : Explosion.Effect.NONE; // Purpur
             float f = this.isPowered() ? 2.0F : 1.0F;
@@ -346,6 +357,7 @@ public class EntityCreeper extends EntityMonster {
             // CraftBukkit end
         }
 
+        this.exploding = false; // Purpur
     }
 
     private void createEffectCloud() {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 61361ca712cdc92c76b64dd2a87cea0080edc02e..1adedace256828ba34c643eaf2b480601ede1b2b 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -711,12 +711,14 @@ public class PurpurWorldConfig {
 
     public boolean creeperRidable = false;
     public boolean creeperRidableInWater = false;
+    public boolean creeperExplodeWhenKilled = false;
     public boolean creeperAllowGriefing = true;
     public double creeperChargedChance = 0.0D;
     public double creeperMaxHealth = 20.0D;
     private void creeperSettings() {
         creeperRidable = getBoolean("mobs.creeper.ridable", creeperRidable);
         creeperRidableInWater = getBoolean("mobs.creeper.ridable-in-water", creeperRidableInWater);
+        creeperExplodeWhenKilled = getBoolean("mobs.creeper.explode-when-killed", creeperExplodeWhenKilled);
         creeperAllowGriefing = getBoolean("mobs.creeper.allow-griefing", creeperAllowGriefing);
         creeperChargedChance = getDouble("mobs.creeper.naturally-charged-chance", creeperChargedChance);
         if (PurpurConfig.version < 10) {
