diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index 5ae49426..9b4ad2c5 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -3405,7 +3405,8 @@ Optional shared shape attributes: * `snap` - if `follow` is present, indicated on which axis the snapping to entity coordinates occurs, and which axis will be treated statically, i.e. the coordinate passed in a coord triple is the actual value in the world. Default value is `'xyz'`, meaning the shape will be drawn relatively to the entity in all three directions. Using `xz` for - instance makes so that the shape follows the entity, but stays at the same, absolute Y coordinate. + instance makes so that the shape follows the entity, but stays at the same, absolute Y coordinate. Preceeding an axis + with `d`, like `dxdydz` would make so that entity position is treated discretely (rounded down). Available shapes: * `'line'` - draws a straight line between two points. diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index 5bbdadb1..8091997d 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -75,7 +75,8 @@ Optional shared shape attributes: * `snap` - if `follow` is present, indicated on which axis the snapping to entity coordinates occurs, and which axis will be treated statically, i.e. the coordinate passed in a coord triple is the actual value in the world. Default value is `'xyz'`, meaning the shape will be drawn relatively to the entity in all three directions. Using `xz` for - instance makes so that the shape follows the entity, but stays at the same, absolute Y coordinate. + instance makes so that the shape follows the entity, but stays at the same, absolute Y coordinate. Preceeding an axis + with `d`, like `dxdydz` would make so that entity position is treated discretely (rounded down). Available shapes: * `'line'` - draws a straight line between two points. diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 00168e1b..d514bf19 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -257,6 +257,7 @@ public class ShapeDispatcher protected int followEntity; protected String snapTo; protected boolean snapX, snapY, snapZ; + protected boolean discreteX, discreteY, discreteZ; protected RegistryKey shapeDimension; @@ -319,15 +320,18 @@ public class ShapeDispatcher snapX = snapTo.contains("x"); snapY = snapTo.contains("y"); snapZ = snapTo.contains("z"); + discreteX = snapTo.contains("dx"); + discreteY = snapTo.contains("dy"); + discreteZ = snapTo.contains("dz"); } } public int getExpiry() { return duration; } public Vec3d toAbsolute(Entity e, Vec3d vec, float partialTick) { return vec.add( - snapX?MathHelper.lerp(partialTick, e.prevX, e.getX()):0.0, - snapY?MathHelper.lerp(partialTick, e.prevY, e.getY()):0.0, - snapZ?MathHelper.lerp(partialTick, e.prevZ, e.getZ()):0.0 + snapX?(discreteX ?MathHelper.floor(e.getX()):MathHelper.lerp(partialTick, e.prevX, e.getX())):0.0, + snapY?(discreteY ?MathHelper.floor(e.getY()):MathHelper.lerp(partialTick, e.prevY, e.getY())):0.0, + snapZ?(discreteZ ?MathHelper.floor(e.getZ()):MathHelper.lerp(partialTick, e.prevZ, e.getZ())):0.0 ); } public Vec3d relativiseRender(World world, Vec3d vec, float partialTick) @@ -370,6 +374,10 @@ public class ShapeDispatcher hash ^= shapeDimension.hashCode(); hash *= 1099511628211L; hash ^= color; hash *= 1099511628211L; hash ^= followEntity; hash *= 1099511628211L; + if (followEntity >= 0) + { + hash ^= snapTo.hashCode(); hash *= 1099511628211L; + } hash ^= Float.hashCode(lineWidth); hash *= 1099511628211L; if (fa != 0.0) { hash = 31*hash + fillColor; hash *= 1099511628211L; } return hash; @@ -830,7 +838,12 @@ public class ShapeDispatcher put("duration", new NonNegativeIntParam("duration")); put("color", new ColorParam("color")); put("follow", new EntityParam("follow")); - put("snap", new StringChoiceParam("snap", "xyz", "xz", "yz", "xy", "x", "y", "z")); + put("snap", new StringChoiceParam("snap", + "xyz", "xz", "yz", "xy", "x", "y", "z", + "dxdydz", "dxdz", "dydz", "dxdy", "dx", "dy", "dz", + "xdz", "dxz", "ydz", "dyz", "xdy", "dxy", + "xydz", "xdyz", "xdydz", "dxyz", "dxydz", "dxdyz" + )); put("line", new PositiveFloatParam("line")); put("fill", new ColorParam("fill"));