Jump to content

[1.16.5 MCP] detect entities around the player


ElTotisPro50

Recommended Posts

i tried something with axisAlignedBB but is not working

BlockPos playerPos = player.getPosition();
                BlockPos pos1 = playerPos.add(new Vector3i(player.getPosX() + 10,player.getPosY() + 10,player.getPosZ() + 10));
                BlockPos pos2 = playerPos.add(new Vector3i(player.getPosX() + 10,player.getPosY() + 10,player.getPosZ() + 10));
                List<CowEntity> targets = world.getEntitiesWithinAABB(CowEntity.class,new AxisAlignedBB(pos1,pos2));
                if(!targets.isEmpty()) {
                    player.sendStatusMessage(new StringTextComponent("there is a cow around you"))
                }
                  
           		AND (for example there are 3 cows in the range)
                  
                if(!targets.isEmpty()) {
                    player.sendStatusMessage(new StringTextComponent(targets))
                }

 

Link to comment
Share on other sites

7 hours ago, diesieben07 said:

pos1 and pos2 are the same position. As such your AABB is completely empty.

then, i have to subtract the 10 in pos1 or pos2? (i want to make the area a cube of 10x10 and the center of the area has to be the player)

BlockPos pos1 = playerPos.add(new Vector3i(player.getPosX() + 10,player.getPosY() + 10,player.getPosZ() + 10));
BlockPos pos2 = playerPos.add(new Vector3i(player.getPosX() - 10,player.getPosY() - 10,player.getPosZ() - 10));

 

Edited by ElTotisPro50
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.