Jump to content

Player enters area


DrPiggy

Recommended Posts

Hey, i have a region type system, and i want to check whenever a player enters that region/area, and teleport him back(Basically not give him access to that area.), now i could just check with getEntitiesWithinAABB every tick but that sounds heavy on the tps and just pretty stupid, i wandered if there's some kind of event or better way to do that? thanks.

Link to comment
Share on other sites

One alternative would be subscribing to PlayerTickEvent and checking if the player is in the region before teleporting them back. This probably has fairly minimal overhead, but you should profile it to check.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

3 minutes ago, Choonster said:

One alternative would be subscribing to PlayerTickEvent and checking if the player is in the region before teleporting them back. This probably has fairly minimal overhead, but you should profile it to check.

well yea, that's just using a tick handler that's what i thought will probably lag the server.

Link to comment
Share on other sites

26 minutes ago, DrPiggy said:

well yea, that's just using a tick handler that's what i thought will probably lag the server.

 

I don't think there's any other way than checking every tick, but doing it per-player may be less expensive than using World#getEntitiesWithinAABB.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

2 hours ago, Choonster said:

 

I don't think there's any other way than checking every tick, but doing it per-player may be less expensive than using World#getEntitiesWithinAABB.

how would i check if hes inside an area if i only have the the xyz1 and xyz2 of the area? (Besides using getEntitiesWithinAABB)

Link to comment
Share on other sites

3 minutes ago, DrPiggy said:

i only have the the xyz1 and xyz2 of the area

2
 

You can use these coordinates to determine the smaller and bigger coordinate of each axis, and check if the player's position is the coordinates.

Edited by larsgerrits

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Just now, diesieben07 said:

Check if the players xyz is greater than xyz1 and smaller than xyz2.

 

Just now, larsgerrits said:

You can use these coordinates to determine the smaller and bigger coordinate of each axis, and check if the player's position is the corodinates.

thanks :D

Link to comment
Share on other sites

3 minutes ago, DrPiggy said:

how would i check if hes inside an area if i only have the the xyz1 and xyz2 of the area? (Besides using getEntitiesWithinAABB)

 

Just now, diesieben07 said:

Check if the players xyz is greater than xyz1 and smaller than xyz2.

 

You can get an entity's bounding box with Entity#getEntityBoundingBox and then use AxisAlignedBB#intersects(double, double, double, double, double, double) to check if it intersects with the region's coordinates. This is essentially what World#getEntitiesWithinAABB does for every entity in the chunks covered by the AABB.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Just now, Choonster said:

 

 

You can get an entity's bounding box with Entity#getEntityBoundingBox and then use AxisAlignedBB#intersects(double, double, double, double, double, double) to check if it intersects with the region's coordinates. This is essentially what World#getEntitiesWithinAABB does for every entity in the chunks covered by the AABB.

Welp, thanks! thats easier then this :P

if (event.player.posX >= area.getLocA()[0] && event.player.posY >= area.getLocA()[1]
					&& event.player.posZ >= area.getLocA()[2] && event.player.posX <= area.getLocB()[0]
					&& event.player.posY <= area.getLocB()[1] && event.player.posZ <= area.getLocB()[2]) {

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.