--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2012/03/18 14:36:49 1750 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2012/03/19 10:01:12 1755 @@ -53,7 +53,7 @@ return true; } - File templateFile = new File( plugin.getDataFolder(), "template_" + args[0] + ".txt"); + File templateFile = new File( plugin.getDataFolder(), "templates/" + args[0] + ".txt"); if (! templateFile.exists() ) { sender.sendMessage( ChatColor.YELLOW + "Template not found" ); return true; @@ -122,6 +122,10 @@ if (line.charAt(0) == '-') continue; + + if ( y >= ysize) { + throw new Exception( "Template: found more levels in file than specified in header" ); + } String elements[] = line.split(","); if (elements.length != zsize) { @@ -177,18 +181,41 @@ } void buildTemplate(Location loc, Pair[][][] template, int pass) { + + World world = loc.getWorld(); for (int i=0; i= 255) { continue; + } + + switch ( getFacing(loc) ) { + case 0: //west + x = loc.getBlockX() - k; + z = loc.getBlockZ() + i + 1; + break; + case 1: //north + x = loc.getBlockX() - i - 1; + z = loc.getBlockZ() - k; + break; + case 2: //east + x = loc.getBlockX() + k; + z = loc.getBlockZ() - i - 1; + break; + case 3: //south + x = loc.getBlockX() + i + 1; + z = loc.getBlockZ() + k; + break; } + int type = template[i][j][k].id; byte data = (byte) template[i][j][k].subId; @@ -210,5 +237,23 @@ } } + + + //yaw is left,right looking direction, 0=straight west + int getFacing(Location loc) { + int angle = (int) loc.getYaw(); + + if (angle < 45) { + return 0; + } else if (angle < 135) { + return 1; + } else if (angle < 225) { + return 2; + } else if (angle < 315) { + return 3; + } else { + return 0; + } + } }