From f5868b24e29bc773e1f8b2f7e564505bddc7d349 Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 9 Jun 2020 02:59:53 -0300 Subject: [PATCH] Duration can be sent as 0 --- .../carpet/script/utils/ShapeDispatcher.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 770d7639..6215fe99 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -585,7 +585,7 @@ public class ShapeDispatcher public static Map of = new HashMap(){{ put("shape", new ShapeParam()); put("dim", new DimensionParam()); - put("duration", new PositiveIntParam("duration")); + put("duration", new NonNegativeIntParam("duration")); put("color", new ColorParam("color")); put("follow", new EntityParam("follow")); put("line", new PositiveFloatParam("line")); @@ -704,6 +704,20 @@ public class ShapeDispatcher public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value).getInt()); } } + public static class NonNegativeIntParam extends NumericParam + { + protected NonNegativeIntParam(String id) { super(id); } + @Override + public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); } + @Override + public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value).getInt()); } + @Override public Value validate(Map options, CarpetContext cc, Value value) + { + Value ret = super.validate(options, cc, value); + if (((NumericValue)ret).getDouble()<0) throw new InternalExpressionException("'"+id+"' should be non-negative"); + return ret; + } + } public static class Vec3Param extends Param {