Jump to content

Having an entity check for a Blocks Metadata


SureenInk

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.