xNuminousx
Verified Member
So for starters here's the code I'm working with:
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.
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;
}
}
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.