Detect a cuboid inside a room that includes blocks other than air.

Discussion in 'Plugin Development' started by JamEngulfer221, Aug 28, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    JamEngulfer221

    I am writing the code for my plugin called Rooms, and I need to have the plugin automatically detect the cuboid of the room behind a door. (and have a cutoff point so it doesn't try and detect the entire world)
     
  2. So the rooms are going to be cubic?

    Might not be the most efficient way to do it, but I might try to find size of one wall (as example the one with the door), by one row / column at time for the farthest block. Then check the third axis for every block on this wall and get the farthest one.

    This way is going to have problems if you are going to have windows (not glass, just holes).

    Kinda hard to explain what Im thinking...
     
    JamEngulfer221 likes this.
  3. Offline

    bergerkiller

    Got something I made before...

    Code:
        public Block getSolid(Block from, BlockFace direction) {
            int maxinter = 20;
            while (from != null && from.getType() == Material.AIR) {
                from = from.getRelative(direction);
                --maxinter;
                if (maxinter < 0) break;
            }
            return from;
        }
    Code:
    Cuboid c = new Cuboid();
    c.xMin = getSolid(from, BlockFace.NORTH).getLocation().getBlockX();
    c.xMax = getSolid(from, BlockFace.SOUTH).getLocation().getBlockX();
    c.yMin = getSolid(from, BlockFace.DOWN).getLocation().getBlockY();
    c.yMax = getSolid(from, BlockFace.UP).getLocation().getBlockY();
    c.zMin = getSolid(from, BlockFace.EAST).getLocation().getBlockZ();
    c.zMax = getSolid(from, BlockFace.WEST).getLocation().getBlockZ();
     
  4. Offline

    JamEngulfer221

    @varesa
    @bergerkiller

    Well, I think I should give you a bit more context: I simply want to detect any chests and beds inside the room, so I can clear the chest and remove any homes set on the beds.

    My plans changed between now and when I made the original post :) Sorry.
     
  5. Offline

    bergerkiller

    You can use my previous code to get the room and simply loop through the blocks...
    Code:
    for (int x = cuboid.minX;x <= cuboid.maxX;x++) {
        for (int y = cuboid.minY;y <= cuboid.maxY;y++) {
             for (int z = cuboid.minZ;z <= cuboid.maxZ;z++) {
                 Block b = new Location(world, x, y, z).getBlock();
                 Material type = b.getType();
                 if (type == Material.BED) {
                        b.setType(Material.AIR);
                 }
             }
        }
    }
     
  6. Offline

    JamEngulfer221

    Ok, how would I clear any chests I find? I don't want to remove the bed, just any homes set on it (if that is even possible).
     
Thread Status:
Not open for further replies.

Share This Page