1

Need help with a part of code(getting items from chest)

Revengance 2/25/13 1:20 pm
192
2/25/2013 3:40 pm
Hello!
When I click a block I will need it to get some items from a chest nearby, do something with them and then place the remaining items in another chest. Everything is working well but the getting items from chest.
This is the function i'm calling:
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
This is the part of the code that I need help with:
int diamonds = 0;
int torches = 0;
int count = 0;
if(par1World.getBlockId(par2 + 1, par3, par4) != Block.chest.blockID){
par1World.setBlockAndMetadataWithNotify(par2 + 1, par3, par4, Block.chest.blockID, 0, 4);
}else{
TileEntityChest var16 = (TileEntityChest)par1World.getBlockTileEntity(par2 + 1, par3, par4);
int itemid;
ItemStack var9;
for(int var8 = 0; var8 < 27; var8 ++){
var9 = var16.getStackInSlot(var8);
if(var9 != null){
itemid = var9.itemID;
if(itemid == 50){
int stackcount = var9.stackSize;
torches += stackcount;
var9.stackSize += stackcount;
}
if(itemid == Item.diamond.itemID){
int stackcount = var9.stackSize;
diamonds += stackcount;
var9.stackSize -= stackcount;
}
}
}
Posted by
Revengance
Level 15 : Journeyman Miner
3

  Have something to say?

JoinSign in

1

Revengance
02/25/2013 3:40 pm
Level 15 : Journeyman Miner
Ok. I have figured the most out by myself. Only thing left is to remove the stack from the chest. I tried setting var9.stackSize = 0 but that left a phantom torch in the chest and i cant set it to null. when i set var9 to null nothing happens. Help?
1

Welcome