From f5316a1e2d19e124dd51b40e29639436808e82ce Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 21 Apr 2020 01:38:48 -0300 Subject: [PATCH] fixes #228 --- .../java/carpet/script/value/EntityValue.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 97418977..a0237460 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -532,7 +532,37 @@ public class EntityValue extends Value private static final Map> featureModifiers = new HashMap>() {{ put("remove", (entity, value) -> entity.remove()); put("age", (e, v) -> e.age = Math.abs((int)NumericValue.asNumber(v).getLong()) ); - put("health", (e, v) -> { if (e instanceof LivingEntity) ((LivingEntity) e).setHealth((float) NumericValue.asNumber(v).getDouble()); }); + put("health", (e, v) -> { + float health = (float) NumericValue.asNumber(v).getDouble(); + if (health <= 0f && e instanceof ServerPlayerEntity) + { + ServerPlayerEntity player = (ServerPlayerEntity) e; + if (player.container != null) + { + // if player dies with open container, then that causes NPE on the client side + // its a client side bug that may never surface unless vanilla gets into scripting at some point + // bug: #228 + player.closeContainer(); + } + ((LivingEntity) e).setHealth(health); + } + if (e instanceof LivingEntity) ((LivingEntity) e).setHealth(health); + }); + // todo add handling of the source for extra effects + /*put("damage", (e, v) -> { + float dmgPoints; + DamageSource source; + if (v instanceof ListValue && ((ListValue) v).getItems().size() > 1) + { + List vals = ((ListValue) v).getItems(); + dmgPoints = (float) NumericValue.asNumber(v).getDouble(); + source = DamageSource ... yeah... + } + else + { + + } + });*/ put("kill", (e, v) -> e.kill()); put("location", (e, v) -> {