# [Solved]Get Entities In Radius Failing

## Recommended Posts

Here is my code my goal is to get all entities withing the radius of 10,000

```	public List<Entity> getEnts(World w,int x, int z,int radius) {
}```

There are lots of pigs and slimes yet it only outputed this list:

`[06:48:25] [Server thread/INFO] [STDOUT]: [com.EvilNotch.lanessentials.commands.CommandButcher:execute:65]: [EntityPlayerMP['Player52'/298, l='New World', x=172.76, y=4.64, z=-1269.33], EntityItem['item.item.beetroot'/295, l='New World', x=202.14, y=4.94, z=-1258.86], EntityItem['item.item.beetroot_seeds'/296, l='New World', x=202.08, y=5.00, z=-1259.44], EntityItem['item.item.beetroot_seeds'/297, l='New World', x=201.01, y=5.00, z=-1259.89]]`

Solved:

```	public List<Entity> getEnts(World w,int x, int z,int radius) {
return w.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(x,0,z,x+1,257,z+1).grow(radius));
}```

Edited by jredfox
##### Share on other sites

14 minutes ago, diesieben07 said:

You are not actually getting entities within a radius, since you are only expanding in the positive direction. You ﻿need to start at x﻿-radius ﻿﻿﻿and go up to x+radius ﻿﻿(radius is half the diameter).

is there a way to get the min and max y dynamically?

```	public List<Entity> getEnts(World w,int x, int z,int radius) {
}```

Edited by jredfox
##### Share on other sites

nevermind

Edited by jredfox
##### Share on other sites

16 minutes ago, diesieben07 said:

You are not actually getting entities within a radius, since you are only expanding in the positive direction. You need to start at x-radius and go up to x+radius (radius is half the diameter).

Edit still not working I put 4 pigs beside me with a block radius of one did my butcher command and it only found 2 out of the 4 pigs in a 1 block radius:

it seems to occur going twords -x and postive z

##### Share on other sites

35 minutes ago, diesieben07 said:

Are you sure those pigs were actually within the radius? Use the debugger.

I did I printed it said on 0,0 with radius of one -x:-1 +x:1 -z:-1 +z:1

I think they were it's just it uses double values which was < -1 as double and which was > 1 as double. So I used -1.999 and 1.999 to get to the very edge of the block.

That seemed to fix all of my errors

Edited by jredfox
##### Share on other sites

3 hours ago, diesieben07 said:

Are you sure those pigs were actually within the radius? Use the debugger.

this isn't solved still now I am having the opposite problem with having the 0.999+ it's now killing stuff it shouldn't be. if I set it to anything like +0.1 it fixes it but then the older issue of it not killing stuff is back. I think w.getEntitiesWithinAABB() is bugged.

Steps to reproduce:
place armor stands all around you
place one inside of you
do /butcher armor_stand 0
it kills your one and several others a block a way
If you change the 0.9 to 0.1 then it won't kill them all in 1 block radius with /butcher armor_stand 1

Code:
https://github.com/jredfox/lanessentials/blob/master/src/main/java/com/EvilNotch/lanessentials/commands/CommandButcher.java

Edited by jredfox
##### Share on other sites

14 hours ago, diesieben07 said:

You should probably use the floating point entity position ﻿﻿(Entity#pos﻿[XYZ]) instead of truncating ﻿it to an int﻿﻿.

I copied and pasted the mob spawner code seemed to fix it although I don't understand why there is a +1 on everything. The only thing I changed was the y:

```	public List<Entity> getEnts(World w,int x, int z,int radius) {
return w.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(x,0,z,x+1,257,z+1).grow(radius));
}```

##### Share on other sites

JRed I have to ask, how did you learn Java?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro (\$\$\$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

Curse/Overwolf: If you are using the Curse Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Curse's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
2. Make a launcher profile targeting this version of Forge.
3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

or alternately,

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

1. Open a command prompt (CMD, Powershell, Terminal, etc).
2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
3. Run the following commands:
1. git init
2. git remote add origin [Your Repository's URL]
• In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
3. git fetch
4. git checkout --track origin/master
5. git stage *
6. git commit -m "[Your commit message]"
7. git push
4. Navigate to GitHub and you should now see most of the files.
• note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

##### Share on other sites

@jredfox You might not have learned this yet, but the first rule of programming is: Its ALWAYS your fault.

Minecraft is a lot of code by a lot of (mostly novice) programmers, there will be bugs in it. But I highly doubt that any code that gets a lot of use (like getEntitiesWithinAABB). You asked why there is a +1? It turns an AABB representing a point into an AABB with a size of one block.

Spoiler

My Discord - Cadiboo#8887

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

##### Share on other sites

11 hours ago, Cadiboo said:

@jredfox You might not have learned this yet, but the first rule of programming is: Its ALWAYS your fault.

Minecraft is a lot of code by a lot of (mostly novice) programmers, there will be bugs in it. But I highly doubt that any code that gets a lot of use (like getEntitiesWithinAABB). You asked why there is a +1? It turns an AABB representing a point into an AABB with a size of one block.

if you read the code I was using what other people gave me and it should have made sense. And no it's not always my fault when it's broken or nobody knows how to use it or it's not made to be used that way.

my original code was x-radius 0,z-radius, x+radius,255,z+radius which should have worked but, for some reason bounding boxes need an extra +xz on their end or it won't work properly and will find entities where it shouldn't be finding them.

##### Share on other sites

16 hours ago, DaemonUmbra said:

JRed I have to ask, how did you learn Java?

read above if you read anything my original code should have worked it was x+-radius z+-radius and that's what everyone else said as well but, bounding boxes need an extra +1 because they are not meant to be in radius they are meant to be in a box so it doesn't quite work that way. So yes I know java but, the method doesn't do what everyone else said it does the way it said it did that's why I made this forum. I forgot about the mob spawner till the very last post and fixed mine

Edited by jredfox
##### Share on other sites

31 minutes ago, jredfox said:

it's﻿ not made to be used tha﻿t way﻿﻿﻿.﻿

Hate to tell you this but this is exactly when it’s your fault. Basically, if your modding minecraft, everything is your fault because minecraft was definitely NOT made to be modded. All of us have to deal with this unfortunate fact everyday. Basically we’re dealing with a dozen other peoples half-written code. You’ve probably figured out by now that even with forge, the end result isn’t pretty. I’m not trying to give you shit but you seem to not understand a lot about how the internals of me work, maybe looking at the concepts that underly it would be a good idea? Who am I kidding your probably gonna have to learn all this through trial and error, as I said minecraft is full of quirks

Spoiler

My Discord - Cadiboo#8887

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

##### Share on other sites

3 minutes ago, Cadiboo said:

Hate to tell you this but this is exactly when it’s your fault. Basically, if your modding minecraft, everything is your fault because minecraft was definitely NOT made to be modded. All of us have to deal with this unfortunate fact everyday. Basically we’re dealing with a dozen other peoples half-written code. You’ve probably figured out by now that even with forge, the end result isn’t pretty.

has nothing to do with that. It wasn't half written it was the simple fact of java x method() doesn't work they way you thought it did because x method needs y() to happen first to your vars

Edited by jredfox
##### Share on other sites

4 minutes ago, jredfox said:

has nothing to do with that. It wasn't half written it was the simple fact of java x method() doesn't work they way you thought it did because x method needs y() to happen first to your vars

Um AABB was written by Notch it’s not just a normal java method

Spoiler

My Discord - Cadiboo#8887

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

## 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.

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 previous content has been restored.   Clear editor

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

### Announcements

×

• #### Activity

×
• Create New...

## Important Information

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