From 4f9bd3ab780f5f1dc0d527ad6ba1d807bceafbcc Mon Sep 17 00:00:00 2001 From: altrisi Date: Sun, 2 Oct 2022 18:46:58 +0200 Subject: [PATCH] Simplify and standarize some conversions with `ValueConversions` --- src/main/java/carpet/script/api/WorldAccess.java | 12 +++++------- .../java/carpet/script/value/ValueConversions.java | 4 +--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 372466e4..52620ba4 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -1,6 +1,5 @@ package carpet.script.api; -import carpet.CarpetServer; import carpet.CarpetSettings; import carpet.fakes.ChunkGeneratorInterface; import carpet.fakes.ChunkTicketManagerInterface; @@ -11,7 +10,6 @@ import carpet.fakes.ThreadedAnvilChunkStorageInterface; import carpet.helpers.FeatureGenerator; import carpet.mixins.PoiRecord_scarpetMixin; import carpet.script.CarpetContext; -import carpet.script.CarpetScriptServer; import carpet.script.Context; import carpet.script.Expression; import carpet.script.Fluff; @@ -340,7 +338,7 @@ public class WorldAccess { ListValue.of( ValueConversions.of(Registry.POINT_OF_INTEREST_TYPE.getKey(p.getPoiType().value())), new NumericValue(p.getPoiType().value().maxTickets() - ((PoiRecord_scarpetMixin)p).getFreeTickets()), - ListValue.of(new NumericValue(p.getPos().getX()), new NumericValue(p.getPos().getY()), new NumericValue(p.getPos().getZ())) + ValueConversions.of(p.getPos()) ) ).collect(Collectors.toList())); }); @@ -452,14 +450,14 @@ public class WorldAccess { BlockPos pos = ((BlockValue) v).getPos(); if (pos == null) throw new InternalExpressionException("Cannot fetch position of an unrealized block"); - return ListValue.of(new NumericValue(pos.getX()), new NumericValue(pos.getY()), new NumericValue(pos.getZ())); + return ValueConversions.of(pos); } else if (v instanceof EntityValue) { Entity e = ((EntityValue) v).getEntity(); if (e == null) throw new InternalExpressionException("Null entity"); - return ListValue.of(new NumericValue(e.getX()), new NumericValue(e.getY()), new NumericValue(e.getZ())); + return ValueConversions.of(e.position()); } else { @@ -481,7 +479,7 @@ public class WorldAccess { if (lv.size() > locator.offset+1) howMuch = (int) NumericValue.asNumber(lv.get(locator.offset+1)).getLong(); BlockPos retpos = pos.relative(dir, howMuch); - return ListValue.of(new NumericValue(retpos.getX()), new NumericValue(retpos.getY()), new NumericValue(retpos.getZ())); + return ValueConversions.of(retpos); }); expression.addContextFunction("solid", -1, (c, t, lv) -> @@ -1414,7 +1412,7 @@ public class WorldAccess { BoundingBox box = start.getBoundingBox(); structureList.put( new StringValue(NBTSerializableValue.nameFromRegistryId(reg.getKey(entry.getKey()))), - ListValue.of(ListValue.fromTriple(box.minX(), box.minY(), box.minZ()), ListValue.fromTriple(box.maxX(), box.maxY(), box.maxZ())) + ValueConversions.of(box) ); } return MapValue.wrap(structureList); diff --git a/src/main/java/carpet/script/value/ValueConversions.java b/src/main/java/carpet/script/value/ValueConversions.java index e870fb8c..670a102d 100644 --- a/src/main/java/carpet/script/value/ValueConversions.java +++ b/src/main/java/carpet/script/value/ValueConversions.java @@ -178,9 +178,7 @@ public class ValueConversions { if (id == null) // should be Value.NULL return Value.NULL; - if (id.getNamespace().equals("minecraft")) - return new StringValue(id.getPath()); - return new StringValue(id.toString()); + return new StringValue(simplify(id)); } public static String simplify(ResourceLocation id)