Check if blocklocation is within portal frame

Discussion in 'Plugin Development' started by Darkman2412, Sep 3, 2011.

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

    Darkman2412

    Hi!

    I'm working on a plugin that uses custom portals (normal obsidian portal frame with water inside it), but I can't find a way to determine if a block is inside the frame.

    So I tried to find out, but I'm out of ideas...
    This is what I have now:
    Code:java
    1. public boolean isPortal(Location loc) {
    2. Location loc1 = loc;
    3. Block currblock = loc1.getBlock();
    4. int i;
    5. for(i=0; i<4; i++)
    6. {
    7. if(currblock.getRelative(0, i, 0).getType().equals(Material.OBSIDIAN))
    8. {
    9. currblock = currblock.getRelative(0, i, 0);
    10. if(currblock.getRelative(BlockFace.DOWN, 1).getType().equals(Material.STATIONARY_WATER)
    11. &&currblock.getRelative(BlockFace.DOWN, 1).getType().equals(Material.STATIONARY_WATER)
    12. &&currblock.getRelative(BlockFace.DOWN, 2).getType().equals(Material.STATIONARY_WATER)
    13. &&currblock.getRelative(BlockFace.DOWN, 3).getType().equals(Material.STATIONARY_WATER)
    14. &&currblock.getRelative(BlockFace.DOWN, 4).getType().equals(Material.OBSIDIAN))
    15. return true;
    16. }
    17. }
    18. return false;
    19. }


    Thanks in advance,
    Darkman2412
     
  2. Offline

    Jogy34

    just take a block of obsidian and check to see if (using X/Y/Z) there is an obsidian frame and then in it if there is water or you can check to see if when the player touches water blocks if there is the right amount of water/obsidian around it using the same method
     
  3. Offline

    Darkman2412

    Well, that's easier said than done, lol
    So, I split a giant function into 2 functions (checkNorth->when portal is pointing to the north, and checkEast->you know what I mean lol), but they both return false.

    Code is so long, so I put it on :gist ^^ https://gist.github.com/616378a44434ade43998

    Thanks in advance
     
  4. Offline

    bergerkiller

    Used a similar function in MyWorlds for the water portal. Maybe this will guide you into some direction...

    Code:
        public static boolean isSolid(Block b, BlockFace direction) {
            int maxwidth = 10;
            while (true) {
                int id = b.getTypeId();
                if (id == 0) return false;
                if (id != 9 && id != 8) return true;
                b = b.getRelative(direction);
                --maxwidth;
                if (maxwidth <= 0) return false;
            }
        }
    Code:
        @Override
        public void onPlayerMove(PlayerMoveEvent event) {
            Block b = event.getTo().getBlock();
            if (MyWorlds.useWaterTeleport && b.getTypeId() == 9) {
                if (b.getRelative(BlockFace.UP).getTypeId() == 9 ||
                        b.getRelative(BlockFace.DOWN).getTypeId() == 9) {
                    boolean allow = false;
                    if (b.getRelative(BlockFace.NORTH).getType() == Material.AIR ||
                            b.getRelative(BlockFace.SOUTH).getType() == Material.AIR) {
                        if (isSolid(b, BlockFace.WEST) && isSolid(b, BlockFace.EAST)) {
                            allow = true;
                        }
                    } else if (b.getRelative(BlockFace.EAST).getType() == Material.AIR ||
                            b.getRelative(BlockFace.WEST).getType() == Material.AIR) {
                        if (isSolid(b, BlockFace.NORTH) && isSolid(b, BlockFace.SOUTH)) {
                            allow = true;
                        }
                    }
                    if (allow)
                        Portal.handlePortalEnter(event.getPlayer());
                }
            }
        }
    Also, reason why I don't use the Material.WATER is that for some reason deep water is not in the Material enumeration. Therefore, 8 and 9.
     
Thread Status:
Not open for further replies.

Share This Page