mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 03:47:27 +00:00
IWorld:
-getEntitiesNear sorts by which one is nearest to the position.
This commit is contained in:
1 parent
6a852d9578
commit
1c10f2ebf1
2 files changed
+18
-15
No files matched your search
@@ -192,19 +192,6 @@ public class ScriptWorld implements IWorld {
|
||||
return list.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
public IEntity[] getEntitiesNear(double x, double y, double z, double range) {
|
||||
ArrayList<IEntity> list = new ArrayList<>();
|
||||
|
||||
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(
|
||||
x - range, y - range, z - range,
|
||||
x + range, y + range, z + range));
|
||||
for(Entity entity : entities){
|
||||
list.add(NpcAPI.Instance().getIEntity(entity));
|
||||
}
|
||||
|
||||
return list.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
public IEntity[] getEntitiesNear(IPos position, double range) {
|
||||
ArrayList<IEntity> list = new ArrayList<>();
|
||||
|
||||
@@ -215,9 +202,25 @@ public class ScriptWorld implements IWorld {
|
||||
list.add(NpcAPI.Instance().getIEntity(entity));
|
||||
}
|
||||
|
||||
list.sort((e1, e2) -> {
|
||||
double dist1 = e1.getPos().distanceTo(position);
|
||||
double dist2 = e2.getPos().distanceTo(position);
|
||||
|
||||
if (dist1 > dist2) {
|
||||
return 1;
|
||||
} else if (dist1 < dist2) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return list.toArray(new IEntity[0]);
|
||||
}
|
||||
|
||||
public IEntity[] getEntitiesNear(double x, double y, double z, double range) {
|
||||
return getEntitiesNear(new ScriptBlockPos(new BlockPos(x,y,z)), range);
|
||||
}
|
||||
|
||||
public void setTileEntity(int x, int y, int z, ITileEntity tileEntity){
|
||||
world.setTileEntity(x,y,z,tileEntity.getMCTileEntity());
|
||||
}
|
||||
|
||||
@@ -100,10 +100,10 @@ public interface IWorld {
|
||||
|
||||
IEntity[] getLoadedEntities();
|
||||
|
||||
IEntity[] getEntitiesNear(double x, double y, double z, double range);
|
||||
|
||||
IEntity[] getEntitiesNear(IPos position, double range);
|
||||
|
||||
IEntity[] getEntitiesNear(double x, double y, double z, double range);
|
||||
|
||||
/**
|
||||
* Sets the block's tile entity at the given position.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user