Improve JS exec return value handling (#1290)

This commit is contained in:
skbeh
2023-03-19 11:34:59 +08:00
committed by GitHub
parent 5200826333
commit ab3bcc95b4
13 changed files with 47 additions and 56 deletions

View File

@@ -5,10 +5,10 @@ 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 21da282c50a31d0d9a59bc93e6c60afe37950900..7518564208579de9104bdaddcab67db736d263f8 100644
index 21da282c50a31d0d9a59bc93e6c60afe37950900..9e4a8278ef601b17311ba53cb187329a434f7bab 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1965,9 +1965,18 @@ public abstract class Player extends LivingEntity {
@@ -1965,9 +1965,19 @@ public abstract class Player extends LivingEntity {
@Override
public int getExperienceReward() {
if (!this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) && !this.isSpectator()) {
@@ -18,11 +18,12 @@ index 21da282c50a31d0d9a59bc93e6c60afe37950900..7518564208579de9104bdaddcab67db7
+ // 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 = Math.round(((Number) scriptEngine.eval("let expLevel = " + experienceLevel + "; " +
+ "let expTotal = " + totalExperience + "; " +
+ "let exp = " + experienceProgress + "; " +
+ level.purpurConfig.playerDeathExpDropEquation)).floatValue());
+ } catch (javax.script.ScriptException e) {
+ e.printStackTrace();
+ toDrop = experienceLevel * 7;
+ }
+ return Math.min(toDrop, level.purpurConfig.playerDeathExpDropMax);
@@ -31,7 +32,7 @@ index 21da282c50a31d0d9a59bc93e6c60afe37950900..7518564208579de9104bdaddcab67db7
return 0;
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index ac895bceb7e352c36061a872a097e806b4fe3115..0f5940a1897dc1982233c29eaef908cb098ed0fd 100644
index 22e2f70c91be09444fb5e55a08448a650b556cc4..6d04bdafd0a2f40d51aad5735a6eb87b49264402 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -175,6 +175,8 @@ public class PurpurWorldConfig {