--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2012/03/18 11:43:52 1748 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2012/03/19 08:59:33 1753 @@ -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; } @@ -175,30 +176,80 @@ } - void buildTemplate(Location loc, Pair[][][] template) { + void buildTemplate(Location loc, Pair[][][] template, int pass) { + + World world = loc.getWorld(); for (int i=0; i= 256) { + y = loc.getBlockY() + j; + if (y >= 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; //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; + } 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; + } + } }