Skip to content

Commit

Permalink
polygon.shift, with_world
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 22, 2021
1 parent b86a02e commit 8996f47
Showing 1 changed file with 51 additions and 3 deletions.
Expand Up @@ -78,7 +78,9 @@ public PolygonTag(WorldTag world, double yMin, double yMax, List<Corner> corners
this.world = world;
this.yMin = yMin;
this.yMax = yMax;
this.corners.addAll(corners);
for (Corner corner : corners) {
this.corners.add(new Corner(corner.x, corner.z));
}
recalculateBox();
}

Expand Down Expand Up @@ -641,6 +643,32 @@ public static void registerTags() {
return list;
});

// <--[tag]
// @attribute <PolygonTag.shift[<vector>]>
// @returns PolygonTag
// @description
// Returns a copy of the polygon, with all coordinates shifted by the given location-vector.
// -->
registerTag("shift", (attribute, polygon) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("PolygonTag.shift[...] tag must have an input.");
return null;
}
LocationTag shift = attribute.contextAsType(1, LocationTag.class);
PolygonTag toReturn = polygon.clone();
toReturn.yMin += shift.getY();
toReturn.yMax += shift.getY();
for (Corner corner : toReturn.corners) {
corner.x += shift.getX();
corner.z += shift.getZ();
}
toReturn.boxMin.x += shift.getX();
toReturn.boxMin.z += shift.getZ();
toReturn.boxMax.x += shift.getX();
toReturn.boxMax.z += shift.getZ();
return toReturn;
});

// <--[tag]
// @attribute <PolygonTag.with_corner[<location>]>
// @returns PolygonTag
Expand All @@ -655,8 +683,9 @@ public static void registerTags() {
}
LocationTag corner = attribute.contextAsType(1, LocationTag.class);
PolygonTag toReturn = polygon.clone();
toReturn.corners.add(new Corner(corner.getX(), corner.getZ()));
toReturn.recalculateBox();
Corner added = new Corner(corner.getX(), corner.getZ());
toReturn.corners.add(added);
toReturn.recalculateToFit(added);
return toReturn;
});

Expand Down Expand Up @@ -692,6 +721,25 @@ public static void registerTags() {
return toReturn;
});

// <--[tag]
// @attribute <PolygonTag.with_world[<world>]>
// @returns PolygonTag
// @description
// Returns a copy of the polygon, with the specified world.
// -->
registerTag("with_world", (attribute, polygon) -> {
if (!attribute.hasContext(1)) {
attribute.echoError("PolygonTag.with_world[...] tag must have an input.");
return null;
}
PolygonTag toReturn = polygon.clone();
toReturn.world = attribute.contextAsType(1, WorldTag.class);
if (toReturn.world == null) {
return null;
}
return toReturn;
});

// <--[tag]
// @attribute <PolygonTag.include_y[<#.#>]>
// @returns PolygonTag
Expand Down

0 comments on commit 8996f47

Please sign in to comment.