--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2012/03/18 11:38:57 1747 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2012/03/19 20:21:14 1759 @@ -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; @@ -73,7 +73,8 @@ return true; } - buildTemplate( player.getLocation(), template); + buildTemplate( player.getLocation(), template, 1); + buildTemplate( player.getLocation(), template, 2); return false; } @@ -119,8 +120,12 @@ if (line.length() == 0) continue; - if (line.charAt(0) == '-') + 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) { @@ -140,7 +145,7 @@ throw new Exception( "Template: invalid value on line " + lines + ": " + element[0] ); } - if (val < 0 || val>255) { + if (val < -1 || val>255) { throw new Exception( "Template: invalid value on line " + lines + ": " + val ); } @@ -175,26 +180,88 @@ } - void buildTemplate(Location loc, Pair[][][] template) { + 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; + + if (type == -1) { + continue; + } //plugin.getLogger().info( String.format( "Setting typeid at %d,%d,%d to %d", x,y,z, type) ); + if (pass == 1) { + if ( type == 50 || type == 75 || type == 76) //torch / redstone torch + continue; + if (type == 64 || type==71) //door / irondoor + continue; + if (type == 68) // sign + continue; + if (type == 65) // ladder + continue; + if (type == 67) // steps + continue; + } world.getBlockAt(x, y, z).setTypeIdAndData(type, data, true); + } } } } + + + //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; + } + } }