Posted May 20, 201411 yr 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?
May 20, 201411 yr 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.
May 20, 201411 yr 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?
May 20, 201411 yr if (par2ItemStack != null && par2ItemStack.getItem() instanceof ItemCloth){ system.out.println(par2ItemStack.getItemDamage());
May 20, 201411 yr 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?
May 21, 201411 yr 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.