Jump to content

Recommended Posts

Posted

i have the following problem:

public static boolean setBlock(EntityPlayer player, int x, int y, int z, int id, int meta)
{
	boolean rv = false;
	if(player.worldObj.isAirBlock(x, y, z) && player.canPlayerEdit(x, y, z))
	{
	player.worldObj.setBlockAndMetadataWithNotify(x,y,z,id,meta);
	return true;
	}
	return rv;
}

 

it checks if the block is air but i cant check if an entity stands on the block. how can i check this?

Posted

well you can get close to it by checking if the distance to block is less or equal to one.

 

public boolean collectItem(EntityItem targetItem)
{
 if(targetItem == null)
    {
	    targetItem = findClosestItem(this.posX, this.posY, this.posZ,30);
    }
    else
    {
    	if(!targetItem.isEntityAlive())
	    {
	    	targetItem = null;		    	
	    }	
    }
    if(targetItem != null)
    {
    	
    	PathEntity PathToItem = this.worldObj.getPathEntityToEntity(this, targetItem, 30, true, false, false, true);
	    if(hasPath()){
		    this.setPathToEntity(PathToItem);
		    this.moveSpeed = 1.0F;
		    [b]if(targetItem.getDistanceSq(this.posX,this.posY,this.posZ) < 2)[/b]
		    {
			 targetItem.setDead();
			 //TODO add item to inventory
			 targetItem = null;
		    }				 
	    }
	    else
	    {
	    	this.moveSpeed = 0.23F;
	    }
    }
	return false;
}

this is the code i use for collecting items. It has cod for checking distance to target.

Posted

i dont have any entity... i have only X, Y & Z Coordinates and i whant to find out if there is a entity in this "block"

oh so you want to find if its just above the block.

//your'll have to fiddle with the bound box size to find only items above
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(x,y+1,z, x+1,y+2,z+1);
//change EntityItem too the entity you want to find
List<EntityItem> items = par1World.getEntitiesWithinAABB(EntityItem.class, bounds);
if(items.size > 0)
{
//there is something above block
}

 

there is more likely an easier bit of code that just checks of the spot you want to place is clear, or else placing normal block would cause issues. Check line 3461 in World.class and the ItemBlock.class

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.