I'm wondering how I'm able to create a square and be able to detect if players are in or out of the square. I would also need it to fit into chunks as well since I don't want half a chunk in the square and half the chunk out, if anyone can give me a hand in doing this it would be great.
MCCoding If you're looking to create a simple cube like region, which does overlap chunks if needed, you simply need to establish 3 for loops, these being for x,y, and z. for X, you want it to start at say.. 5 blocks less than the players current X co-ord, increasing to 5 higher, for example: int xLocation = player.getLocation().getX(); Code: for (int x = (xLocation - 5); x < (xLocation + 5); x++){ } Then, inside of this, you need a for loop for y, then z. This essentially scans all blocks within the given radius. Hopefully this will push you in the right direction
valon750 Not sure how looping through all blocks on every axis around a player finds who is in a square? MCCoding To check if someone is in a cuboid, you need corners. But if all you need is a square, you only need 1 origin and the length. So a player is in the cube if originX <= playerX <= originX + length, same goes for Z (not Y since you want a square). Now to fit them into chunks, just let the length be 16 and the origin a certain corner which you define, let's say North West, and always use NW origins with your squares.
Avygeil "Square" in a game based around cubes isn't exactly possible. The location used in my example can easily be altered to any location. You would then simply get all online players and check if they're in there, bingo.
valon750 I know what a square is. I assumed he meant a square as in a 2D plane, so that Y would not matter. Also, I didn't comment about your method because I thought you probably misread what the OP wanted. So if I have a 500*500*100 region, with your method, I'm going to loop through 25000000 blocks? All you need to do is compare coordinates. If coordinates are between boundaries, whatever shape it is, then it's inside. Looping through every block is like the slowest method for the simplest thing.
Avygeil No where in the original post does it mention he wants to search a large area. Sure, if they're after a large radius then there are plenty of other methods.
valon750 But why, on earth, would you ever loop through blocks for something as simple as cuboid coordinates check, even if it's a small region? Give me a single reason.
However, should keep in mind that once you get going with bigger side lengths (50x50 for example) this will lagg the server.
All you need to do is hold in memory the coordinates/locations of the minimum and maximum boundaries of the region and then check if the player's coordinates are greater than/equal to the minimum and less than/equal to the maximum. This can be done with two Vectors and then using the isInAABB() method with the player's location converted to a Vector. If you want to have it constrained to chunks, just make sure the minimum coordinates are multiples of 16 and the maximum coordinates are multiples of 16, minus 1. This is a terribly inefficient solution.