Hey, How can I check if a player is nearby a specific block (Podzol)? I tried using getNearbyEntities(x,y,z); but that only works for an entity... Thank you,
Josh014 That's the method I use for checking if a player is near a block: Code:java public static boolean isNearBlock(Player p, int range, Material mat) { Location loc = p.getLocation(); World world = p.getWorld(); double cX = loc.getX(); double cY = loc.getY(); double cZ = loc.getZ(); double bPow = Math.pow(range + 0.5D, 2); double xPow; double zPow; for (int z = -range; z <= range; z++) { zPow = Math.pow(z, 2); for (int x = -range; x <= range; x++) { xPow = Math.pow(x, 2); for (int y = -range; y <= range; y++) if ((xPow + Math.pow(y, 2) + zPow) <= bPow) if (world.getBlockAt((int) (cX + x), (int) (cY + y), (int) (cZ + z)).getType() == mat) return true; } } return false; }
DarkBladee12 , How can I give players potion effects with this? Oh and when does this trigger? Only when a player is nearby a a block? Can you make it more like a pseudo code so I can understand a bit about what you've done?
Josh014 Isn't that clear what that is? It's just a method that checks if a player is nearby a block with the specified material, so it doesn't trigger itself at all... It depends on where you want to check it, so if you want to check when the player moves if he is near such a block just use the PlayerMoveEvent.
DarkBlade12 How can I trigger it? Like, do I need to copy this and place it in PlayerMoveEvent? Edit: I have never used this before, sorry.
Josh014 So you never make own methods, huh? Of course you have to copy it into one of your classes and call the method with isNearBlock(PLAYER, RANGE, MATERIAL);.
DarkBladee12 I used it a few times. Btw is the range around the block? If it is, is it possible to make it only go high up in the sky/ground?
Josh014 It makes a sphere with the desired range about the player and checks if inside the sphere is a block with the specified material. Yeah it's possible to only check if the block with this material is somewhere beneath or above the player.
DarkBladee12 Alright I got it to work, but how can I do it that it only goes high up and in the ground? Or just that I can modify the x,y,z of the range? Edit: How can I check it with the Matrial Podzol?
spoljo666 it works fine, but I want that the radius goes in a box around it and that you can configure the height/width of the box. Instead of a sphere.