Jump to content

Recommended Posts

Posted

I am trying to create a container/tile entity for a block I am making. I have been following a tutorial that described it step by step. I followed the tutorial to the word and somehow I still have an error with setting an NBT tag to an item, even when in the tutorial, there are no errors.

 

Here is the code for the method involved:

 

private void dropItems(World world, int x, int y, int z){
        Random rand = new Random();
       
        TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
       
        if(!(tile_entity instanceof IInventory)){
                return;
        }

        IInventory inventory = (IInventory) tile_entity;

        for(int i = 0; i < inventory.getSizeInventory(); i++){
                ItemStack item = inventory.getStackInSlot(i);
               
                if(item != null && item.stackSize > 0){
                float rx = rand.nextFloat() * 0.6F + 0.1F;
                float ry = rand.nextFloat() * 0.6F + 0.1F;
                float rz = rand.nextFloat() * 0.6F + 0.1F;
               
                EntityItem entity_item = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
               
                if(item.hasTagCompound()){
                        entity_item.item.setTagCompound((NBTTagCompound) item.getTagCompound().copy());
                }

                float factor = 0.5F;
               
                entity_item.motionX = rand.nextGaussian() * factor;
                entity_item.motionY = rand.nextGaussian() * factor + 0.2F;
                entity_item.motionZ = rand.nextGaussian() * factor;
                world.spawnEntityInWorld(entity_item);
                item.stackSize = 0;
                }
        }
}

 

The affected line is

entity_item.item.setTagCompound((NBTTagCompound) item.getTagCompound().copy());

 

More specifically, there is an error in the .item. part saying "Item cannot be resolved or is not a field". I checked the Containers and GUIs tutorial on the wiki, but all they have in that place is .func_92014_d(). which is hardly helpful.

 

Does anyone have any idea what to do? Thanks!

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.