• Hello Guest! Did you know that ProjectKorra has an official Discord server? A lot of discussion about the official server, development process, and community discussion happens over there. Feel free to join now by clicking the link below.

    Join the Discord Server

Certain BlockFaces not working?

xNuminousx

Verified Member
So for starters here's the code I'm working with:
Java:
private boolean canSpawn(Location loc) {
        Block targetBlock = loc.getBlock();
        if (targetBlock.getRelative(BlockFace.DOWN).getType() == Material.AIR &&
                targetBlock.getRelative(BlockFace.UP).getType() == Material.AIR &&
                targetBlock.getRelative(BlockFace.EAST).getType() == Material.AIR &&
                targetBlock.getRelative(BlockFace.WEST).getType() == Material.AIR &&
                targetBlock.getRelative(BlockFace.NORTH).getType() == Material.AIR &&
                targetBlock.getRelative(BlockFace.SOUTH).getType() == Material.AIR) {
            return false;
        } else {
            return true;
        }
    }
My goal for this method was to have a check that could be used to see if a location is completely in the air or not. If one of the faces was against a block, then it would be considered against a wall and should return true. In other words, I want this method to return true if the 'targetBlock' is against a wall, on a ceiling, or on the floor. This works smoothly except for certain directions. This method returns true if you are looking north, west, or down (in terms of block faces I think this would be the south, east, and up faces regarding the BlockFace enum. Not sure how the direction is decided which makes this a little more tricky for me). However, if you are facing south, east, or up (in terms of BlockFace this may be north, west and down) this method is returning false and not allowing the location to register.

Okay so if that was confusing I'll try to make it a bit more simple. Basically, the method is returning true for only half of the directions and the other half are making the method return false. If there's an easier way to make or use this check, that'd be helpful. Otherwise, I'm confused as to what is wrong with this method which is making it do this. I did notice that there are other BlockFaces (like EAST_NORTH_EAST) however not sure if these other block faces could solve the issue.
 

Da Psic

Verified Member
Not a java programmer but have you tried splitting the code up to diagnose which directions work and which do not. Or maybe its trying to check to fast, I know that can be an issue in js.

An alternative would be to check if a block can be placed.
 

xNuminousx

Verified Member
I've already tested that method in game. I'm using it for my ability Orb and this method determines whether the Orb can be placed down or not. This method works for half of the faces but the other half do not. Although, I'm sure I could split the method up to see what's working and what's not.
 

xNuminousx

Verified Member
So a little update. I got the method to work better than before. The only issue now is that it doesn't work on ceilings. Rather than trying to sniff out which block faces weren't working, I figured the whole BlockFace collection probably means more than what I think so I included all of the faces. Here's the new code:

Java:
private boolean canSpawn(Location loc) {
        
        BlockFace[] faces = { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN,
                              BlockFace.EAST_NORTH_EAST, BlockFace.EAST_SOUTH_EAST,
                              BlockFace.NORTH_EAST, BlockFace.NORTH_NORTH_EAST, BlockFace.NORTH_NORTH_WEST, BlockFace.NORTH_WEST,
                              BlockFace.SOUTH_EAST, BlockFace.SOUTH_SOUTH_EAST, BlockFace.SOUTH_SOUTH_WEST, BlockFace.SOUTH_WEST,
                              BlockFace.WEST_NORTH_WEST, BlockFace.WEST_SOUTH_WEST };
        
        for (BlockFace face : faces) {
            if (GeneralMethods.isSolid(loc.getBlock().getRelative(face))) {
                return true;
            }
        }
        return false;
    }
 

Simplicitee

Staff member
Plugin Developer
Verified Member
Could you send whatever is using your canSpawn method? That would help in determining what might be wrong.
 

xNuminousx

Verified Member
Basically there's a configuration option that can be turned on or off. If requireGround is true, then the canSpawn method will be ran. If canSpawn returns false, then the ability won't continue on. If it returns true, then the ability continues. The canSpawn method is using targetLoc to check for BlockFaces. plantRange is another config variable that determines how far away a player is allowed to place down the ability.
Java:
this.targetLoc = GeneralMethods.getTargetedLocation(player, plantRange);
                    if (requireGround) {
                        if (!canSpawn(targetLoc)) {
                            remove();
                            return;
                        }
                    }
 

Simplicitee

Staff member
Plugin Developer
Verified Member
so far nothing you've sent shows that any of the code wouldn't work on ceilings
 

Simplicitee

Staff member
Plugin Developer
Verified Member
Add a debug message in the displayOrb method to see if it's actually running. I assume that GeneralMethods#getTargetedLocation isn't returning what you think.
 
Top