I'm working on a plugin for the minecraft server api known as Bukkit.
My issues are getting the blocks as I don't know how to achieve this.
At the moment, I have the following:
public boolean loadSigns(Location loc1, Location loc2){
Selection selection = new Selection(loc1, loc2);
if(selection.getMax().getBlockY() - selection.getMin().getBlockY() != 0){
return false;
}
if ((selection.getMax().getBlockX() - selection.getMin().getBlockX()) != 0 && (selection.getMin().getBlockZ() - selection.getMax().getBlockZ() != 0)) {
return false;
}
World w = loc1.getWorld();
Integer x1 = loc1.getBlockX();
Integer y1 = loc1.getBlockY();
Integer z1 = loc1.getBlockZ();
Integer x2 = loc2.getBlockX();
Integer z2 = loc2.getBlockZ();
@SuppressWarnings("deprecation")
int dir = new Location(w, x1, y1, z1).getBlock().getData();
if (x1 - x2 == 0) {
for (int a = Math.max(x1, x2); a >= Math.min(x1, x2); a--) {
Location l = new Location(w, a, y1, z1);
BlockState b = l.getBlock().getState();
if (b instanceof Sign) {
signs.add((Sign) b);
} else {
return false;
}
}
} else {
for (int a = Math.min(z1, z2); a <= Math.max(z1, z2); a++) {
Location l = new Location(w, x1, y1, a);
BlockState b = l.getBlock().getState();
if (b instanceof Sign) {
signs.add((Sign) b);
} else {
return false;
}
}
}
if (dir == 3 || dir == 5) {
Collections.reverse(signs);
}
update();
return true;
}
loc1 is the left/start of the sign row; loc2 is the end/right of the sign row.
The problem with this is that any sign facing east or west only gets the first/start sign and not any of the others. If you need to see any other code, please say so.
P.S. new Selection(Location, Location);
is just a cuboid region.