Jump to content

Recommended Posts

Posted

For a mod i'm working on i have a function that scans from a start location out so many blocks. This works fine for getting the first instance of a block in from the corner of the scan area; However, it doesn't work for getting the closest block to a location. How would i program it so it will find the closest block too the location. Which the location is going to be an entity which moves.

 

 

Also another question how would i find the closest instanceof a tileEntity

Here is the code i'm using to find it but it doesn't seem to be working

 /**
  * used to find the closest controller
  * @param par1 - x
  * @param par3 - y
  * @param par5 - z
  * @param par7 - range in blocks
  * @return the nearest controller
  */
	 public TileEntityComp getClosestControler(double par1, double par3, double par5, double par7)
    {
	 double var9 = -1.0D;
	    TileEntityComp var11 = null;
	    List itemList = worldObj.getEntitiesWithinAABB(TileEntityComp.class, this.boundingBox.expand(par7, 4.0D, par7));
	    for (int var12 = 0; var12 < itemList.size(); ++var12)
	    {
	    	TileEntityComp var13 = (TileEntityComp)itemList.get(var12);
	        double var14 = var13.getDistanceFrom(par1, par3, par5);

	        if ((par7 < 0.0D || var14 < par7 * par7) && (var9 == -1.0D || var14 < var9))
	        {
	            var9 = var14;
	            var11 = var13;
	        }
	    }

	    return var11;
    }
 /**
  * used to find the closest controller with an empty slot mainly used to find and add a robot to the controller
  * @param par1 - x
  * @param par3 - y
  * @param par5 - z
  * @param par7 - range in blocks
  * @return the nearest controller block with an empty control slot
  */
 public TileEntityComp getEmptyControler(double par1, double par3, double par5, double par7)
    {
	 double var9 = -1.0D;
	    TileEntityComp var11 = null;
	    List itemList = worldObj.getEntitiesWithinAABB(TileEntityComp.class, this.boundingBox.expand(par7, 4.0D, par7));
	    for (int var12 = 0; var12 < itemList.size(); ++var12)
	    {
	    	TileEntityComp var13 = (TileEntityComp)itemList.get(var12);
	        double var14 = var13.getDistanceFrom(par1, par3, par5);

	        if ((par7 < 0.0D || var14 < par7 * par7) && (var9 == -1.0D || var14 < var9))
	        {
	        	for(int c = 0; c < 4; c++)
	        	{
	        	if(var13.BotList[c]==null)
	        	{
	        		 var11 = var13;
	        	}
	        	}
	            var9 = var14;		           
	        }
	    }

	    return var11;
    }

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.