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!