From 4dca3575e7e2c3d3f9e48a14147a581c2ea9e7c6 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 11 Oct 2019 16:07:40 -0300 Subject: [PATCH] delete accepts lvalues, still need to be more full proofed. --- src/main/java/carpet/script/Expression.java | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/script/Expression.java b/src/main/java/carpet/script/Expression.java index 6b037022..a10c16eb 100644 --- a/src/main/java/carpet/script/Expression.java +++ b/src/main/java/carpet/script/Expression.java @@ -2399,13 +2399,27 @@ public class Expression implements Cloneable } }); - addBinaryFunction("delete", (container, address) -> + addLazyFunction("delete", -1, (c, t, lv) -> { - if (container instanceof ContainerValueInterface) + Value containerOrLValue = lv.get(0).evalValue(c, Context.LVALUE); + ContainerValueInterface container; + Value address; + if (containerOrLValue instanceof LContainerValue) { - return ((ContainerValueInterface) container).delete(address); + container = ((LContainerValue) containerOrLValue).getContainer(); + address = ((LContainerValue) containerOrLValue).getAddress(); } - throw new InternalExpressionException("First argument of delete should be a container: list, map or nbt"); + else if (containerOrLValue instanceof ContainerValueInterface) + { + container = (ContainerValueInterface) containerOrLValue; + address = lv.get(1).evalValue(c); + } + else + { + throw new InternalExpressionException("First argument of delete should be a container: list, map or nbt"); + } + Value ret = container.delete(address); + return (cc, tt) -> ret; }); }