This commit is contained in:
gnembon committed 2020-04-21 01:38:48 -03:00
1 parent d56706b133
commit f5316a1e2d
1 file changed
+31 -1
@@ -532,7 +532,37 @@ public class EntityValue extends Value
private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{ private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{
put("remove", (entity, value) -> entity.remove()); put("remove", (entity, value) -> entity.remove());
put("age", (e, v) -> e.age = Math.abs((int)NumericValue.asNumber(v).getLong()) ); 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<Value> vals = ((ListValue) v).getItems();
dmgPoints = (float) NumericValue.asNumber(v).getDouble();
source = DamageSource ... yeah...
}
else
{
}
});*/
put("kill", (e, v) -> e.kill()); put("kill", (e, v) -> e.kill());
put("location", (e, v) -> put("location", (e, v) ->
{ {