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.

[SOLVED][1.7.10] Searching for a dropped item on the ground...

Featured Replies

Posted

Hi guys,

 

I am looking for something similar to

 

Entity.worldObj.getEntitiesWithinAABB ....

 

but that would return a specific searched item that was dropped on the ground. Any idea what method I could use?

 

Here is what I want to achieve.

 

My mob scan 50 squares around him and can smell a raw steak that was dropped on the ground. I am looking for a method that would return the list of instance of a specific item class within a specific range of a position.

 

I googled the heck out of this ... might be my choice of words, but I was not able to find anything.

 

Where should I start to look at?

  • Author

That's the method you have to use - specify EntityItem as the class of Entity to retrieve, and you will have a list of only EntityItems. Iterate through the list, cast to EntityItem, and check if it is the item you want.

 

Holy hell that does make sense. I was not figuring out that an item, when dropped on the ground ... becomes an EntityItem, which contains an ItemStack, which contains an Item.

 

Thanks a thousand time CoolAlias. I will come back here with my final result.

  • Author

That's the method you have to use - specify EntityItem as the class of Entity to retrieve, and you will have a list of only EntityItems. Iterate through the list, cast to EntityItem, and check if it is the item you want.

 

Ok so here is the way I did it .... works perfectly

 

protected EntityItem GetClosestItem(Entity fromEntity, Class anItemClass, int xDistance, int yDistance, int zDistance)
{
	try
	{
		if (fromEntity!=null)
		{
			List _itemList = fromEntity.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(fromEntity.posX - xDistance, fromEntity.posY - yDistance, fromEntity.posZ - zDistance, fromEntity.posX + xDistance, fromEntity.posY + yDistance, fromEntity.posZ + zDistance));
			if ((_itemList!=null) && (_itemList.size()>0))
			{
				EntityItem _entityItem = null;
				Iterator _iterator = _itemList.iterator();

				while (_iterator.hasNext())
				{
					_entityItem = (EntityItem)_iterator.next();
					ItemStack _stack = _entityItem.getEntityItem();
					Item _item = _stack.getItem();
					//Check if the stack is the correct item type
					if (_item.getClass().equals(anItemClass))
					{
						return _entityItem;
					}
				}
			}
			return null;
		}
		return null;
	}
	catch (Exception e)
	{
		return null;
	}
}

Just putting it out there, it's generally bad practice to test for an item class since they tend to be used for multiple instances.

You can test stack.getItem().equals(Items.steak)

 

There is the odd time where you'll test for a class to group the instances, but you can then instead use stack.getItem() instanceof ItemSteak

  • Author

Just putting it out there, it's generally bad practice to test for an item class since they tend to be used for multiple instances.

You can test stack.getItem().equals(Items.steak)

 

There is the odd time where you'll test for a class to group the instances, but you can then instead use stack.getItem() instanceof ItemSteak

 

Good point you have there. Thanks for the hint.

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.