Skip to content

Commit

Permalink
ellipse.shell tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 18, 2020
1 parent f1bb1e3 commit 4c16ee4
Showing 1 changed file with 47 additions and 3 deletions.
Expand Up @@ -18,7 +18,7 @@
import java.util.ArrayList;
import java.util.List;

public class EllipsoidTag implements ObjectTag, Notable {
public class EllipsoidTag implements ObjectTag, Notable, Cloneable {

// <--[language]
// @name EllipsoidTag Objects
Expand Down Expand Up @@ -167,6 +167,41 @@ public List<LocationTag> getBlockLocationsUnfiltered() {
return locations;
}

public ListTag getShell() {
ListTag output = new ListTag();
double yScale = size.getY();
double diameterX = size.getX() * 2;
double diameterZ = size.getZ() * 2;
int maxY = (int) Math.floor(yScale);
output.addObject(new LocationTag(loc.getBlockX(), loc.getBlockY() - maxY, loc.getBlockZ(), loc.getWorldName()));
if (maxY != 0) {
output.addObject(new LocationTag(loc.getBlockX(), loc.getBlockY() + maxY, loc.getBlockZ(), loc.getWorldName()));
}
for (int y = -maxY; y <= maxY; y++) {
double yProgMin = Math.min(1.0, (Math.abs(y) + 1) / yScale);
double yProgMax = Math.abs(y) / yScale;
double minSubWidth = Math.sqrt(1.0 - yProgMin * yProgMin);
double maxSubWidth = Math.sqrt(1.0 - yProgMax * yProgMax);
double minX = diameterX * minSubWidth - 1;
double minZ = diameterZ * minSubWidth - 1;
double maxX = diameterX * maxSubWidth;
double maxZ = diameterZ * maxSubWidth;
for (int x = 0; x < maxX; x++) {
for (int z = 0; z < maxZ; z++) {
double scaleTestMin = (x * x) / (minX * minX) + (z * z) / (minZ * minZ);
double scaleTestMax = (x * x) / (maxX * maxX) + (z * z) / (maxZ * maxZ);
if (scaleTestMin >= 1.0 && scaleTestMax <= 1.0) {
output.addObject(new LocationTag(loc.getBlockX() + x, loc.getBlockY() + y, loc.getBlockZ() + z, loc.getWorldName()));
output.addObject(new LocationTag(loc.getBlockX() - x, loc.getBlockY() + y, loc.getBlockZ() + z, loc.getWorldName()));
output.addObject(new LocationTag(loc.getBlockX() + x, loc.getBlockY() + y, loc.getBlockZ() - z, loc.getWorldName()));
output.addObject(new LocationTag(loc.getBlockX() - x, loc.getBlockY() + y, loc.getBlockZ() - z, loc.getWorldName()));
}
}
}
}
return output;
}

public boolean contains(Location test) {
double xbase = test.getX() - loc.getX();
double ybase = test.getY() - loc.getY();
Expand Down Expand Up @@ -259,8 +294,7 @@ public static void registerTags() {
// @returns ListTag(LocationTag)
// @description
// Returns each block location within the EllipsoidTag.
// Optionally, specify a list of materials to only return locations
// with that block type.
// Optionally, specify a list of materials to only return locations with that block type.
// -->
registerTag("blocks", (attribute, object) -> {
if (attribute.hasContext(1)) {
Expand All @@ -271,6 +305,16 @@ public static void registerTags() {
}
}, "get_blocks");

// <--[tag]
// @attribute <EllipsoidTag.shell>
// @returns ListTag(LocationTag)
// @description
// Returns a 3D outline (shell) of this ellipsoid, as a list of block locations.
// -->
registerTag("shell", (attribute, object) -> {
return object.getShell();
});

// <--[tag]
// @attribute <EllipsoidTag.location>
// @returns LocationTag
Expand Down

0 comments on commit 4c16ee4

Please sign in to comment.