Skip to content

Commit

Permalink
support cuboid input into cuboid.include
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 14, 2020
1 parent 11a7f08 commit a5d7478
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
Expand Up @@ -1124,37 +1124,23 @@ public static void registerTags() {
});

// <--[tag]
// @attribute <CuboidTag.include[<location>]>
// @attribute <CuboidTag.include[<location>/<cuboid>]>
// @returns CuboidTag
// @description
// Expands the first member of the CuboidTag to contain the given location, and returns the expanded cuboid.
// Expands the first member of the CuboidTag to contain the given location (or entire cuboid), and returns the expanded cuboid.
// -->
registerTag("include", (attribute, cuboid) -> {
if (!attribute.hasContext(1)) {
Debug.echoError("The tag CuboidTag.include[...] must have a value.");
return null;
}
CuboidTag newCuboid = CuboidTag.valueOf(attribute.getContext(1), CoreUtilities.noDebugContext);
if (newCuboid != null) {
return cuboid.including(newCuboid.getLow(0)).including(newCuboid.getHigh(0));
}
LocationTag loc = LocationTag.valueOf(attribute.getContext(1));
if (loc != null) {
if (loc.getX() < cuboid.pairs.get(0).low.getX()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), loc.getX(), cuboid.pairs.get(0).low.getY(), cuboid.pairs.get(0).low.getZ());
}
if (loc.getY() < cuboid.pairs.get(0).low.getY()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), cuboid.pairs.get(0).low.getX(), loc.getY(), cuboid.pairs.get(0).low.getZ());
}
if (loc.getZ() < cuboid.pairs.get(0).low.getZ()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), cuboid.pairs.get(0).low.getX(), cuboid.pairs.get(0).low.getY(), loc.getZ());
}
if (loc.getX() > cuboid.pairs.get(0).high.getX()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), loc.getX(), cuboid.pairs.get(0).high.getY(), cuboid.pairs.get(0).high.getZ());
}
if (loc.getY() > cuboid.pairs.get(0).high.getY()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), cuboid.pairs.get(0).high.getX(), loc.getY(), cuboid.pairs.get(0).high.getZ());
}
if (loc.getZ() > cuboid.pairs.get(0).high.getZ()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), cuboid.pairs.get(0).high.getX(), cuboid.pairs.get(0).high.getY(), loc.getZ());
}
return cuboid;
return cuboid.including(loc);
}
return null;
});
Expand All @@ -1166,6 +1152,7 @@ public static void registerTags() {
// Expands the first member of the CuboidTag to contain the given X value, and returns the expanded cuboid.
// -->
registerTag("include_x", (attribute, cuboid) -> {
cuboid = cuboid.clone();
if (!attribute.hasContext(1)) {
Debug.echoError("The tag CuboidTag.include_x[...] must have a value.");
return null;
Expand All @@ -1187,6 +1174,7 @@ public static void registerTags() {
// Expands the first member of the CuboidTag to contain the given Y value, and returns the expanded cuboid.
// -->
registerTag("include_y", (attribute, cuboid) -> {
cuboid = cuboid.clone();
if (!attribute.hasContext(1)) {
Debug.echoError("The tag CuboidTag.include_y[...] must have a value.");
return null;
Expand All @@ -1208,6 +1196,7 @@ public static void registerTags() {
// Expands the first member of the CuboidTag to contain the given Z value, and returns the expanded cuboid.
// -->
registerTag("include_z", (attribute, cuboid) -> {
cuboid = cuboid.clone();
if (!attribute.hasContext(1)) {
Debug.echoError("The tag CuboidTag.include_z[...] must have a value.");
return null;
Expand Down Expand Up @@ -1459,6 +1448,29 @@ public static void registerTags() {
});
}

public CuboidTag including(Location loc) {
CuboidTag cuboid = clone();
if (loc.getX() < cuboid.pairs.get(0).low.getX()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), loc.getX(), cuboid.pairs.get(0).low.getY(), cuboid.pairs.get(0).low.getZ());
}
if (loc.getY() < cuboid.pairs.get(0).low.getY()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), cuboid.pairs.get(0).low.getX(), loc.getY(), cuboid.pairs.get(0).low.getZ());
}
if (loc.getZ() < cuboid.pairs.get(0).low.getZ()) {
cuboid.pairs.get(0).low = new LocationTag(cuboid.pairs.get(0).low.getWorld(), cuboid.pairs.get(0).low.getX(), cuboid.pairs.get(0).low.getY(), loc.getZ());
}
if (loc.getX() > cuboid.pairs.get(0).high.getX()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), loc.getX(), cuboid.pairs.get(0).high.getY(), cuboid.pairs.get(0).high.getZ());
}
if (loc.getY() > cuboid.pairs.get(0).high.getY()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), cuboid.pairs.get(0).high.getX(), loc.getY(), cuboid.pairs.get(0).high.getZ());
}
if (loc.getZ() > cuboid.pairs.get(0).high.getZ()) {
cuboid.pairs.get(0).high = new LocationTag(cuboid.pairs.get(0).high.getWorld(), cuboid.pairs.get(0).high.getX(), cuboid.pairs.get(0).high.getY(), loc.getZ());
}
return cuboid;
}

public static ObjectTagProcessor<CuboidTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerTag(String name, TagRunnable.ObjectInterface<CuboidTag> runnable, String... variants) {
Expand Down
Expand Up @@ -71,7 +71,7 @@ public FlagCommand() {
//
// @Usage
// Use to create or set a flag on a player.
// - flag player playstyle:agressive
// - flag player playstyle:aggressive
//
// @Usage
// Use to flag an npc with a given tag value.
Expand Down

0 comments on commit a5d7478

Please sign in to comment.