Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

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.

  • Author

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"

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.