From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Thu, 26 Dec 2019 22:08:37 -0600
Subject: [PATCH] Add player death exp control options


diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index d761865eabfc67651b0a2a92ad35fc236886b61d..3e04510519ca5d03eb16aab8b1094e24101cebf4 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1907,9 +1907,18 @@ public abstract class Player extends LivingEntity {
     @Override
     protected int getExperienceReward(Player player) {
         if (!this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) && !this.isSpectator()) {
-            int i = this.experienceLevel * 7;
-
-            return i > 100 ? 100 : i;
+            // Purpur start
+            int toDrop;
+            try {
+                scriptEngine.eval("expLevel = " + experienceLevel);
+                scriptEngine.eval("expTotal = " + totalExperience);
+                scriptEngine.eval("exp = " + experienceProgress);
+                toDrop = (int) Math.round((Double) scriptEngine.eval(level.purpurConfig.playerDeathExpDropEquation));
+            } catch (Exception ignore) {
+                toDrop = experienceLevel * 7;
+            }
+            return Math.min(toDrop, level.purpurConfig.playerDeathExpDropMax);
+            // Purpur end
         } else {
             return 0;
         }
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 6ef7cdf5e006c027e5316dffff5931607b79243f..ff6d433b5b235948324d754297d837b955c924a1 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -167,6 +167,8 @@ public class PurpurWorldConfig {
     public boolean idleTimeoutTargetPlayer = true;
     public int playerSpawnInvulnerableTicks = 60;
     public boolean playerInvulnerableWhileAcceptingResourcePack = false;
+    public String playerDeathExpDropEquation = "expLevel * 7";
+    public int playerDeathExpDropMax = 100;
     private void playerSettings() {
         idleTimeoutKick = getBoolean("gameplay-mechanics.player.idle-timeout.kick-if-idle", idleTimeoutKick);
         idleTimeoutTickNearbyEntities = getBoolean("gameplay-mechanics.player.idle-timeout.tick-nearby-entities", idleTimeoutTickNearbyEntities);
@@ -175,6 +177,8 @@ public class PurpurWorldConfig {
         idleTimeoutTargetPlayer = getBoolean("gameplay-mechanics.player.idle-timeout.mods-target", idleTimeoutTargetPlayer);
         playerSpawnInvulnerableTicks = getInt("gameplay-mechanics.player.spawn-invulnerable-ticks", playerSpawnInvulnerableTicks);
         playerInvulnerableWhileAcceptingResourcePack = getBoolean("gameplay-mechanics.player.invulnerable-while-accepting-resource-pack", playerInvulnerableWhileAcceptingResourcePack);
+        playerDeathExpDropEquation = getString("gameplay-mechanics.player.exp-dropped-on-death.equation", playerDeathExpDropEquation);
+        playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax);
     }
 
     public boolean silkTouchEnabled = false;
