Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ThreadBuildHouse extends Thread
- {
- boolean running = false;
- Player player;
- Stack<Block> doors = new Stack<Block>();
- ArrayList<Block> tempdoors;
- HashSet<String> processeddoors = new HashSet<String>();
- ArrayList<HashSet<String>> rooms = new ArrayList<HashSet<String>>();
- HashSet<String> processed;
- HashMap<Integer,Integer> blockcount;
- int c;
- boolean door = false;
- Block doorblock = null;
- public ThreadBuildHouse(Player player, int x, int y, int z)
- {
- this.player = player;
- doors.push(new Block(64,x,y,z));
- running = true;
- this.start();
- }
- public void run()
- {
- player.sendMessage("-House-");
- while (!doors.empty())
- {
- Block door = doors.pop();
- int x = door.getX();
- int y = door.getY();
- int z = door.getZ();
- processeddoors.add(x+":"+(y+1)+":"+z);
- processeddoors.add(x+":"+(y)+":"+z);
- int tx = 0, ty = 0, tz = 0;
- //Get Other Things
- if (!transparentBlocks.contains(server.getBlockAt(x+1, y, z).getType()) && !transparentBlocks.contains(server.getBlockAt(x-1, y, z).getType()))
- {
- tx = x; ty = y; tz = z+1;
- if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
- tx = x; ty = y; tz = z-1;
- if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
- }
- else if (!transparentBlocks.contains(server.getBlockAt(x, y, z+1).getType()) && !transparentBlocks.contains(server.getBlockAt(x, y, z-1).getType()))
- {
- tx = x+1; ty = y; tz = z;
- if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
- tx = x-1; ty = y; tz = z;
- if (!roomProcessed(tx,ty,tz)) {makeRoom(door,tx,ty,tz);}
- }
- }
- player.sendMessage("------");
- }
- public void makeRoom(Block door, int x, int y, int z)
- {
- int dx = door.getX();
- int dy = door.getY();
- int dz = door.getZ();
- processed = new HashSet<String>();
- blockcount = new HashMap<Integer,Integer>();
- tempdoors = new ArrayList<Block>();
- c = 0;
- //AddOtherDoorBlocks
- processed.add(dx+":"+(dy+1)+":"+dz);
- processed.add(dx+":"+dy+":"+dz);
- if (makeRoomStep(x, y, z))
- {
- ping( "Room size: "+c);
- rooms.add(processed);
- //player.sendMessage("Another room");
- for (Block tempdoor:tempdoors)
- {
- doors.push(tempdoor);
- }
- }
- else
- {
- //ping("Leak!");
- }
- }
- public boolean makeRoomStep(int x, int y, int z)
- {
- if (processed.contains(x+":"+y+":"+z)) {return true;}
- processed.add(x+":"+y+":"+z);
- if (server.getBlockAt(x, y-1, z).getY() == getHighestBlockY(x, z))
- {
- return false;
- }
- int type = server.getBlockAt(x, y, z).getType();
- if (!transparentBlocks.contains(Integer.valueOf(type)))
- {
- if (type == 64 && server.getBlockAt(x, y-1, z).getType() != 64 && server.getBlockAt(x, y-1, z).getType() != 0)
- {
- door = true;
- if (server.getBlockAt(x, y+1, z).getType() == 64)
- {
- if (!processeddoors.contains(x+":"+y+":"+z))
- {
- tempdoors.add(new Block(64,x,y,z));
- }
- }
- }
- if (blockcount.containsKey(type))
- {
- blockcount.put(type, blockcount.get(type)+1);
- }
- else
- {
- blockcount.put(type, 1);
- }
- //player.sendMessage("Wall");
- return true;
- }
- if ( makeRoomStep(x, y - 1, z) &&
- makeRoomStep(x, y + 1, z) &&
- makeRoomStep(x + 1, y, z) &&
- makeRoomStep(x - 1, y, z) &&
- makeRoomStep(x, y, z + 1) &&
- makeRoomStep(x, y, z - 1))
- {
- c++;
- return true;
- }
- return false;
- }
- public boolean roomProcessed(int x, int y, int z)
- {
- for (HashSet<String> room : rooms)
- {
- if (room.contains(x+":"+y+":"+z)) {return true;}
- }
- return false;
- }
- public void ping(String txt)
- {
- server.getPlayer("Mendel").sendMessage(txt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement