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

So, I'm a little confused...I need to be able to check for a block's metadata, but I'm unsure how to do it. In my coding, I have these 2 lines of code:

this.tasks.addTask(2, new EntityAITempt(this, 1.0D, Item.getItemFromBlock(Blocks.double_plant), false));
if ((helditem != null) && (helditem.getItem() == Item.getItemFromBlock(Blocks.double_plant)))

I want to be able to check for the lilac, which as far as I can tell is metadata 1, but both of these are only allowing me to check for Item, which doesn't have the parameters to do metadata. I've tried using ItemStack instead, but that doesn't work because I have to search for Item, not ItemStack...could anyone help?

Finding an actual placed block's meta data?

i think it's World.getMetaFromBlock(x,y,z) not sure, else if you're looking for an itemblock you have to check the itemdamage, if itemdamage of block.double_plant returns 1, it should be the one you're looking for.

  • Author

Yeah, I'm checking to see if the player has the itemblock in their hand. How do I go about checking for it's damage, then?

if (par2ItemStack != null && par2ItemStack.getItem() instanceof ItemCloth){
system.out.println(par2ItemStack.getItemDamage());

  • Author

Uhh...hmm...I'm confused still (sorry!) How do I use that in the ai coding? Also...I can't do an instance of BlockDoublePlant for an item...so how would I do that?

I will edit or reply when i am on my machine with the source, i've done it for my entity that collects items based on nbt and metadata.

 

 

 

        if (this._golem.GetItem() == null || this._golem.IsInventoryFull())
            return false;
        else {
        	List list = this._golem.worldObj.getEntitiesWithinAABB(EntityItem.class, this._golem.boundingBox.expand(20.0D, 4.0D, 20.0D));
        EntityItem entityitem = null;
            double d0 = Double.MAX_VALUE;
            Iterator iterator = list.iterator();

            while (iterator.hasNext()) {
            	EntityItem entityitem1 = (EntityItem)iterator.next();

            	if (entityitem1 instanceof EntityItem && entityitem1.getEntityItem().getItem() == this._golem.GetItem()) {
                    double d1 = this._golem.getDistanceSqToEntity(entityitem1);

                    if (d1 <= d0) {
                        d0 = d1;
                        if(this._golem.isSetWithNBT()) {
                        	if (ItemStack.areItemStackTagsEqual(_golem.GetItemStack(), entityitem1.getEntityItem())) {
                        		if(entityitem1.getEntityItem().getItem() instanceof ItemBlock){
                        			System.out.println(entityitem1.getEntityItem().getItemDamage());
                        			if(entityitem1.getEntityItem().getItemDamage() == _golem.GetItemStack().getItemDamage()){
                        			entityitem = entityitem1;
	                        		break;
                        			}
                        		}
                        		else{
                        		entityitem = entityitem1;
                        		break;
                        		}
                        	}
                        }
                        else {
                        	entityitem = entityitem1;
                        	break;
                        }
                    }
                }
            }

 

 

 

This snippet is an example of my ai, it checks if the nbt and metadata are the same. (mine is controlled by a boolean though)

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.