Files
Purpur/patches/server/0065-Add-player-death-exp-control-options.patch
BillyGalbreath 82ef35225f progress
2021-06-16 17:17:33 -05:00

60 lines
2.8 KiB
Diff

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 686f64000ca633fe58d8d479ef3c8462052ec9c5..b7d572b2ce34f9b856e023fd90d1c7999fc448e5 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -196,6 +196,8 @@ public abstract class Player extends LivingEntity {
public abstract void resetLastActionTime();
// Purpur start
+ private javax.script.ScriptEngine scriptEngine = new javax.script.ScriptEngineManager().getEngineByName("rhino");
+
public void setAfk(boolean afk) {
}
@@ -1899,9 +1901,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 46ce3d663b7bbcc7bb40964245ddf0350081d000..b36f3a38ec80db8fef2850a37e839b9d1492d730 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -146,6 +146,13 @@ public class PurpurWorldConfig {
}
}
+ public String playerDeathExpDropEquation = "expLevel * 7";
+ public int playerDeathExpDropMax = 100;
+ private void playerDeathExpSettings() {
+ playerDeathExpDropEquation = getString("gameplay-mechanics.player.exp-dropped-on-death.equation", playerDeathExpDropEquation);
+ playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax);
+ }
+
public boolean idleTimeoutKick = true;
public boolean idleTimeoutTickNearbyEntities = true;
public boolean idleTimeoutCountAsSleeping = false;