* @return The ItemStack remained after place attempt
*/
public ItemStack tryPlaceInPosition(ItemStack itemStack, Vector3 position, ForgeDirection dir)
{
TileEntity tileEntity = position.getTileEntity(this.worldObj);
ForgeDirection direction = dir.getOpposite();
if (tileEntity != null && itemStack != null)
{
/** Try to put items into a chest. */
if (tileEntity instanceof TileMultiBlockPart)
{
Vector3 mainBlockPosition = ((TileMultiBlockPart) tileEntity).getMainBlock();
if (mainBlockPosition != null)
{
if (!(mainBlockPosition.getTileEntity(this.worldObj) instanceof TileMultiBlockPart))
{
return tryPlaceInPosition(itemStack, mainBlockPosition, direction);
}
}
}
else if (tileEntity instanceof TileEntityChest)
{
TileEntityChest[] chests = { (TileEntityChest) tileEntity, null };
/** Try to find a double chest. */
for (int i = 2; i < 6; i++)
{
ForgeDirection searchDirection = ForgeDirection.getOrientation(i);
Vector3 searchPosition = position.clone();
searchPosition.translate(searchDirection);
if (searchPosition.getTileEntity(this.worldObj) != null)
{