Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.06 KB | None | 0 0
  1.     public class ThreadBuildHouse extends Thread
  2.     {
  3.         boolean running = false;
  4.         Player player;
  5.        
  6.         Stack<Block> doors = new Stack<Block>();
  7.         ArrayList<Block> tempdoors;
  8.         HashSet<String> processeddoors = new HashSet<String>();
  9.        
  10.         ArrayList<HashSet<String>> rooms = new ArrayList<HashSet<String>>();
  11.        
  12.         HashSet<String> processed;
  13.         HashMap<Integer,Integer> blockcount;
  14.        
  15.         int c;
  16.        
  17.         boolean door = false;
  18.         Block doorblock = null;
  19.        
  20.         public ThreadBuildHouse(Player player, int x, int y, int z)
  21.         {
  22.             this.player = player;
  23.             doors.push(new Block(64,x,y,z));
  24.            
  25.             running = true;
  26.             this.start();
  27.         }
  28.        
  29.         public void run()
  30.         {
  31.             player.sendMessage("-House-");
  32.             while (!doors.empty())
  33.             {
  34.                 Block door = doors.pop();
  35.                 int x = door.getX();
  36.                 int y = door.getY();
  37.                 int z = door.getZ();
  38.                
  39.                 processeddoors.add(x+":"+(y+1)+":"+z);
  40.                 processeddoors.add(x+":"+(y)+":"+z);
  41.                
  42.                 int tx = 0, ty = 0, tz = 0;
  43.                 //Get Other Things
  44.                 if (!transparentBlocks.contains(server.getBlockAt(x+1, y, z).getType()) && !transparentBlocks.contains(server.getBlockAt(x-1, y, z).getType()))
  45.                 {
  46.                     tx = x; ty = y; tz = z+1;
  47.                     if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
  48.                    
  49.                     tx = x; ty = y; tz = z-1;
  50.                     if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
  51.                 }
  52.                 else if (!transparentBlocks.contains(server.getBlockAt(x, y, z+1).getType()) && !transparentBlocks.contains(server.getBlockAt(x, y, z-1).getType()))
  53.                 {
  54.                     tx = x+1; ty = y; tz = z;
  55.                     if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
  56.                    
  57.                     tx = x-1; ty = y; tz = z;
  58.                     if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
  59.                 }
  60.                
  61.             }
  62.             player.sendMessage("------");
  63.         }
  64.        
  65.         public void makeRoom(Block door, int x, int y, int z)
  66.         {          
  67.             int dx = door.getX();
  68.             int dy = door.getY();
  69.             int dz = door.getZ();
  70.            
  71.             processed = new HashSet<String>();
  72.             blockcount = new HashMap<Integer,Integer>();
  73.             tempdoors = new ArrayList<Block>();
  74.             c = 0;
  75.            
  76.             //AddOtherDoorBlocks
  77.             processed.add(dx+":"+(dy+1)+":"+dz);
  78.             processed.add(dx+":"+dy+":"+dz);
  79.            
  80.             if (makeRoomStep(x, y, z))
  81.             {
  82.                 ping( "Room size: "+c);
  83.                 rooms.add(processed);
  84.                 //player.sendMessage("Another room");
  85.                
  86.                 for (Block tempdoor:tempdoors)
  87.                 {
  88.                     doors.push(tempdoor);
  89.                 }
  90.             }
  91.             else
  92.             {
  93.                 //ping("Leak!");
  94.             }
  95.         }
  96.        
  97.         public boolean makeRoomStep(int x, int y, int z)
  98.         {
  99.             if (processed.contains(x+":"+y+":"+z)) {return true;}
  100.             processed.add(x+":"+y+":"+z);
  101.            
  102.             if (server.getBlockAt(x, y-1, z).getY() == getHighestBlockY(x, z))
  103.             {
  104.                 return false;
  105.             }
  106.            
  107.             int type = server.getBlockAt(x, y, z).getType();
  108.             if (!transparentBlocks.contains(Integer.valueOf(type)))
  109.             {
  110.                 if (type == 64 && server.getBlockAt(x, y-1, z).getType() != 64 && server.getBlockAt(x, y-1, z).getType() != 0)
  111.                 {
  112.                     door = true;
  113.                     if (server.getBlockAt(x, y+1, z).getType() == 64)
  114.                     {
  115.                         if (!processeddoors.contains(x+":"+y+":"+z))
  116.                         {
  117.                             tempdoors.add(new Block(64,x,y,z));
  118.                         }
  119.                     }
  120.                 }
  121.                
  122.                 if (blockcount.containsKey(type))
  123.                 {
  124.                     blockcount.put(type, blockcount.get(type)+1);
  125.                 }
  126.                 else
  127.                 {
  128.                     blockcount.put(type, 1);
  129.                 }
  130.                 //player.sendMessage("Wall");
  131.                 return true;
  132.             }
  133.            
  134.             if (    makeRoomStep(x, y - 1, z) &&
  135.                     makeRoomStep(x, y + 1, z) &&
  136.                     makeRoomStep(x + 1, y, z) &&
  137.                     makeRoomStep(x - 1, y, z) &&
  138.                     makeRoomStep(x, y, z + 1) &&
  139.                     makeRoomStep(x, y, z - 1))
  140.                 {
  141.                     c++;
  142.                     return true;
  143.                 }
  144.            
  145.         return false;    
  146.         }
  147.  
  148.         public boolean roomProcessed(int x, int y, int z)
  149.         {
  150.             for (HashSet<String> room : rooms)
  151.             {
  152.                 if (room.contains(x+":"+y+":"+z)) {return true;}
  153.             }
  154.            
  155.             return false;
  156.         }
  157.        
  158.         public void ping(String txt)
  159.         {
  160.             server.getPlayer("Mendel").sendMessage(txt);
  161.         }
  162.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement