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

@@ -31,10 +31,10 @@ index 41a6cd3a81c531b6349ca364b85712954a97aa11..b64c492a245494ab60c325d66dc6ec65
+ if (!this.level.purpurConfig.shulkerSpawnFromBulletNearbyEquation.isBlank()) {
+ int nearby = this.level.getEntities((EntityTypeTest) EntityType.SHULKER, axisalignedbb.inflate(this.level.purpurConfig.shulkerSpawnFromBulletNearbyRange), Entity::isAlive).size();
+ try {
+ scriptEngine.eval("nearby = " + nearby);
+ chance -= (float) scriptEngine.eval(this.level.purpurConfig.shulkerSpawnFromBulletNearbyEquation);
+ } catch (Exception ignore) {
+ chance -= (float) (nearby - 1) / 5.0F;
+ chance -= ((Number) scriptEngine.eval("let nearby = " + nearby + "; " + this.level.purpurConfig.shulkerSpawnFromBulletNearbyEquation)).floatValue();
+ } catch (javax.script.ScriptException e) {
+ e.printStackTrace();
+ chance -= (nearby - 1) / 5.0F;
+ }
+ }
+ if (this.level.random.nextFloat() <= chance) {