Skip to content

Commit

Permalink
Add cuboid.is_within[cuboid] tag
Browse files Browse the repository at this point in the history
Also check world in intersects. Also fix some meta.
  • Loading branch information
mcmonkey4eva committed Feb 6, 2015
1 parent 33b4183 commit b044381
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 41 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dCuboid.java
Expand Up @@ -829,23 +829,62 @@ public String getAttribute(Attribute attribute) {
dCuboid cub2 = dCuboid.valueOf(attribute.getContext(1));
if (cub2 != null) {
boolean intersects = false;
for (LocationPair pair: pairs) {
whole_loop: for (LocationPair pair: pairs) {
for (LocationPair pair2: cub2.pairs) {
if (!pair.low.getWorld().getName().equalsIgnoreCase(pair2.low.getWorld().getName())) {
return new Element("false").getAttribute(attribute.fulfill(1));
}
if (pair2.low.getX() <= pair.high.getX()
&& pair2.low.getY() <= pair.high.getY()
&& pair2.low.getZ() <= pair.high.getZ()
&& pair2.high.getX() >= pair.low.getX()
&& pair2.high.getY() >= pair.low.getY()
&& pair2.high.getZ() >= pair.low.getZ()) {
intersects = true;
break;
break whole_loop;
}
}
}
return new Element(intersects).getAttribute(attribute.fulfill(1));
}
}

// <--[tag]
// @attribute <cu@cuboid.is_within[<cuboid>]>
// @returns Element(Boolean)
// @description
// Returns whether this cuboid is fully inside another cuboid.
// -->
if (attribute.startsWith("is_within")
&& attribute.hasContext(1)) {
dCuboid cub2 = dCuboid.valueOf(attribute.getContext(1));
if (cub2 != null) {
boolean contains = true;
for (LocationPair pair2: pairs) {
boolean contained = false;
for (LocationPair pair: cub2.pairs) {
if (!pair.low.getWorld().getName().equalsIgnoreCase(pair2.low.getWorld().getName())) {
return new Element("false").getAttribute(attribute.fulfill(1));
}
if (!(pair2.low.getX() >= pair.low.getX()
&& pair2.low.getY() >= pair.low.getY()
&& pair2.low.getZ() >= pair.low.getZ()
&& pair2.high.getX() <= pair.high.getX()
&& pair2.high.getY() <= pair.high.getY()
&& pair2.high.getZ() <= pair.high.getZ())) {
contained = true;
break;
}
}
if (!contained) {
contains = false;
break;
}
}
return new Element(contains).getAttribute(attribute.fulfill(1));
}
}

// <--[tag]
// @attribute <cu@cuboid.center[<index>]>
// @returns dLocation
Expand Down
Expand Up @@ -3390,7 +3390,7 @@ public void playerGameModeChange(PlayerGameModeChangeEvent event) {
// <context.location> returns the dLocation the player is clicking on.
// <context.cuboids> returns a dList of the notable cuboids that contain the clicked block.
// <context.click_type> returns an Element of the click type.
// <context.relative> returns a dLocation of the air block in front of the click block.
// <context.relative> returns a dLocation of the air block in front of the clicked block.
//
// @Determine
// "CANCELLED" to stop the click from happening.
Expand Down

0 comments on commit b044381

Please sign in to comment.