Skip to content

Commit

Permalink
add tag location.block_facing, fixes #1863
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 16, 2019
1 parent a99486b commit 0ab93cd
Showing 1 changed file with 19 additions and 1 deletion.
Expand Up @@ -34,6 +34,7 @@
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Attachable;
import org.bukkit.material.Directional;
import org.bukkit.material.MaterialData;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -517,6 +518,23 @@ public String getAttribute(Attribute attribute) {
// BLOCK ATTRIBUTES
/////////////////

// <--[tag]
// @attribute <l@location.block_facing>
// @returns dLocation
// @description
// Returns the relative location vector of where this block is facing.
// Only works for block types that have directionality (such as signs, chests, stairs, etc.).
// This can return for example "1,0,0" to mean the block is facing towards the positive X axis.
// You can use <some_block_location.add[<some_block_location.block_facing>]> to get the block directly in front of this block (based on its facing direction).
// -->
if (attribute.matches("block_facing")) {
if (getBlock().getBlockData() instanceof Directional) {
Vector facing = ((Directional) getBlock().getBlockData()).getFacing().getDirection();
return new dLocation(getWorld(), facing.getX(), facing.getY(), facing.getZ())
.getAttribute(attribute.fulfill(1));
}
}

// <--[tag]
// @attribute <l@location.above>
// @returns dLocation
Expand Down Expand Up @@ -546,7 +564,7 @@ public String getAttribute(Attribute attribute) {
// Returns the location of the block this location is on,
// i.e. returns a location without decimals or direction.
// -->
if (attribute.startsWith("block")) {
if (attribute.matches("block")) {
return new dLocation(getWorld(), getBlockX(), getBlockY(), getBlockZ())
.getAttribute(attribute.fulfill(1));
}
Expand Down

0 comments on commit 0ab93cd

Please sign in to comment.